mirror of
https://github.com/archr-linux/Arch-R.git
synced 2026-03-31 14:41:55 -07:00
157 lines
5.2 KiB
Bash
Executable File
157 lines
5.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
################################################################################
|
|
# This file is part of OpenELEC - http://www.openelec.tv
|
|
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
|
|
#
|
|
# This Program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2, or (at your option)
|
|
# any later version.
|
|
#
|
|
# This Program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with OpenELEC.tv; see the file COPYING. If not, write to
|
|
# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
|
|
# http://www.gnu.org/copyleft/gpl.html
|
|
################################################################################
|
|
|
|
TMP_DIR="$HOME/.xbmc/temp"
|
|
|
|
if [ -f /etc/update.conf ]; then
|
|
. /etc/update.conf
|
|
elif [ -f /var/config/settings.conf ]; then
|
|
. /var/config/settings.conf
|
|
AUTOUPDATE="$UPDATE_AUTO"
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
if [ -f /etc/repo.conf ]; then
|
|
. /etc/repo.conf
|
|
if [ -n "$KEYFILE" ]; then
|
|
SCP_ARG="-i $KEYFILE"
|
|
fi
|
|
else
|
|
exit 0
|
|
fi
|
|
|
|
download () {
|
|
case "$DL_METHOD" in
|
|
wget)
|
|
wget -U "$THIS_DISTRIBUTION ($THIS_ARCH): $THIS_VERSION" \
|
|
-c ${1}?sysid=$SYSTEMID \
|
|
-O $2 > /dev/null 2>&1
|
|
;;
|
|
scp)
|
|
scp $SCP_ARG "$1" $TMP_DIR
|
|
;;
|
|
esac
|
|
}
|
|
|
|
send_message () {
|
|
xbmc-send --host=127.0.0.1 -a "Notification(Automatic update service:,$1,20000)"
|
|
}
|
|
|
|
if [ ! -f /var/lock/update.lock ]; then
|
|
|
|
if [ "$AUTOUPDATE" = "manually" -o "$AUTOUPDATE" = "manual" -o "$AUTOUPDATE" = "auto" ]; then
|
|
|
|
# sleep a bit, maybe we have a lot of work ;-)
|
|
usleep 30000000
|
|
|
|
# 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_DIR/latest
|
|
download "$UPDATEURL/latest" "$TMP_DIR/latest"
|
|
|
|
NEW_IMAGE="`cat $TMP_DIR/latest |grep "$THIS_DISTRIBUTION-$THIS_ARCH"`"
|
|
NEW_VERSION="`echo "$NEW_IMAGE" | cut -d "-" -f3`"
|
|
|
|
rm -rf $TMP_DIR/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_PATCH" -lt "$NEW_PATCH" -a \
|
|
"$THIS_MINOR" -eq "$NEW_MINOR" -a \
|
|
"$THIS_MAJOR" -eq "$NEW_MAJOR" ] || \
|
|
[ "$THIS_MINOR" -lt "$NEW_MINOR" -a \
|
|
"$THIS_MAJOR" -eq "$NEW_MAJOR" -a \
|
|
"$NEW_MINOR" -lt 90 ] || \
|
|
[ "$THIS_MINOR" -ge 90 -a \
|
|
"$NEW_MINOR" -lt 90 -a \
|
|
$(( $THIS_MAJOR + 1 )) -eq "$NEW_MAJOR" ]; then
|
|
AUTOUPDATE="$AUTOUPDATE"
|
|
elif [ "$THIS_MAJOR" -lt "$NEW_MAJOR" -a \
|
|
"$NEW_MINOR" -lt 90 ]; then
|
|
AUTOUPDATE="manually"
|
|
else
|
|
AUTOUPDATE="no"
|
|
fi
|
|
|
|
if [ "$AUTOUPDATE" = "manually" -o "$AUTOUPDATE" = "manual" ]; then
|
|
|
|
# show a message if a new version is available
|
|
send_message "New update available: $NEW_VERSION - please update manually"
|
|
|
|
elif [ "$AUTOUPDATE" = "auto" ]; then
|
|
|
|
# show a message if a new version is available
|
|
send_message "New update available: $NEW_VERSION - downloading and extracting the new version..."
|
|
|
|
# locking autoupdate
|
|
touch /var/lock/update.lock
|
|
|
|
# downloading the new version
|
|
rm -rf $TMP_DIR/$NEW_IMAGE.tar.bz2
|
|
download "$UPDATEURL/$NEW_IMAGE.tar.bz2" "$TMP_DIR/$NEW_IMAGE.tar.bz2"
|
|
|
|
# extract the image
|
|
rm -rf $TMP_DIR/$NEW_IMAGE
|
|
tar -xjvf $TMP_DIR/$NEW_IMAGE.tar.bz2 -C $TMP_DIR
|
|
|
|
# move KERNEL and SYSTEM to an temporary file
|
|
mkdir -p /storage/.update
|
|
if [ -f $TMP_DIR/$NEW_IMAGE/target/KERNEL -a -f $TMP_DIR/$NEW_IMAGE/target/KERNEL.md5 ]; then
|
|
mv $TMP_DIR/$NEW_IMAGE/target/KERNEL /storage/.update/KERNEL.tmp
|
|
mv $TMP_DIR/$NEW_IMAGE/target/KERNEL.md5 /storage/.update/KERNEL.md5.tmp
|
|
fi
|
|
if [ -f $TMP_DIR/$NEW_IMAGE/target/SYSTEM -a -f $TMP_DIR/$NEW_IMAGE/target/SYSTEM.md5 ]; then
|
|
mv $TMP_DIR/$NEW_IMAGE/target/SYSTEM /storage/.update/SYSTEM.tmp
|
|
mv $TMP_DIR/$NEW_IMAGE/target/SYSTEM.md5 /storage/.update/SYSTEM.md5.tmp
|
|
fi
|
|
sync
|
|
|
|
# move KERNEL and SYSTEM to the right place
|
|
mv /storage/.update/KERNEL.tmp /storage/.update/KERNEL
|
|
mv /storage/.update/KERNEL.md5.tmp /storage/.update/KERNEL.md5
|
|
mv /storage/.update/SYSTEM.tmp /storage/.update/SYSTEM
|
|
mv /storage/.update/SYSTEM.md5.tmp /storage/.update/SYSTEM.md5
|
|
sync
|
|
|
|
# cleanup tmp files
|
|
rm -rf $TMP_DIR/$NEW_IMAGE
|
|
rm -rf $TMP_DIR/$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
|