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 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 33 command=python mirror_aosp_to_ghub_repo.py 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 42 curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/instance/attributes/deploy_key" > /home/gitbot/deploy_key 43 chown gitbot /home/gitbot/deploy_key 44 chmod 400 /home/gitbot/deploy_key 45 46 curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/instance/attributes/main" > /home/gitbot/mirror_aosp_to_ghub_repo.py 47 chown gitbot /home/gitbot/mirror_aosp_to_ghub_repo.py 48 chmod 755 /home/gitbot/mirror_aosp_to_ghub_repo.py 49 50 cd /home/gitbot 51 sudo -u gitbot bash -c "mkdir -p .ssh; ssh-keyscan github.com >> .ssh/known_hosts;" 52 /usr/bin/supervisord -c /etc/supervisord.conf 53 54 dd if=/dev/zero of=/swap bs=1M count=4k 55 chmod 600 /swap 56 mkswap /swap 57 swapon /swap 58