-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcavate.sh
More file actions
104 lines (89 loc) · 3.24 KB
/
excavate.sh
File metadata and controls
104 lines (89 loc) · 3.24 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
echo "DateTime:" $(date +"%Y-%m-%d %H:%M:%S")
. /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 [ -z "$REMOTE_HOST" ]; then 'REMOTE_HOST environment variable is not set!'; exit 1; fi
if [ -z "$SCOOP_HOME" ]; then echo 'SCOOP_HOME 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
. /root/init_ssh.sh
# Clone bucket and add remotes
if [ ! -d /root/bucket ]; then
echo 'Initializing Bucket repository ...'
git config --global core.autocrlf true
git clone "https://$REMOTE_HOST/$BUCKET" /root/bucket
cd /root/bucket
git remote set-url --push origin "git@$REMOTE_HOST:$BUCKET.git"
if [ $METHOD != 'push' ]; then
git remote add upstream "git@$REMOTE_HOST:$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 [ "$REMOTE_HOST" = 'github.com' ]; then
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
else
if [ -f /root/bucket/bin/checkver.ps1 ]; then
echo 'Updating each manifests ...'
cd /root/bucket
auto_commit() {
local json=$1
local name=$(echo -n $json | sed 's/\.[^\.]*$//')
pwsh /root/bucket/bin/checkver.ps1 -u $json
[ -z $(git status -s) ] && return
local ver=$(jq -r '.version' $json)
local msg=$(printf '%s: Update to version %d' $name $ver)
git add $json
git commit -m $msg
[ $? -ne 0 ] && git checkout .
}
export -f auto_commit
find *.json | xargs -I % bash -c "auto_commit" %
if [ ! -z $(git status -bs | head -n1 | sed -E 's/[^0-9]*//g') ]; then
echo 'Pushing updates ...'
if [ -f /root/first_push ]; then
git push origin master
else
git push -u origin master
touch /root/first_push
fi
else
echo 'All manifests are up to date.'
fi
fi
fi