Test some code here:
|
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 |
#!/bin/bash
arch=`cat /etc/arch`
dir="/storage/downloads"
notification='curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '\''{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"TITLE","message":"MESSAGE","displaytime":8000}}'\'' http://0.0.0.0:80/jsonrpc'
# location of the nightlies
url="http://storage.xxxxxxxxxxxxx.com/"
# get base, revision and filename of last build
last_base=`curl -s $url | grep $arch | grep .tar.bz2 | sed 's/.*\(OpenELEC.*\).tar.bz2.*/\1/' | sort | tail -1`
last_revision=`echo $last_base | sed 's/.*\(r[0-9]*\)/\1/'`
last_filename=$last_base.tar.bz2
# folder name is set equal to base
foldername=$last_base
# get currently installed revision
this_revision=`cat /etc/version | sed 's/.*\(r[0-9]*\)/\1/'`
# check if currently installed revision is up-to-date
if [ $this_revision == $last_revision ];then
title='No Update Available'
message='Will Check Again Next Reboot'
eval `echo "$notification" | sed -e "s/\TITLE/$title/" -e "s/\MESSAGE/$message/"`
exit
else
title='Update Available'
message='Will Notify When Finished Updating'
eval `echo "$notification" | sed -e "s/\TITLE/$title/" -e "s/\MESSAGE/$message/"`
fi
# check if previous download exists and remove it (corrupt files from interupts, etc)
if [ -e $dir/$last_filename ];then
rm $dir/$last_filename
fi
# download corresponding file to working directory
urltolast=$url/$last_filename
wget -P $dir $urltolast
# uncompressing the tarball
tar -xvjf $dir/$last_filename -C $dir
# move OpenELEC files (including .md5 files) to update folder
mv $dir/$foldername/target/* /storage/.update/
# cleanup leftover files and folders
if [ -e $dir/$last_filename ];then
rm $dir/$last_filename
fi
if [ -d $dir/$foldername ];then
rm -r $dir/$foldername
fi
# sync and notify user to reboot system to apply updates
sync
title='Update Finished'
message='Please Reboot When Ready To Update'
eval `echo "$notification" | sed -e "s/\TITLE/$title/" -e "s/\MESSAGE/$message/"` |