-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathinstall-update.sh
executable file
·150 lines (135 loc) · 5.05 KB
/
install-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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
#
# This file is part of nzbget. See <https://nzbget.com>.
#
# Copyright (C) 2015-2016 Andrey Prygunkov <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
if test "$NZBUP_PROCESSID" = ""; then
echo "This file is not supposed to be executed directly. To update NZBGet please choose Settings -> SYSTEM -> Check for update in the web-interface."
exit 1
fi
INSTALLERCFG=`cat "$NZBOP_APPDIR/installer.cfg" 2>/dev/null`
if test "$INSTALLERCFG" = ""; then
echo "[ERROR] File \"installer.cfg\" is missing in the installation directory. Please reinstall NZBGet."
exit 1
fi
echo "Downloading version information..."
UPDATE_INFO_LINK=`cat "$NZBOP_APPDIR/webui/package-info.json" | sed -n 's/^.*update-info-link.*: "\(.*\)".*/\1/p'`
"$NZBOP_APPBIN" -B webget "$NZBOP_TEMPDIR/NZBGET_UPDATE.txt" "$UPDATE_INFO_LINK" 2>/dev/null
if test "$?" != "0"; then
echo "[ERROR] Download failed, please try again later"
exit 1
fi
if test "$NZBUP_BRANCH" = "TESTING"; then
VER_FIELD="testing-version"
DNL_FIELD="testing-download"
SIG_FIELD="testing-signature"
elif test "$NZBUP_BRANCH" = "STABLE"; then
VER_FIELD="stable-version"
DNL_FIELD="stable-download"
SIG_FIELD="stable-signature"
else
echo "[ERROR] Unsupported branch $NZBUP_BRANCH"
exit 1
fi
VER=`cat "$NZBOP_TEMPDIR/NZBGET_UPDATE.txt" | sed -n "s/^.*$VER_FIELD.*: \"\(.*\)\".*/\1/p"`
DNL_LINK=`cat "$NZBOP_TEMPDIR/NZBGET_UPDATE.txt" | sed -n "s/^.*$DNL_FIELD.*: \"\(.*\)\".*/\1/p"`
SIG_LINK=`cat "$NZBOP_TEMPDIR/NZBGET_UPDATE.txt" | sed -n "s/^.*$SIG_FIELD.*: \"\(.*\)\".*/\1/p"`
rm -f "$NZBOP_TEMPDIR/NZBGET_UPDATE.txt"
SIGNATURE="nzbget-$VER.sig.txt"
echo "Downloading verification signature..."
rm -f "$NZBOP_TEMPDIR/$SIGNATURE"
"$NZBOP_APPBIN" -B webget "$NZBOP_TEMPDIR/$SIGNATURE" "$SIG_LINK" 2>/dev/null
if test "$?" != "0"; then
echo "[ERROR] Download failed, please try again later"
exit 1
fi
INSTALLER="nzbget-$VER-bin-linux.run"
echo "Downloading $INSTALLER..."
rm -f "$NZBOP_TEMPDIR/$INSTALLER"
"$NZBOP_APPBIN" -B webget "$NZBOP_TEMPDIR/$INSTALLER" "$DNL_LINK" 2>/dev/null
if test "$?" != "0"; then
echo "[ERROR] Download failed, please try again later"
exit 1
fi
echo "Verifying package authenticity..."
"$NZBOP_APPBIN" -B verify "$NZBOP_APPDIR/pubkey.pem" "$NZBOP_TEMPDIR/$SIGNATURE" "$NZBOP_TEMPDIR/$INSTALLER" 2>/dev/null
if test "$?" != "93"; then
echo "[ERROR] Package authenticity verification failed"
rm -f "$NZBOP_TEMPDIR/$INSTALLER"
rm -f "$NZBOP_TEMPDIR/$SIGNATURE"
exit 1
fi
rm -f "$NZBOP_TEMPDIR/$SIGNATURE"
echo "Updating NZBGet..."
echo "..."
sh "$NZBOP_TEMPDIR/$INSTALLER" --update --destdir "$NZBOP_APPDIR"
if test "$?" != "0"; then
echo "[ERROR] Update failed, installer terminated with error status"
exit 1
fi
rm -f "$NZBOP_TEMPDIR/$INSTALLER"
echo "..."
echo "Update completed"
# Recreating command line used to start NZBGet
CMDLINE=
N=1
while true
do
PARAMNAME="NZBUP_CMDLINE$N"
eval PARAM="\$NZBUP_CMDLINE${N}"
if test "$PARAM" = ""; then
break
fi
if test "$CMDLINE" != ""; then
CMDLINE="$CMDLINE "
fi
CMDLINE="$CMDLINE\"$PARAM\""
# Using "case" to implement expression "N=N+1" to overcome possibly disabled expression support on Busybox
case $N in
1) N=2 ;; 2) N=3 ;; 3) N=4 ;; 4) N=5 ;; 5) N=6 ;; 6) N=7 ;; 7) N=8 ;; 8) N=9 ;; 9) N=10 ;; 10) N=11 ;;
11) N=12 ;; 12) N=13 ;; 13) N=14 ;; 14) N=15 ;; 15) N=16 ;; 16) N=17 ;; 17) N=18 ;; 18) N=19 ;; 19) N=20 ;;
21) N=22 ;; 22) N=23 ;; 23) N=24 ;; 24) N=25 ;; 25) N=26 ;; 26) N=27 ;; 27) N=28 ;; 28) N=29 ;; 29) N=30 ;;
31) N=32 ;; 32) N=33 ;; 33) N=34 ;; 34) N=35 ;; 35) N=36 ;; 36) N=37 ;; 37) N=38 ;; 38) N=39 ;; 39) N=40 ;;
41) N=42 ;; 42) N=43 ;; 43) N=44 ;; 44) N=45 ;; 45) N=46 ;; 46) N=47 ;; 47) N=48 ;; 48) N=49 ;; 49) N=50 ;;
*)
echo "..."
echo "[ERROR] Could not restart NZBGet: cannot recreate command line"
echo "[ERROR] Please restart NZBGet manually (reloading via web-interface isn't sufficient)"
exit 1
esac
done
echo "Restarting NZBGet..."
sleep 1
echo "[NZB] QUIT"
echo "Waiting for NZBGet to terminate"
PSOPT="-A"
OPTWORKING=`ps $PSOPT` 2>/dev/null
if test "$?" != "0"; then
PSOPT=""
fi
while true
do
RUNNING=`ps $PSOPT | sed -n "s/^[\s ]*$NZBUP_PROCESSID[\s ].*/&/p"`
if test "$RUNNING" = ""; then
break
fi
sleep 1
done
echo "Starting NZBGet..."
# Starting NZBGet
eval "$NZBOP_APPBIN" $CMDLINE
exit 0