Primiano Tucci | e0ccef9 | 2017-10-03 10:43:20 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2017 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -e |
| 17 | mkdir -p /home/gitbot |
| 18 | mount -t tmpfs tmpfs /home/gitbot -o size=4G |
| 19 | useradd -d /home/gitbot -s /bin/bash -M gitbot || true |
| 20 | chown gitbot.gitbot /home/gitbot |
| 21 | |
| 22 | apt-get update |
| 23 | apt-get install -y git python curl sudo supervisor |
| 24 | |
Primiano Tucci | e0ccef9 | 2017-10-03 10:43:20 -0700 | [diff] [blame] | 25 | mkdir -p /home/gitbot/logs |
| 26 | cat<<EOF > /etc/supervisord.conf |
| 27 | [supervisord] |
| 28 | logfile=/home/gitbot/logs/supervisord.log |
| 29 | logfile_maxbytes=2MB |
| 30 | |
| 31 | [program:gitbot] |
| 32 | directory=/home/gitbot |
Primiano Tucci | 2cc9966 | 2019-06-05 10:06:37 +0100 | [diff] [blame] | 33 | command=python mirror_aosp_to_ghub_repo.py --push |
Primiano Tucci | e0ccef9 | 2017-10-03 10:43:20 -0700 | [diff] [blame] | 34 | user=gitbot |
| 35 | autorestart=true |
| 36 | startretries=10 |
| 37 | stdout_logfile=/home/gitbot/logs/gitbot.log |
| 38 | stdout_logfile_maxbytes=2MB |
| 39 | redirect_stderr=true |
| 40 | EOF |
| 41 | |
Primiano Tucci | c54641f | 2019-12-10 15:40:33 +0000 | [diff] [blame] | 42 | curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/project/attributes/deploy_key" > /home/gitbot/deploy_key |
| 43 | echo >> /home/gitbot/deploy_key # metadata server strips trailing \n. |
Primiano Tucci | e0ccef9 | 2017-10-03 10:43:20 -0700 | [diff] [blame] | 44 | chown gitbot /home/gitbot/deploy_key |
| 45 | chmod 400 /home/gitbot/deploy_key |
| 46 | |
| 47 | curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/instance/attributes/main" > /home/gitbot/mirror_aosp_to_ghub_repo.py |
| 48 | chown gitbot /home/gitbot/mirror_aosp_to_ghub_repo.py |
| 49 | chmod 755 /home/gitbot/mirror_aosp_to_ghub_repo.py |
| 50 | |
| 51 | cd /home/gitbot |
| 52 | sudo -u gitbot bash -c "mkdir -p .ssh; ssh-keyscan github.com >> .ssh/known_hosts;" |
| 53 | /usr/bin/supervisord -c /etc/supervisord.conf |