This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexcavate.sh
72 lines (60 loc) · 2.18 KB
/
excavate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
. /etc/container_environment.sh
if [ -z "$GIT_USERNAME" ]; then echo 'GIT_USERNAME environment variable is not set!'; exit 1; fi
if [ -z "$GIT_EMAIL" ]; then echo 'GIT_EMAIL environment variable is not set!'; exit 1; fi
if [ -z "$BUCKET" ]; then echo 'BUCKET environment variable is not set!'; exit 1; fi
if [ $METHOD != 'push' ]; then
if [ -z $UPSTREAM ]; then echo 'UPSTREAM environment variable is not set!'; exit 1; fi
fi
find /root/log/*.log -mtime +2 -exec rm {} \;
if [ ! -f /root/first_run ]; then
# Update CRONTAB
if [ ! -z "$CRONTAB" ]; then
echo "$CRONTAB root /bin/bash /root/excavate.sh > /root/log/mud-\$(date +\"\%Y\%m\%d-\%H\%M\%S\").log 2>&1" > /etc/cron.d/excavator
fi
# Set git config settings
git config --global user.name "$GIT_USERNAME"
git config --global user.email "$GIT_EMAIL"
# add github.com to known_hosts and generate private/public key
if [ -z "`grep "$(ssh-keyscan github.com 2>/dev/null)" /root/.ssh/known_hosts`" ]; then
ssh-keyscan github.com >> /root/.ssh/known_hosts
fi
if [ ! -f /root/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 4096 -C "Excavator-$BUCKET" -f /root/.ssh/id_rsa -N ''
fi
# Clone bucket and add remotes
if [ ! -d /root/bucket ]; then
echo 'Initializing Bucket repository ...'
git config --global core.autocrlf true
git clone "https://github.com/$BUCKET" /root/bucket
cd /root/bucket
git remote set-url --push origin "[email protected]:$BUCKET.git"
if [ $METHOD != 'push' ]; then
git remote add upstream "[email protected]:$UPSTREAM.git"
fi
fi
# first run complete
touch /root/first_run
fi
echo 'Updating Scoop ...'
cd /root/scoop
git pull
echo 'Cleaning Scoop cache ...'
cd /root/bucket
rm /root/cache/* 2> /dev/null
echo 'Excavating ...'
ARGS=
if [ $METHOD == 'push' ]; then
ARGS="-Push"
else
ARGS="-Request"
fi
if [ ! -z $SNOWFLAKES ]; then
ARGS="$ARGS -SpecialSnowflakes $SNOWFLAKES"
fi
if [ -f /root/bucket/bin/auto-pr.ps1 ]; then
pwsh /root/bucket/bin/auto-pr.ps1 $ARGS
fi
if [ -f /root/bucket/bin/bucket-updater.ps1 ]; then
pwsh /root/bucket/bin/bucket-updater.ps1 $ARGS
fi