From 6dd0417ab13ac65808f7a4645ece4e20bc716670 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 12 Jan 2018 22:52:50 +0100 Subject: [SSUS] Remove old files when updating slx-admin; check OS version more thoroughly --- satellit_upgrader/updater.template.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'satellit_upgrader/updater.template.sh') diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh index 196ccf1..e50b020 100644 --- a/satellit_upgrader/updater.template.sh +++ b/satellit_upgrader/updater.template.sh @@ -5,16 +5,25 @@ if [ ! -d "/opt/dmsd" ] && [ ! -d "/srv/openslx/www/slx-admin" ]; then echo "This system doesn't look like a bwLehrpool Satellite Server" + echo "(Or this updater is really old)" exit 1 fi -TEST1=$(which systemctl) -TEST2=$(lsb_release -sc) -if [ -z "$TEST1" ] || [ "x$TEST2" != "xjessie" ]; then +if [ "$(lsb_release -si)" != "Debian" ]; then + echo "This updater only supports Debian-based satellite servers" + exit 1 +fi + +TEST2=$(lsb_release -sr) +if [ "${TEST2%%.*}" -lt 8 ]; then echo "This Version of the bwLehrpool Satellite Server is too old!" exit 1 fi -unset TEST1 TEST2 +if [ "${TEST2%%.*}" -gt 8 ]; then + echo "This Version of the bwLehrpool Satellite Server is too new!" + exit 1 +fi +unset TEST2 unset TMPDIR [ -n "$TMPDIR" ] && exit 1 @@ -148,6 +157,7 @@ fi # ************** Extract payload *************************** declare -rg TMPDIR=$(mktemp -d) +export TMPDIR [ -z "$TMPDIR" ] && perror "Could not create temporary directory for installer" dd "bs=$PAYLOAD_OFFSET" "if=$0" skip=1 | tar -z -x -C "$TMPDIR" RET=$? @@ -205,8 +215,13 @@ if [ -n "$TGZ_SLXADMIN" ]; then [ -e "$TMPDIR/$TGZ_SLXADMIN" ] || perror "$TGZ_SLXADMIN missing from payload." echo "* SLX-Admin: $CURRENT_WEBIF_VERSION -> $TARGET_WEBIF_VERSION" # Test archive - tar tf "$TMPDIR/$TGZ_SLXADMIN" >/dev/null 2>&1 || perror "Could not read $TGZ_SLXADMIN" + INCMODS=$(mktemp) + tar tf "$TMPDIR/$TGZ_SLXADMIN" | grep -oP '^modules-available/[^/]+/$' > "$INCMODS" || perror "Could not read $TGZ_SLXADMIN" + # Remove old files - wipe selectively, just in case someone added a new module by hand rm -rf -- "$PATH_SLXADMIN/"{inc,apis,modules,templates,Mustache,script,style} + while read -r line || [[ -n "$line" ]]; do + rm -rf -- "$PATH_SLXADMIN/$line" + done < "$INCMODS" tar -x -C "$PATH_SLXADMIN" -f "$TMPDIR/$TGZ_SLXADMIN" || perror "Could not extract $TGZ_SLXADMIN to $PATH_SLXADMIN" rm -f -- "$PATH_SLXADMIN/config.php.example" # New config.php supplied -- cgit v1.2.3-55-g7522