TOPIC: Update script for OpenELEC on Raspberry Pi

Update script for OpenELEC on Raspberry Pi 9 months 2 weeks ago #1

  • hholtman
  • hholtman's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 4
  • Karma: 0
I have written a bash script to update my Raspberry Pi with the nightly releases of OpenELEC and the latest firmware. This script can be executed from a secure shell connection and there is no need to remove the SD-card. If you are interested please have a look at my blog
The administrator has disabled public write access.
The following user(s) said Thank You: Marvel, sebus, ruscat

Re: Update script for OpenELEC on Raspberry Pi 9 months 2 weeks ago #2

  • lrusak
  • lrusak's Avatar
  • OFFLINE
  • Administrator
  • Posts: 2007
  • Thank you received: 260
  • Karma: 262
thanks, looks good.

be aware that un tar-ing takes some time on the rpi :D

I edited this for use on my personal server :)

also, you could add this script to autostart.sh like this
#!/bin/sh
(sleep 60;
./storage/downloads/update_script)&

then at the end you could remove reboot and append
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Update Available","message":"Please Reboot When Ready To Update","displaytime":8000}}' http://localhost:80/jsonrpc

this would allow it to update when booting normally then it would update when reboots. This may cause problems though if the system loses power midway of the update, hmm. I may add an if statement to check if the file is already downloaded...
<-- Hit me with some karma if I've helped you out :)
Last Edit: 9 months 2 weeks ago by lrusak.
The administrator has disabled public write access.

Re: Update script for OpenELEC on Raspberry Pi 9 months 2 weeks ago #3

  • hholtman
  • hholtman's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 4
  • Karma: 0
lrusak wrote:
be aware that un tar-ing takes some time on the rpi :D
Indeed, I found that out while testing this script, it takes a couple of minutes. But in my opinion running this script is easier than taking out your SD-card everyday ;)
Thanks for your suggestions by the way!
The administrator has disabled public write access.

Re: Update script for OpenELEC on Raspberry Pi 9 months 2 weeks ago #4

  • lrusak
  • lrusak's Avatar
  • OFFLINE
  • Administrator
  • Posts: 2007
  • Thank you received: 260
  • Karma: 262
Here is my script, I have modified it so it will run and notify the user with gui interaction.

EDIT: Updated to allow the recent git changes
#!/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/"`

and here is my autostart.sh script so it runs at boot
#!/bin/sh
(sleep 60;
sh /storage/downloads/update_script)&

If you didn't want it to run every boot you could simply make a command for you remote to run the update (which might be a better choice) by doing something like this to your remote.xml.
<red>XBMC.runscript(/storage/downloads/update_script)</red>
<-- Hit me with some karma if I've helped you out :)
Last Edit: 9 months 1 week ago by lrusak.
The administrator has disabled public write access.

Re: Update script for OpenELEC on Raspberry Pi 9 months 2 weeks ago #5

  • Thorvaldo
  • Thorvaldo's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Hi.

I`m really new to Linux and sorry for the dumb question.

But i don`t know where to put the update.sh file on SD card.

Can somebody explain where I should put it?

Thx in adv.

T
The administrator has disabled public write access.

Re: Update script for OpenELEC on Raspberry Pi 9 months 2 weeks ago #6

  • hholtman
  • hholtman's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 4
  • Karma: 0
The update.sh file should be on the /storage partition of the SD-card since the /flash partition is not large enough. You can either do this by accessing your RPi via a network share and copy it there or you can place the file manually on your SD-card and copy it via a secure shell connection to the /storage partition.

If you are on windows then you can browse via an explorer window to \\<ip-adress of RPi> and then you should see among others a folder named 'Update', placing the file update.sh there will allow you to execute it via Putty by going to the update folder and type
chmod 755 update.sh
./update.sh
The first line will make the script executable.
I hope this helps, good luck.
The administrator has disabled public write access.
The following user(s) said Thank You: Thorvaldo
Moderators: ericab, lrusak

Our Sponsors & Partners

arctic_logo