ATV2 and iOS nightly build semi automatic update scripts
#1
So, I like to automate things, and I hate to type the same stuff over and over. The script below is what I just put together to simplify updating to the latest nightly build (from the official repository, that is http://mirrors.xbmc.org/nightlies/darwin/atv2/):

Code:
#!/bin/sh
xbmcdir=http://mirrors.xbmc.org/nightlies/darwin/atv2
wget -q $xbmcdir
xbmcdeb=$(cat index.html | gawk 'match($0, ">(xbmc-.*-.*-master-atv2.deb)<", a) {print a[1]}' | head -n 1)
rm index.html
wget $xbmcdir/$xbmcdeb
dpkg -i $xbmcdeb
rm $xbmcdeb

What this script does is to first download the file listing from the atv2 builds directory, parse out the name of the topmost build (which should be the newest), and then download and install this package.

I am sure there is plenty of room for improvement, I haven't really made a shell script in about 10 years, so my script-fu is kinda rusty... But hey, this works for me. :-)

The easiest way to get this script on your ATV2 is probably to ssh to the box (I use PuTTY for this) and simply paste the following into your terminal (everything in one go works fine) and press enter:

Code:
rm xbmcup.sh
echo '#!/bin/sh' >> ./xbmcup.sh
echo "xbmcdir=http://mirrors.xbmc.org/nightlies/darwin/atv2" >> ./xbmcup.sh
echo "wget -q \$xbmcdir" >> ./xbmcup.sh
echo "xbmcdeb=\$(cat index.html | gawk 'match(\$0, \">(xbmc-.*-.*-master-atv2.deb)<\", a) {print a[1]}' | head -n 1)"  >> ./xbmcup.sh
echo "rm index.html" >> ./xbmcup.sh
echo "wget \$xbmcdir/\$xbmcdeb" >> ./xbmcup.sh
echo "dpkg -i \$xbmcdeb" >> ./xbmcup.sh
echo "rm \$xbmcdeb" >> ./xbmcup.sh
chmod 755 ./xbmcup.sh

Do remember to press enter, or your script won't be executable.

Now, whenever you'd like to update, you just ssh to your ATV2 and type this:

Code:
./xbmcup.sh

With PuTTY, and probably other ssh clients aswell, you can even tell it to run the above command automatically when you connect to the ATV2, if you'd prefer not to type anything at all except login and password. In session settings, go to Connection > SSH and put ./xbmcup.sh in "Remote command" and save your session). Now, when you connect with this session, instead of an interactive shell, PuTTY will trigger the script, and then disconnect and close its window when the update is finished.

Here's a URL to a picture showing the correct spot in the settings dialog:
http://www.ats.ucla.edu/clusters/common/...ty_ssh.jpg

For absolutely no typing, pair this with ssh keys instead of a logon password and you've got a completely automated updater triggered from your PC.

I will be adapting the script for the iOS (iPad) builds later - if there is any interest I'll post that one, too.

Best regards,
Durniplot
Reply
#2
Alright, not much interest it seems, but I'll post the iOS (works for iPad 2 - no other devices tested) script anyways.

For this to work you might need to install gawk (type apt-get install gawk) first. Apparently there is no head command on the ipad, so the script is slightly different. Also, obviously the download location and package name is also a little bit different from the atv2 builds

Here is what it looks like:

Code:
#!/bin/sh
xbmcdir=http://mirrors.xbmc.org/nightlies/darwin/ios/
wget -q $xbmcdir
xbmcdeb=$(cat index.html | gawk 'match($0, ">(xbmc-.*-.*-master-ios.deb)<", a) {print a[1]}' | gawk 'NR==1{print }')
rm index.html
wget $xbmcdir/$xbmcdeb
dpkg -i $xbmcdeb
rm $xbmcdeb


Once again, the easiest way to get this as a script on your iDevice is probably to just paste the following into your ssh terminal window:

Code:
rm xbmcup.sh
echo '#!/bin/sh' >> ./xbmcup.sh
echo "xbmcdir=http://mirrors.xbmc.org/nightlies/darwin/ios/" >> ./xbmcup.sh
echo "wget -q \$xbmcdir" >> ./xbmcup.sh
echo "xbmcdeb=\$(cat index.html | gawk 'match(\$0, \">(xbmc-.*-.*-master-ios.deb)<\", a) {print a[1]}' | gawk 'NR==1{print $1}')"  >> ./xbmcup.sh
echo "rm index.html" >> ./xbmcup.sh
echo "wget \$xbmcdir/\$xbmcdeb" >> ./xbmcup.sh
echo "dpkg -i \$xbmcdeb" >> ./xbmcup.sh
echo "rm \$xbmcdeb" >> ./xbmcup.sh
chmod 755 ./xbmcup.sh

Remember to press enter after the last line.

Performing an update is now as easy as typing the following into your shell:

Code:
./xbmcup.sh

Hints and tips regarding PuTTY for ATV2 applies here, aswell.

Best regards,
Durniplot
Reply
#3
I couldn't figure out how to change the actual thread's title to "ATV2 and iOS nightly build semi automatic update scripts". If someone can, please do.

Durniplot
Reply
#4
Smile 
Thanks a bunch! works fine here, and I can tell it will save me lots of time when upgrading to nightlies from now on.
Reply
#5
I think it's a good idea, I will probably use this (with cron?), but will add to it so that it SCP's a copy of the nightly build to my server, and perhaps an argument to roll back would be nice too Smile
Reply
#6
Thumbs Up 
Thank you. Excellent script Big Grin
Reply
#7
Cheunce Wrote:Thank you. Excellent script Big Grin

I must agree, it works well, and now to automate it. I added a quick and dirty if file exists statement to it, and also an scp copy to my nas.

This works for me, but I am not fluent in bash scripting, so if there is a better way, please do tell.

Code:
#!/bin/sh
xbmcdir=http://mirrors.xbmc.org/nightlies/darwin/atv2/
wget -q $xbmcdir
xbmcdeb=$(cat index.html | gawk 'match($0,
">(xbmc-.*-.*-master-atv2.deb)<", a) {print a[1]}' | gawk 'NR==1{print
}')
rm index.html
#echo $xbmcdeb
if [ -e $xbmcdeb ]; then {
echo "Already have latest version"
exit 1
}
else echo "Downloading"
wget $xbmcdir/$xbmcdeb
if [ $? != 0 ]; then
{
echo "Failed"
exit 1
} fi
dpkg -i $xbmcdeb
echo "Archiving nightly"
scp $xbmcdeb [email protected]:/mnt/eff/backups/XBMC
if [ $? != 0 ]; then
{
echo "Copy Failed"
exit 1
} fi
rm $xbmcdeb
touch $xbmcdeb
fi

oh, and it works without password for scp'ing because I have added public key to file server.

Thanks for the script!
Reply
#8
This script is great.. thank you!
Reply
#9
I haven't tried this script yet, but it looks awesome. One question--is there a way to incorporate this into another small script that also automates connecting to the ATV2 via ssh? i.e. something where I could just open my terminal window on my mac, type in a command, and the script will automatically connect to the ATV2 and run the update script?
- Amazon FireTV Stick 4K running latest stable Kodi version
- Sony Bravia XBR-x900h Android TV running latest stable Kodi version
- Skin: Aeon Nox: SiLVO
Reply
#10
canadave Wrote:I haven't tried this script yet, but it looks awesome. One question--is there a way to incorporate this into another small script that also automates connecting to the ATV2 via ssh? i.e. something where I could just open my terminal window on my mac, type in a command, and the script will automatically connect to the ATV2 and run the update script?

No clue about Mac OS really, but something like this should work:

Code:
ssh root@iDevice ./xbmcup.sh

.. where iDevice is the hostname or ip-adress assigned to your appletv/ipad/etc.

This will still require you to type in root's password upon connection. Look into ssh keys to get rid of that part too.

You could probably store the above command line in some sort of script file and associate it with an icon in your dock or similar, too, and have a one-click upgrade gadget :-)

Durniplot
Reply
#11
Worked great for me.
Thanks
Reply
#12
Woot! Good job thanks man.
Reply
#13
The only thing I would suggest is rather than removing the last installed .deb file, why not give the option to keep the last .deb file in case there are issues with the latest nightly?
Reply
#14
I highly recommend AGAINST automating a nightly download/install. I mean, come on, it's like two commands, wget to fetch and dpkg -i to install.

If you rely on a script to download/install, then you will be lost when it comes time to revert or remove a bad nightly.
Reply
#15
davilla Wrote:I highly recommend AGAINST automating a nightly download/install. I mean, come on, it's like two commands, wget to fetch and dpkg -i to install.
Well, to be fair, there's a *little* more to it than that Smile You have to go find the name of the last nightly too, copy/paste it into Terminal, etc. Agreed, the step-by-step process is not exactly onerous, but..... "./xbmcup.sh" is pretty simple to type in.

davilla Wrote:If you rely on a script to download/install, then you will be lost when it comes time to revert or remove a bad nightly.
I'm not sure I understand what you mean by saying we'll be "lost" if we've been using a script and need to revert/remove a nightly. Are you saying we won't know how?
- Amazon FireTV Stick 4K running latest stable Kodi version
- Sony Bravia XBR-x900h Android TV running latest stable Kodi version
- Skin: Aeon Nox: SiLVO
Reply

Logout Mark Read Team Forum Stats Members Help
ATV2 and iOS nightly build semi automatic update scripts1