forked from NEMSLinux/legacy-nems-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·273 lines (257 loc) · 7.77 KB
/
update.sh
File metadata and controls
executable file
·273 lines (257 loc) · 7.77 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash
echo ""
echo "NEMS Update"
echo ""
if [[ $EUID -ne 0 ]]; then
echo "ERROR: This script must be run as root" 2>&1
exit 1
else
online=$(/usr/local/bin/nems-info online)
if [[ $online == 0 ]]; then
echo "*** NEMS cannot detect your Internet connection. Please make sure you are online. ***"
fi
# Just in case nems-quickfix is running
update=$(/usr/local/bin/nems-info update)
if [[ $update == 1 ]]; then
echo 'NEMS Linux is currently updating itself. Please wait...'
while [[ $update == 1 ]]
do
sleep 1
update=$(/usr/local/bin/nems-info update)
done
fi
echo $$ > /var/run/nems-update.pid
# Don't do updates if fixes is running, since that is a sub-process of update and could conflict
fixes=$(/usr/local/bin/nems-info fixes)
if [[ $fixes == 1 ]]; then
echo 'NEMS Linux is currently updating itself. Please wait...'
while [[ $fixes == 1 ]]
do
sleep 1
update=$(/usr/local/bin/nems-info fixes)
done
fi
echo "Updating NEMS Core Components"
# Update nems-migrator
echo " - nems-migrator"
cd /root/nems/nems-migrator
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /root/nems/nems-migrator /root/nems/nems-migrator~
cd /root/nems
git clone https://github.com/Cat5TV/nems-migrator
if [[ -d /root/nems/nems-migrator ]]; then
echo 'Successfully reinstalled.'
rm -rf /root/nems/nems-migrator~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /root/nems/nems-migrator~ /root/nems/nems-migrator
fi
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Get the latest version data from nems-migrator
cp -f /root/nems/nems-migrator/data/nems/ver-current.txt /var/www/html/inc/ver-available.txt
# Update nems-www
echo " - nems-www... "
cd /var/www/html
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /var/www/html /var/www/nems-www~
cd /var/www
git clone https://github.com/Cat5TV/nems-www
if [[ -d /var/www/nems-www ]]; then
mv nems-www html
chown -R www-data:www-data html
echo 'Successfully reinstalled.'
rm -rf /var/www/nems-www~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /var/www/nems-www~ /var/www/html
fi
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Update nems-tv
echo " - nems-tv... "
cd /var/www/nems-tv
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /var/www/nems-tv /var/www/nems-tv~
cd /var/www
git clone https://github.com/Cat5TV/nems-tv
if [[ -d /var/www/nems-tv ]]; then
chown -R www-data:www-data nems-tv
echo 'Successfully reinstalled.'
rm -rf /var/www/nems-tv~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /var/www/nems-tv~ /var/www/nems-tv
fi
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Update nems-admin
echo " - nems-admin... "
cd /root/nems/nems-admin
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /root/nems/nems-admin /root/nems/nems-admin~
cd /root/nems
git clone https://github.com/Cat5TV/nems-admin
if [[ -d /root/nems/nems-admin ]]; then
echo 'Successfully reinstalled.'
rm -rf /root/nems/nems-admin~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /root/nems/nems-admin~ /root/nems/nems-admin
fi
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Update nems-nconf
echo " - nconf... "
cd /var/www/nconf
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /var/www/nconf /var/www/nconf~
cd /var/www
git clone https://github.com/Cat5TV/nconf
if [[ -d /var/www/nconf ]]; then
echo 'Successfully reinstalled.'
rm -rf /var/www/nconf~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /var/www/nconf~ /var/www/nconf
fi
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Update nems-tools
echo " - nems-tools... "
if [[ -d /root/nems/nems-tools ]]; then
cd /root/nems/nems-tools
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /root/nems/nems-tools /root/nems/nems-tools~
cd /root/nems
git clone https://github.com/Cat5TV/nems-tools
if [[ -d /root/nems/nems-tools ]]; then
echo 'Successfully reinstalled.'
rm -rf /root/nems/nems-tools~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /root/nems/nems-tools~ /root/nems/nems-tools
fi
fi
else
echo "nems-tools is not installed."
cd /root/nems
git clone https://github.com/Cat5TV/nems-tools
echo 'Installed nems-tools.'
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Update self
echo " - nems-scripts... "
if [ -d /usr/local/share/nems/nems-scripts ]; then
cd /usr/local/share/nems/nems-scripts
commit=`git rev-parse HEAD`
echo " Commit: $commit"
printf " "
result=`git pull`
echo $result
if [[ $result =~ 'error:' ]]; then
echo 'Error detected. Reinstalling...';
mv /usr/local/share/nems/nems-scripts /usr/local/share/nems/nems-scripts~
cd /usr/local/share/nems
git clone https://github.com/Cat5TV/nems-scripts
if [[ -d /usr/local/share/nems ]]; then
echo 'Successfully reinstalled.'
rm -rf /usr/local/share/nems/nems-scripts~
else
echo 'Reinstall failed. Please copy your backup.nems file and re-image your device.'
mv /usr/local/share/nems/nems-scripts~ /usr/local/share/nems/nems-scripts
fi
fi
fi
commitnew=`git rev-parse HEAD`
if [[ $commit == $commitnew ]]; then
echo " No changes."
else
echo " New Commit: $commit"
fi
# Check if we are still on legacy 1.1 or 1.2.x and update that way, otherwise fixes will not run to patch it
if [ -d /home/pi/nems-scripts ]; then
echo "*** You need to upgrade your NEMS server to a current version! ***"
cd /home/pi/nems-scripts && git pull
fi
echo ""
# Perform any fixes that have been released since NEMS was built
printf "Running updates and fixes... "
if [ -d /usr/local/share/nems/nems-scripts ]; then
/usr/local/share/nems/nems-scripts/fixes.sh
fi
# Legacy support
if [ -d /home/pi/nems-scripts ]; then
/home/pi/nems-scripts/fixes.sh
fi
echo ""
fi
echo "Done."
echo ""
rm -f /var/run/nems-update.pid