-
Notifications
You must be signed in to change notification settings - Fork 1
/
lms-update.sh
executable file
·427 lines (384 loc) · 12.9 KB
/
lms-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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#!/bin/sh
#
# lms-update.sh
#
# Script to update slimserver.tcz on piCorePlayer from LMS nightlies.
#
# Script Source https://github.com/piCorePlayer/lms-update-script
# Script by Paul_123 @ http://forum.tinycorelinux.net/
# Original script concept by jgrulich
#
# Most common usage will be 'sudo lms-update.sh -r'
#
. /etc/init.d/tc-functions
checkroot
TCEDIR=$(readlink "/etc/sysconfig/tcedir")
DL_DIR="/tmp/slimupdate"
UPDATELINK="${DL_DIR}/update_url"
SCRIPT=$(readlink -f $0)
NEWARGS="${@}"
GIT_REPO="https://raw.githubusercontent.com/piCorePlayer/lms-update-script/Master"
[ -d ${DL_DIR} ] || mkdir -p ${DL_DIR}
usage(){
echo " usage: $0 [-u] [-d] [-m] [-r] [-s] [-t]"
echo " -u Unattended Execution"
echo " -d Debug, Temp files not erased"
echo " -m Manual download Link Check for LMS update"
echo " -r Reload LMS after Update"
echo " -s Skip Update from GitHub"
echo " -t Test building, but do not move extension to tce directory"
echo " --mm <version> Force the version you want to update. (eg 7.9.1)"
echo
}
O=$(/usr/bin/getopt -l sss,mm: -- mudrts "$@") || exit 1
eval set -- "$O"
while true; do
case "$1" in
-u) UNATTENDED=1;;
-d) DEBUG=1;;
-m) MANUAL=1;;
--mm) MANUAL=1;VERSION="$2"; shift;;
-r) RELOAD=1;;
-t) TEST=1;;
-s) SKIPUPDATE=1;;
--sss) RESUME=1;; #For script relaunch use only, do not use from
--) shift; break;;
-*) usage
exit 1;;
*) break;; # terminate while loop
esac
shift
done
if [ -z "$RESUME" ]; then
[ -z "$UNATTENDED" ] && clear
echo
echo "${BLUE}###############################################################"
echo
echo " This script will update the Logitech Media Server extension "
echo
usage
[ -n "$UNATTENDED" ] && echo " Unattended Operation Enabled"
[ -n "$DEBUG" ] && echo " Debug Enabled"
[ -n "$MANUAL" ] && echo -n " Manual Download Link Check Enabled"
[ -n "$VERSION" ] && echo " Version:${VERSION}" || echo ""
[ -n "$RELOAD" ] && echo " Automatic Reload Enabled"
[ -n "$SKIPUPDATE" ] && echo " Skipping Update"
[ -n "$TEST" ] && echo " Test Mode Enabled"
echo "###############################################################"
echo
echo "Press Enter to continue, or Ctrl-c to exit and change options${NORMAL}"
[ -z "$UNATTENDED" ] && read key
if [ "$SKIPUPDATE" != "1" ]; then
#Check for depednancy of openssl for wget to work with https://
if [ ! -x /usr/local/bin/openssl ]; then
if [ ! -f $TCEDIR/optional/openssl.tcz ]; then
echo "${GREEN} Downloading required extension openssl.tcz${NORMAL}"
echo
su - tc -c "tce-load -liw openssl.tcz"
else
echo "${GREEN} Loading Local Extension openssl.tcz${NORMAL}"
echo
su - tc -c "tce-load -li openssl.tcz"
fi
if [ "$?" != "0" ]; then echo "${RED}Failed to load required extension!. ${NORMAL} Check by manually installing extension openssl.tcz"; exit 1; fi
fi
echo "${GREEN}Updateing Script from Github..."
FILES="lms-update.sh"
for F in $FILES
do
rm -f ${DL_DIR}/${F}
wget -O ${DL_DIR}/${F} ${GIT_REPO}/${F}
if [ "$?" != "0" ]; then
echo "${RED}Download FAILED......Please Check or Relauch script with with -s option!${NORMAL}"
exit 1
fi
done
echo "${GREEN}Relaunching Script in 3 seconds${NORMAL}"
chmod 755 ${DL_DIR}/lms-update.sh
sleep 3
set -- "--sss" $NEWARGS
exec /bin/sh ${DL_DIR}/lms-update.sh "${@}"
else
#if we are going to dismount drive to automatically reload extension, we cannot run lms-update.sh from /usr/local/bin
if [ -n "$RELOAD" ]; then
echo "${GREEN}Copying and Running script to tmp so we can automatically reload LMS later"
cp -f ${SCRIPT} ${DL_DIR}/lms-update.sh
set -- "--sss" $NEWARGS
exec /bin/sh ${DL_DIR}/lms-update.sh "${@}"
fi
fi
fi
if [ "$SKIPUPDATE" != "1" ]; then
echo "${GREEN}Updateing Slimserver customizations from Github..."
FILES="custom-strings.txt picore-update.html Custom.pm slimserver"
for F in $FILES
do
rm -f ${DL_DIR}/${F}
wget -O ${DL_DIR}/${F} ${GIT_REPO}/${F}
if [ "$?" != "0" ]; then
echo "${RED}Download FAILED......Please Check or Relauch script with with -s option!${NORMAL}"
exit 1
fi
done
fi
if [ -z "$MANUAL" ]; then
if [ -f "${UPDATELINK}" ]; then
read LINK < $UPDATELINK
else
LINK="0"
fi
else
[ -z $VERSION ] && VERSION=$(fgrep "our \$VERSION" /usr/local/slimserver/slimserver.pl | cut -d"'" -f2)
REVISION=$(head -n 1 /usr/local/slimserver/revision.txt)
echo "${YELLOW}Performing manual check for update link, Current Version is: $VERSION r${REVISION}.${NORMAL}"
tmp=`mktemp`
wget "http://www.mysqueezebox.com/update/?version=${VERSION}&revision=${REVISION}&geturl=1&os=nocpan" -O $tmp
if [ "$?" != "0" ]; then echo "${RED}Unable to Contact Download Server!${NORMAL}"; rm $tmp; exit 1; fi
read LINK < $tmp
rm -f $tmp
fi
if [ "$LINK" = "0" ]; then
# No Update needed
if [ -z "$MANUAL" ]; then
echo
echo "${BLUE}No update link found. THis either means that there is no update, or you do not have automatic update"
echo "checks and automatic downloads enabled in the LMS settings."
echo
echo "If you would like to manually check for updates using a static update check, please relaunch this script"
echo "using the -m command line switch"
echo
echo "DONE${NORMAL}"
exit 0
else
echo "${BLUE}Revision $VERSION r${REVISION} is the latest. No Update Needed."
echo
echo "DONE.${NORMAL}"
exit 0
fi
else
echo
echo "${GREEN}Downloading update from ${LINK}"
fi
rm -f $DL_DIR/*.tgz
wget -P $DL_DIR $LINK
if [ "$?" != "0" ]; then
echo "${RED}Download FAILED...... exiting!${NORMAL}"
[ -n "$DEBUG" ] || rm -f $DL_DIR/'*.tgz'
exit 1
fi
NEWUPDATE=`find ${DL_DIR} -name "*.tgz"`
if [ -z $NEWUPDATE ]; then
echo "${BLUE}No Update Found, please make sure Automatic updates and Automatic Downloads are enable in LMS.${NORMAL}"
echo
exit 0
fi
#Check for depednancy of mksquashfs
if [ ! -x /usr/local/bin/mksquashfs ]; then
if [ ! -f $TCEDIR/optional/squashfs-tools.tcz ]; then
echo "${GREEN}Downloading required extension squashfs-tools.tcz${NORMAL}"
echo
su - tc -c "tce-load -liw squashfs-tools.tcz"
else
echo "${GREEN}Loading Local Extension squashfs-tools.tcz${NORMAL}"
echo
su - tc -c "tce-load -li squashfs-tools.tcz"
fi
if [ "$?" != "0" ]; then echo "${RED}Failed to load required extension!. ${NORMAL} Check by manually installing extension squashfs-tools.tcz"; exit 1; fi
fi
echo
echo "${GREEN}Updating from ${NEWUPDATE}"
# Extract Downloaded File
echo
echo -ne "${GREEN}Extracting Update..."
SRC_DIR=`mktemp -d`
f=`mktemp`
( tar -xzf ${NEWUPDATE} -C $SRC_DIR; echo -n $? > $f ) &
rotdash $!
read e < $f
if [ "$e" != "0" ]; then
echo "${RED}File Extraction FAILED.....exiting!${NORMAL}"
[ -n "$DEBUG" ] || rm -rf $SRC_DIR
exit 1
fi
rm -f $f
echo
echo -e "${BLUE}Tar Extraction Complete, Building Updated Extension Filesystem"
echo
echo "Press Enter to continue, or Ctrl-c to exit${NORMAL}"
[ -z "$UNATTENDED" ] && read key
echo
echo -ne "${GREEN}Update in progress ..."
BUILD_DIR=`mktemp -d`
f=`mktemp`
echo 0 > $f
# Each command has an error trap
(mkdir -p $BUILD_DIR/usr/local/bin
[ "$?" != "0" ] && echo -n "1" > $f
mkdir -p $BUILD_DIR/usr/local/etc/init.d
[ "$?" != "0" ] && echo -n "1" > $f
mv $SRC_DIR/*-noCPAN $BUILD_DIR/usr/local/slimserver
[ "$?" != "0" ] && echo -n "1" > $f
#Copy in piCore custom files
FDIR="usr/local/slimserver/Slim/Utils/OS"
F="Custom.pm"
if [ -e ${DL_DIR}/${F} ]; then # Copy Updated Version
cp -f ${DL_DIR}/${F} $BUILD_DIR/${FDIR}/${F}
else # Copy version from current Extension
cp -f /tmp/tcloop/slimserver/${FDIR}/${F} $BUILD_DIR/${FDIR}/${F}
fi
[ "$?" != "0" ] && echo -n "1" > $f
FDIR="usr/local/slimserver/HTML/EN/html/docs"
F="picore-update.html"
if [ -e ${DL_DIR}/${F} ]; then # Copy Updated Version
cp -f ${DL_DIR}/${F} $BUILD_DIR/${FDIR}/${F}
else # Copy version from current Extension
cp -f /tmp/tcloop/slimserver/${FDIR}/${F} $BUILD_DIR/${FDIR}/${F}
fi
[ "$?" != "0" ] && echo -n "1" > $f
FDIR="usr/local/slimserver"
F="custom-strings.txt"
if [ -e ${DL_DIR}/${F} ]; then # Copy Updated Version
cp -f ${DL_DIR}/${F} $BUILD_DIR/${FDIR}/${F}
else # Copy version from current Extension
cp -f /tmp/tcloop/slimserver/${FDIR}/${F} $BUILD_DIR/${FDIR}/${F}
fi
[ "$?" != "0" ] && echo -n "1" > $f
###tarfile comes with only user ownership, which breaks symlinks on TC
#Change all files to 644
chmod -R 644 $BUILD_DIR
[ "$?" != "0" ] && echo -n "1" > $f
#Change mode for directories to 755
find $BUILD_DIR -type d | xargs -t -I {} chmod 755 {} > /dev/null 2>&1
[ "$?" != "0" ] && echo -n "1" > $f
#Change mod for executables
find $BUILD_DIR -name "*.pl" | xargs -t -I {} chmod 755 {} > /dev/null 2>&1
[ "$?" != "0" ] && echo -n "1" > $f
find $BUILD_DIR -name "dbish" | xargs -t -I {} chmod 755 {} > /dev/null 2>&1
[ "$?" != "0" ] && echo -n "1" > $f
#Copy in new init.d script
FDIR="usr/local/etc/init.d"
F="slimserver"
if [ -e ${DL_DIR}/${F} ]; then # Copy Updated Version
cp -f ${DL_DIR}/${F} $BUILD_DIR/${FDIR}/${F}
chmod 755 $BUILD_DIR/${FDIR}/${F}
else # Copy version from current Extension
cp -f /tmp/tcloop/slimserver/${FDIR}/${F} $BUILD_DIR/${FDIR}/${F}
fi
[ "$?" != "0" ] && echo -n "1" > $f
#Copy Update Script
FDIR="usr/local/bin"
F="lms-update.sh"
echo "${DL_DIR}/${F}"
if [ -x "${DL_DIR}/${F}" ]; then # Copy Updated Version
cp -f ${DL_DIR}/${F} $BUILD_DIR/${FDIR}/${F}
else # Copy version from current Extension
cp -f /tmp/tcloop/slimserver/${FDIR}/${F} $BUILD_DIR/${FDIR}/${F}
fi
[ "$?" != "0" ] && echo -n "1" > $f
) &
rotdash $!
read e < $f
if [ "$e" != "0" ]; then
echo "${RED}Update FAILED.....exiting!${NORMAL}"
[ -n "$DEBUG" ] || (rm -rf $SRC_DIR; rm -rf $BUILD_DIR)
exit 1
fi
rm -f $f
echo
echo
echo -e "${BLUE}Done Updating Files. The files are ready to be packed into the new extension"
echo
echo "${BLUE}Press Enter to continue, or Ctrl-c to exit${NORMAL}"
[ -z "$UNATTENDED" ] && read key
echo "${GREEN}Creating extension, it may take a while ... especially on rpi 0/A/B/A+/B+"
mksquashfs $BUILD_DIR /tmp/slimserver.tcz -noappend -force-uid 0 -force-gid 50
if [ "$?" != "0" ]; then
echo "${RED}Building Extension FAILED...... exiting!${NORMAL}"
[ -n "$DEBUG" ] || (rm -rf $SRC_DIR; rm -rf $BUILD_DIR)
exit 1
fi
REBOOT=""
if [ -z "$TEST" ]; then
if [ -n "$RELOAD" ]; then
echo "${BLUE}Ready to Reload LMS, Press Enter to Continue${NORMAL}"
[ -z "$UNATTENDED" ] && read key
echo "${GREEN}Stopping LMS"
/usr/local/etc/init.d/slimserver stop
if [ "$?" != "0" ]; then
echo "${RED}Extension will be replaced, but a reboot will be requied when finished"
REBOOT=1
fi
echo "${GREEN}Waiting for File Handles to Close"
CNT=0
until ! lsof | grep -q /tmp/tcloop/slimserver
do
[ $((CNT++)) -gt 10 ] && break || sleep 1
done
if [ $CNT -gt 10 ]; then
echo "${RED}Drive is still busy, Extension will be replaced, but a reboot will be requied when finished"
REBOOT=1
fi
if [ -z "$REBOOT" ]; then
echo "${GREEN}Unmounting Extension${NORMAL}"
umount -d -f /tmp/tcloop/slimserver
if [ "$?" != "0" ]; then
echo "${RED}Unmounting Filesystem failed......extension will be replaced, but reboot is requried${NORMAL}"
REBOOT=1
fi
fi
rm -f /usr/local/tce.installed/slimserver
echo "${GREEN}Moving new Extension to $TCEDIR/optional${NORMAL}"
md5sum /tmp/slimserver.tcz > $TCEDIR/optional/slimserver.tcz.md5.txt
sed -i 's|/tmp/||' $TCEDIR/optional/slimserver.tcz.md5.txt
mv -f /tmp/slimserver.tcz $TCEDIR/optional
chown tc.staff $TCEDIR/optional/slimserver.tcz*
echo
echo "${GREEN}Syncing filesystems${NORMAL}"
sync
if [ -z "$REBOOT" ]; then
echo "${GREEN}Loading new Extension${NORMAL}"
su - tc -c "tce-load -li slimserver.tcz"
if [ "$?" != "0" ]; then
echo "${RED}Problem Mounting new slimserver extension. Please check errors"
echo "Might just need to reboot${NORMAL}"
else
echo "${GREEN}Starting New Version of LMS${NORMAL}"
/bin/sh -c "/usr/local/etc/init.d/slimserver start"
echo
fi
else
echo
echo "${BLUE}Extension copied and will be loaded on next reboot${NORMAL}"
fi
else
echo "${GREEN}Moving new Extension to $TCEDIR/optional${NORMAL}"
md5sum /tmp/slimserver.tcz > $TCEDIR/optional/slimserver.tcz.md5.txt
sed -i 's|/tmp/||' $TCEDIR/optional/slimserver.tcz.md5.txt
mv -f /tmp/slimserver.tcz $TCEDIR/optional
chown tc.staff $TCEDIR/optional/slimserver.tcz*
echo
echo "${GREEN}Syncing filesystems${NORMAL}"
sync
echo
echo "${BLUE}Extension copied and will be loaded on next reboot${NORMAL}"
fi
else
md5sum /tmp/slimserver.tcz > /tmp/slimserver.tcz.md5.txt
sed -i 's|/tmp/||' /tmp/slimserver.tcz.md5.txt
echo
echo -e "${BLUE}Done, the new extension was left at /tmp/slimserver.tcz"
echo
fi
echo
echo "${BLUE}Press Enter to Cleanup and exit${NORMAL}"
echo
[ -z "$UNATTENDED" ] && read key
if [ -z "$DEBUG" ]; then
echo -e "${GREEN}Deleting the temp folders"
rm -rf $BUILD_DIR
rm -rf $SRC_DIR
#Erase Downloaded Files
rm -f ${DL_DIR}/*
fi
echo "${BLUE}DONE${NORMAL}"
echo