-
Notifications
You must be signed in to change notification settings - Fork 62
/
update.sh
64 lines (60 loc) · 1.88 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
#!/usr/bin/env bash
DEST="/home/lampac"
cd $DEST
ver=$(cat vers.txt)
gitver=$(curl --connect-timeout 10 -m 20 -k -s https://api.github.com/repos/immisterio/Lampac/releases/latest | grep tag_name | sed s/[^0-9]//g)
if [ $gitver -gt $ver ]; then
echo "update lampac to version $gitver"
rm -f update.zip
if ! curl -L -k -o update.zip https://github.com/immisterio/Lampac/releases/latest/download/update.zip; then
echo "Failed to download update.zip. Exiting."
exit 1
fi
if ! unzip -t update.zip; then
echo "Failed to test update.zip. Exiting."
exit 1
fi
systemctl stop lampac
unzip -o update.zip
rm -f update.zip
echo -n $gitver > vers.txt
systemctl start lampac
else
check_ping() {
response=$(curl --connect-timeout 5 -m 10 -k -s "$1/ping")
if [[ "$response" == *"pong"* ]]; then
return 0
else
return 1
fi
}
if check_ping "http://noah.lampac.sh"; then
BASE_URL="http://noah.lampac.sh"
elif check_ping "https://lampac.sh"; then
BASE_URL="https://lampac.sh"
else
echo "minor updates are not available"
exit 1
fi
mver=$(cat vers-minor.txt)
dver=$(curl -k -s $BASE_URL/update/$ver.txt)
if [[ ${#dver} -eq 8 && $dver != $mver ]]; then
echo "update lampac to version $gitver.$mver"
rm -f update.zip
if ! curl -L -k -o update.zip "$BASE_URL/update/$dver.zip"; then
echo "Failed to download update.zip. Exiting."
exit 1
fi
if ! unzip -t update.zip; then
echo "Failed to test update.zip. Exiting."
exit 1
fi
systemctl stop lampac
unzip -o update.zip
rm -f update.zip
echo -n $dver > vers-minor.txt
systemctl start lampac
else
echo "lampac already current version $ver"
fi
fi