-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·108 lines (90 loc) · 2.44 KB
/
update.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
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
104
105
106
107
108
#!/bin/env bash
if [ -d ./.git ]; then
echo "Cannot update. This copy is managed by a git repo"
exit
fi
OP="$1" # check, download, test, apply, do, install, postinstall
if [[ "$OP" == "check" ]]; then
if [[ ! -f "VERSION" ]]; then
touch VERSION
fi
URL="https://github.com/KASTEL-MobilityLab/ArtificialMetro/archive/refs/heads/trunk.zip"
LOCAL_VERSION=`cat VERSION`
REMOTE_VERSION=`curl -IL $URL | grep etag`
if [[ "$LOCAL_VERSION" == "$REMOTE_VERSION" ]]; then
exit 0
else
# if an update dir exists, that update has failed. Skip update if it is the same
if [[ -d update ]]; then
FAILED_VERSION=`cat update/VERSION`
if [[ "$FAILED_VERSION" == "$REMOTE_VERSION" ]]; then
exit 0
fi
fi
exit 1
fi
elif [[ "$OP" == "download" ]]; then
SUCCESS=0
BRANCH="trunk"
if [[ ! -z "$2" ]]; then
BRANCH="$2"
fi
URL="https://github.com/KASTEL-MobilityLab/ArtificialMetro/archive/refs/heads/$BRANCH.zip"
echo "Download $BRANCH"
wget -O update.zip "$URL"
NEW_VERSION=`curl -IL $URL | grep etag`
if [[ -d update ]]; then
rm -r update
fi
mkdir update
unzip -u -d "update/inner" update.zip
pushd update
cp -rf inner/*/* .
rm -r inner
chmod u+x *.sh
echo "$NEW_VERSION" > "VERSION"
./update.sh install # let update handle its own install
SUCCESS="$?"
popd
rm update.zip
exit "$SUCCESS"
elif [[ "$OP" == "install" ]]; then
npm i && npm run build
exit "$?"
elif [[ "$OP" == "postinstall" ]]; then
exit 0
elif [[ "$OP" == "test" ]]; then
echo "Test Update"
pushd update
./prod-test.sh
RESULT="$?"
popd
exit "$RESULT"
elif [[ "$OP" == "apply" ]]; then
echo "Apply Update"
cp -rf update/* .
rm -r update
./update.sh postinstall # let the new update handle its own postinstall
exit "$?"
elif [[ "$OP" == "do" ]]; then
./update.sh download "$2"
if [[ "$?" != "0" ]]; then
exit 1
fi
./update.sh test
if [[ "$?" != 0 ]]; then
exit 2
fi
./update.sh apply
if [[ "$?" != 0 ]]; then
exit 3
fi
else
echo "Usage:"
echo "$0 check check for update"
echo "$0 download [BRANCH] download the current version of BRANCH"
echo "$0 test run some tests to verify a working update"
echo "$0 apply apply the previously downloaded update"
echo "$0 install do necessary install steps like building etc"
echo "$0 postinstall do some post install steps"
fi