• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16set -e
17mkdir -p /home/gitbot
18mount -t tmpfs tmpfs /home/gitbot -o size=4G
19useradd -d /home/gitbot -s /bin/bash -M gitbot || true
20chown gitbot.gitbot /home/gitbot
21
22apt-get update
23apt-get install -y git python curl sudo supervisor
24
25mkdir -p /home/gitbot/logs
26cat<<EOF > /etc/supervisord.conf
27[supervisord]
28logfile=/home/gitbot/logs/supervisord.log
29logfile_maxbytes=2MB
30
31[program:gitbot]
32directory=/home/gitbot
33command=python mirror_aosp_to_ghub_repo.py
34user=gitbot
35autorestart=true
36startretries=10
37stdout_logfile=/home/gitbot/logs/gitbot.log
38stdout_logfile_maxbytes=2MB
39redirect_stderr=true
40EOF
41
42curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/instance/attributes/deploy_key" > /home/gitbot/deploy_key
43chown gitbot /home/gitbot/deploy_key
44chmod 400 /home/gitbot/deploy_key
45
46curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/instance/attributes/main" > /home/gitbot/mirror_aosp_to_ghub_repo.py
47chown gitbot /home/gitbot/mirror_aosp_to_ghub_repo.py
48chmod 755 /home/gitbot/mirror_aosp_to_ghub_repo.py
49
50cd /home/gitbot
51sudo -u gitbot bash -c "mkdir -p .ssh; ssh-keyscan github.com >> .ssh/known_hosts;"
52/usr/bin/supervisord -c /etc/supervisord.conf
53
54dd if=/dev/zero of=/swap bs=1M count=4k
55chmod 600 /swap
56mkswap /swap
57swapon /swap
58