Skip to content

Instantly share code, notes, and snippets.

@untergrundbiber
Last active November 30, 2016 21:50
Show Gist options
  • Save untergrundbiber/6c17e5709dd473b7ad8e8ea212d6fc51 to your computer and use it in GitHub Desktop.
Save untergrundbiber/6c17e5709dd473b7ad8e8ea212d6fc51 to your computer and use it in GitHub Desktop.
An automated development build updater script for LibreELEC nightly builds from Milhouse
#!/usr/bin/env bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
set -e
var="$1"
# "LibreELEC_DEV" ; An automated development build updater script for LibreELEC nightly builds from Milhouse
server="http://milhouse.libreelec.tv/builds/master/RPi2/"
# default locations
updatedir="/storage/.update"
. /etc/os-release
arch=$LIBREELEC_ARCH
localversion=$(echo "$VERSION" | awk '{gsub(/[[:punct:]]/," ")}1' | awk '{print $3}' | tr -d 'r')
updating(){
ls -nas "$updatedir"
}
updatefile_check (){
while true;
do
pending=$(find /storage/.update/* 2> /dev/null | wc -l)
if [ "$pending" = "1" ] ;
then
echo
echo
echo "Update-File are already in place."
echo "You must reboot to complete the update."
echo "Would you like to reboot now (y/n) ?"
read -r -n1 -p "==| " reb
if [[ $reb != "Y" ]] && [[ $reb != "y" ]] && [[ $reb != "N" ]] && [[ $reb != "n" ]] ;
then
echo
echo
echo "Unrecognized Input."
sleep 1
echo "Please answer (y/n)"
continue
elif [[ $reb = "Y" || $reb = "y" ]] ;
then
echo
echo
echo
echo "Rebooting..."
sync
sleep 2
reboot
elif [[ $reb = "N" || $reb = "n" ]] ;
then
echo
echo
echo "Please reboot to complete the update."
sleep 1
echo "Exiting."
exit 0
fi
fi
break
done
}
update(){
echo "Would you like to update (y/n) ?"
read -r -n1 -p "==| " yn
if [[ $yn != "Y" ]] && [[ $yn != "y" ]] && [[ $yn != "N" ]] && [[ $yn != "n" ]] ;
then
echo
echo
echo "Unrecognized Input."
sleep 2
echo "Please answer (y/n)"
echo "Exiting."
echo
exit 1
elif [[ $yn = "Y" || $yn = "y" ]] ;
then
sleep .5
echo
echo
echo "Downloading Image: $url to $updatedir"
wget "$url" -P "$updatedir"
echo "Done!"
sleep 1
echo "Please reboot to complete the update."
exit 0
elif [[ $yn = "N" || $yn = "n" ]] ;
then
echo
echo
echo "User aborted process."
sleep 2
echo "Exiting."
echo
exit 0
fi
}
check_update (){
echo "Check for update"
file=""
url=""
ar="\"LibreELEC[_0-9A-Za-z\-]*${arch//\./\.}-.*\.ta[^im]*\""
file=$(curl --silent $server | grep -o "$ar" | sed -e 's/"//g' | tail -n 1 | cut -d " " -f1)
ver=$(echo "$file" | sed -e 's/%23/#/g' | grep -o "\#[0-9]*" | grep -o "[0-9]*")
url="$server$file"
#echo "$file"
#echo "$url"
#echo "$ver"
echo
echo "Local: $localversion Compiled: $(echo "$VERSION" | cut -f 2-2 -d'-' | sed 's/......$//;s/./& /4' | sed 's/./& /7' | awk '{ print "[ "$1"-"$2"-"$3" ]" }')"
echo "Remote: $ver Compiled: $(echo "$file" | cut -f 5-5 -d'-' | sed 's/......$//;s/./& /4' | sed 's/./& /7' | awk '{ print "[ "$1"-"$2"-"$3" ]" }')"
echo
if [ "$ver" -gt "$localversion" ]; then
echo "Update available"
update "$url"
else
echo "No update available"
if [ "$var" = "force" ]; then
echo "Force Update"
update "$url"
fi
fi
echo
}
echo "Device Detected: $arch"
echo
mkdir -p "$updatedir"
updatefile_check
check_update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment