blob: 2ae7143e45d0d96fad50a93d9051d424063a79cc [file] [log] [blame]
Primiano Tuccie0ccef92017-10-03 10:43:20 -07001#!/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
Primiano Tuccie0ccef92017-10-03 10:43:20 -070025mkdir -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
Primiano Tucci2cc99662019-06-05 10:06:37 +010033command=python mirror_aosp_to_ghub_repo.py --push
Primiano Tuccie0ccef92017-10-03 10:43:20 -070034user=gitbot
35autorestart=true
36startretries=10
37stdout_logfile=/home/gitbot/logs/gitbot.log
38stdout_logfile_maxbytes=2MB
39redirect_stderr=true
40EOF
41
Primiano Tuccic54641f2019-12-10 15:40:33 +000042curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/project/attributes/deploy_key" > /home/gitbot/deploy_key
43echo >> /home/gitbot/deploy_key # metadata server strips trailing \n.
Primiano Tuccie0ccef92017-10-03 10:43:20 -070044chown gitbot /home/gitbot/deploy_key
45chmod 400 /home/gitbot/deploy_key
46
47curl -H Metadata-Flavor:Google "http://metadata.google.internal/computeMetadata/v1/instance/attributes/main" > /home/gitbot/mirror_aosp_to_ghub_repo.py
48chown gitbot /home/gitbot/mirror_aosp_to_ghub_repo.py
49chmod 755 /home/gitbot/mirror_aosp_to_ghub_repo.py
50
51cd /home/gitbot
52sudo -u gitbot bash -c "mkdir -p .ssh; ssh-keyscan github.com >> .ssh/known_hosts;"
53/usr/bin/supervisord -c /etc/supervisord.conf