From ed2940b1d467e32d06dfcf22fa8829f6ee058a17 Mon Sep 17 00:00:00 2001 From: Stephan Raue Date: Tue, 13 Apr 2010 00:46:06 +0200 Subject: [PATCH] new package: - adding package autoupdate --- .../sysutils/autoupdate/config/update.conf | 15 +++ packages/sysutils/autoupdate/install | 19 ++++ .../autoupdate/scripts/autoupdate.devel | 84 +++++++++++++++++ .../autoupdate/scripts/autoupdate.release | 92 +++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 packages/sysutils/autoupdate/config/update.conf create mode 100755 packages/sysutils/autoupdate/install create mode 100755 packages/sysutils/autoupdate/scripts/autoupdate.devel create mode 100755 packages/sysutils/autoupdate/scripts/autoupdate.release diff --git a/packages/sysutils/autoupdate/config/update.conf b/packages/sysutils/autoupdate/config/update.conf new file mode 100644 index 0000000000..e6b47b08a3 --- /dev/null +++ b/packages/sysutils/autoupdate/config/update.conf @@ -0,0 +1,15 @@ +# Setup autoupdate ( no / manually / auto ) +# +# no: no popup-information about new updates, no automatically download, +# no autoupdate. +# +# manually: shows popupinformation about updates, you must manually download the +# and extract the update package. Copy the files "SYSTEM" and "KERNEL" +# locally or per SSH/SCP to /storage/.update or via SMB to the +# "Update" share. Then reboot the system to install the update. +# +# auto: shows popupinformation about updates, the autoupdater downloads the +# update package and shows an information that the system must +# manually rebooted to install the update. + +AUTOUPDATE=manually \ No newline at end of file diff --git a/packages/sysutils/autoupdate/install b/packages/sysutils/autoupdate/install new file mode 100755 index 0000000000..90c175b83f --- /dev/null +++ b/packages/sysutils/autoupdate/install @@ -0,0 +1,19 @@ +#!/bin/sh + +. config/options + +PKG_DIR=`find $PACKAGES -type d -name $1` + +mkdir -p $INSTALL/usr/bin + if [ "$DEVTOOLS" = "yes" ]; then + cp -P $PKG_DIR/scripts/autoupdate.devel $INSTALL/usr/bin/autoupdate + else + cp -P $PKG_DIR/scripts/autoupdate.release $INSTALL/usr/bin/autoupdate + fi + +mkdir -p $INSTALL/usr/config + cp -P $PKG_DIR/config/update.conf $INSTALL/usr/config + +mkdir -p $INSTALL/etc/crontabs + echo -e "*/5 * * * *\t/usr/bin/autoupdate" >> $INSTALL/etc/crontabs/root + diff --git a/packages/sysutils/autoupdate/scripts/autoupdate.devel b/packages/sysutils/autoupdate/scripts/autoupdate.devel new file mode 100755 index 0000000000..24033132eb --- /dev/null +++ b/packages/sysutils/autoupdate/scripts/autoupdate.devel @@ -0,0 +1,84 @@ +#!/bin/sh + +. /storage/.config/update.conf + +if [ ! -f /var/lock/update.lock ]; then + + if [ "$AUTOUPDATE" = "manually" -o "$AUTOUPDATE" = "auto" ]; then + # locking autoupdate + touch /var/lock/update.lock + + # sleep a bit, maybe we have a lot of work ;-) + sleep 30 + + send_message () { + xbmc-send --host=127.0.0.1 -a "Notification(Automatic update service:,$1)" + } + + UPDATEURL="http://snapshots.openelec.tv" + + # getting this version + THIS_DISTRIBUTION="`cat /etc/distribution`" + THIS_ARCH="`cat /etc/arch`" + THIS_VERSION="`cat /etc/version`" + + # get infofile with the latest released version + rm -rf /tmp/latest + wget $UPDATEURL/latest -P /tmp + + NEW_IMAGE="`cat /tmp/latest |grep "$THIS_DISTRIBUTION-$THIS_ARCH"`" + NEW_VERSION="`echo "$NEW_IMAGE" | cut -d "-" -f5 | tr -d "r"`" + + rm -rf /tmp/latest + + # compare installed version with latest released version + THIS_VERSION="`echo "$THIS_VERSION" | cut -d "-" -f3 | tr -d "r"`" + + if [ "$THIS_VERSION" -lt "$NEW_VERSION" ]; then + + if [ "$AUTOUPDATE" = "manually" ]; then + + # show a message if a new version is avaible + send_message "New update avaible: r$NEW_VERSION - please update manually" + + # remove locking + rm -rf /var/lock/update.lock + + elif [ "$AUTOUPDATE" = "auto" ]; then + + # show a message if a new version is avaible + send_message "New update avaible: r$NEW_VERSION - downloading the new version" + + # downloading the new version + wget -c $UPDATEURL/$NEW_IMAGE.tar.bz2 -P /tmp + + # extract the image + rm -rf /tmp/$NEW_IMAGE + tar -xjvf /tmp/$NEW_IMAGE.tar.bz2 -C /tmp + + # move KERNEL and SYSTEM to an temporary file + mkdir -p /storage/.update + + [ -f /tmp/$NEW_IMAGE/target/KERNEL ] && \ + mv /tmp/$NEW_IMAGE/target/KERNEL /storage/.update/KERNEL.tmp + + [ -f /tmp/$NEW_IMAGE/target/SYSTEM ] && \ + mv /tmp/$NEW_IMAGE/target/SYSTEM /storage/.update/SYSTEM.tmp + sync + + # move KERNEL and SYSTEM to the right place + mv /storage/.update/KERNEL.tmp /storage/.update/KERNEL + mv /storage/.update/SYSTEM.tmp /storage/.update/SYSTEM + + # cleanup tmp files + rm -rf /tmp/$NEW_IMAGE + rm -rf /tmp/$NEW_IMAGE.tar.bz2 + rm -rf /storage/.update/*.tmp + + # we are ready (hopefully) + send_message "Update r$NEW_VERSION - downloaded and extracted - please reboot to install" + + fi + fi + fi +fi diff --git a/packages/sysutils/autoupdate/scripts/autoupdate.release b/packages/sysutils/autoupdate/scripts/autoupdate.release new file mode 100755 index 0000000000..2bf4c4b5d2 --- /dev/null +++ b/packages/sysutils/autoupdate/scripts/autoupdate.release @@ -0,0 +1,92 @@ +#!/bin/sh + +. /storage/.config/update.conf + +if [ ! -f /var/lock/update.lock ]; then + + if [ "$AUTOUPDATE" = "manually" -o "$AUTOUPDATE" = "auto" ]; then + # locking autoupdate + touch /var/lock/update.lock + + # sleep a bit, maybe we have a lot of work ;-) + sleep 30 + + send_message () { + xbmc-send --host=127.0.0.1 -a "Notification(Automatic update service:,$1)" + } + + UPDATEURL="http://releases.openelec.tv" + + # getting this version + THIS_DISTRIBUTION="`cat /etc/distribution`" + THIS_ARCH="`cat /etc/arch`" + THIS_VERSION="`cat /etc/version`" + THIS_MAJOR="`echo "$THIS_VERSION" | cut -d "." -f1`" + THIS_MINOR="`echo "$THIS_VERSION" | cut -d "." -f2`" + THIS_PATCH="`echo "$THIS_VERSION" | cut -d "." -f3`" + + # get infofile with the latest released version + rm -rf /tmp/latest + wget $UPDATEURL/latest -P /tmp + + NEW_IMAGE="`cat /tmp/latest |grep "$THIS_DISTRIBUTION-$THIS_ARCH"`" + NEW_VERSION="`echo "$NEW_IMAGE" | cut -d "-" -f3`" + + rm -rf /tmp/latest + + # compare installed version with latest released version + NEW_MAJOR="`echo "$NEW_VERSION" | cut -d "." -f1`" + NEW_MINOR="`echo "$NEW_VERSION" | cut -d "." -f2`" + NEW_PATCH="`echo "$NEW_VERSION" | cut -d "." -f3`" + + if [ "$THIS_MAJOR" -lt "$NEW_MAJOR" -o \ + "$THIS_MINOR" -lt "$NEW_MINOR" -o \ + "$THIS_PATCH" -lt "$NEW_PATCH" ]; then + + if [ "$AUTOUPDATE" = "manually" ]; then + + # show a message if a new version is avaible + send_message "New update avaible: $NEW_VERSION - please update manually" + + # remove locking + rm -rf /var/lock/update.lock + + elif [ "$AUTOUPDATE" = "auto" ]; then + + # show a message if a new version is avaible + send_message "New update avaible: $NEW_VERSION - downloading the new version" + + # downloading the new version + wget -c $UPDATEURL/$NEW_IMAGE.tar.bz2 -P /tmp + + # extract the image + rm -rf /tmp/$NEW_IMAGE + tar -xjvf /tmp/$NEW_IMAGE.tar.bz2 -C /tmp + + # move KERNEL and SYSTEM to an temporary file + mkdir -p /storage/.update + + [ -f /tmp/$NEW_IMAGE/target/KERNEL ] && \ + mv /tmp/$NEW_IMAGE/target/KERNEL /storage/.update/KERNEL.tmp + + [ -f /tmp/$NEW_IMAGE/target/SYSTEM ] && \ + mv /tmp/$NEW_IMAGE/target/SYSTEM /storage/.update/SYSTEM.tmp + sync + + # move KERNEL and SYSTEM to the right place + mv /storage/.update/KERNEL.tmp /storage/.update/KERNEL + mv /storage/.update/SYSTEM.tmp /storage/.update/SYSTEM + + touch /var/ + # cleanup tmp files + rm -rf /tmp/$NEW_IMAGE + rm -rf /tmp/$NEW_IMAGE.tar.bz2 + rm -rf /storage/.update/*.tmp + + # we are ready (hopefully) + send_message "Update $NEW_VERSION - downloaded and extracted - please reboot to install" + + fi + fi + fi +fi