From ab59ae08b63f4617207a858dff18ac07caf8a83e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 10 Feb 2016 18:49:11 +0100 Subject: [SSUS] Updating more packages works --- satellit_upgrader/updater.template.sh | 83 +++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 8 deletions(-) (limited to 'satellit_upgrader/updater.template.sh') diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh index 427d288..f02e57f 100644 --- a/satellit_upgrader/updater.template.sh +++ b/satellit_upgrader/updater.template.sh @@ -12,14 +12,21 @@ done declare -rg SELFPID=$$ perror () { if [ -n "$IGNORE_ERRORS" ]; then - echo "[ERROR] $@" + echo -n -e '\033[01;31m[ERROR]\033[00m ' + echo "$@" return 0 fi - echo "[FATAL] $@" + echo -n -e '\033[01;31m[FATAL]\033[00m ' + echo "$@" [ "$$" != "$SELFPID" ] && kill "$SELFPID" exit 1 } +pwarning () { + echo -n -e '\033[01;33m[WARNING]\033[00m ' + echo "$@" +} + if [ "$UID" != "0" ]; then perror "Must be running as root" fi @@ -34,13 +41,24 @@ mysql () { "$(which mysql)" --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 "$@" } +# ** Restart given systemd service, warn if it fails but do not bail out +restart_service () { + systemctl restart "$1" || pwarning "Could not restart service $1 - !! YOU SHOULD REBOOT THE SERVER !!" +} + # ** Constants - to be patched by the packaging script declare -rg TARGET_WEBIF_VERSION="%TARGET_WEBIF_VERSION%" declare -rg TGZ_SLXADMIN="%TGZ_SLXADMIN%" +declare -rg TGZ_DOZMOD="%TGZ_DOZMOD%" +declare -rg TGZ_TASKMANAGER="%TGZ_TASKMANAGER%" +declare -rg TGZ_TFTP="%TGZ_TFTP%" declare -rg PAYLOAD_OFFSET="%PAYLOAD_OFFSET%" # ** Constants - hardcoded or determined at runtime declare -rg PATH_SLXADMIN="/srv/openslx/www/slx-admin" +declare -rg PATH_DOZMOD="/opt/dmsd" +declare -rg PATH_TASKMANAGER="/opt/taskmanager" +declare -rg PATH_TFTP="/srv/openslx/tftp" # ** Check if constants have been filled, bail out otherwise if [ -z "$TARGET_WEBIF_VERSION" ] || [[ "$TARGET_WEBIF_VERSION" == %*% ]]; then @@ -90,13 +108,62 @@ if [ -n "$TGZ_SLXADMIN" ]; then fi # ************************* Dozmod ************************* -echo "* Dozentenmodul" -echo "Adjusting mysql permissions of user sat" -mysql -e 'GRANT CREATE, ALTER ON sat.* TO sat@localhost' || perror "Could not GRANT permissions ON sat.* to sat@localhost" -mysql -e 'GRANT SELECT ON openslx.location TO sat@localhost' || perror "Could not GRANT permissions ON openslx.location to sat@localhost" +if [ -n "$TGZ_DOZMOD" ]; then + [ -e "$TMPDIR/$TGZ_DOZMOD" ] || perror "$TGZ_DOZMOD missing from payload." + echo "* Dozentenmodul" + echo "Adjusting mysql permissions of user sat" + mysql -e 'GRANT CREATE, ALTER ON sat.* TO sat@localhost' || perror "Could not GRANT permissions ON sat.* to sat@localhost" + mysql -e 'GRANT SELECT ON openslx.location TO sat@localhost' || perror "Could not GRANT permissions ON openslx.location to sat@localhost" + echo "Extracting new jar" + tar -x -C "$PATH_DOZMOD" -f "$TMPDIR/$TGZ_DOZMOD" || perror "Could not extract $TGZ_DOZMOD to $PATH_DOZMOD" + if mysql -e 'SHOW TABLES' openslx | grep -q '^location$'; then + echo "Enabling location feature" + sed -i '/^db.location-table\b/d' "$PATH_DOZMOD/config.properties" + echo 'db.location-table = openslx.location' >> "$PATH_DOZMOD/config.properties" + fi + chmod 0640 "$PATH_DOZMOD/config.properties" + chown root:images "$PATH_DOZMOD/config.properties" + echo "Restarting service" + restart_service dmsd + echo "Dozentenmodul Server Daemon upgrade complete" +fi +# ********************** Taskmanager *********************** +if [ -n "$TGZ_TASKMANAGER" ]; then + [ -e "$TMPDIR/$TGZ_TASKMANAGER" ] || perror "$TGZ_TASKMANAGER missing from payload" + echo "* Task manager" + echo "Extracting new jar and data" + # Replacement trick (see slxadmin) + tar -x -C "$PATH_TASKMANAGER" -f "$TMPDIR/$TGZ_TASKMANAGER" || perror "Could not extract $TGZ_TASKMANAGER to $PATH_TASKMANAGER" + rm -rf -- "$PATH_TASKMANAGER/data" "$PATH_TASKMANAGER/scripts" "$PATH_TASKMANAGER/plugins" + tar -x -C "$PATH_TASKMANAGER" -f "$TMPDIR/$TGZ_TASKMANAGER" + echo "Restarting service" + restart_service taskmanager + echo "Taskmanager upgrade complete" +fi + +# ************************** TFTP ************************** +if [ -n "$TGZ_TFTP" ]; then + [ -e "$TMPDIR/$TGZ_TFTP" ] || perror "$TGZ_TFTP missing from payload" + echo "* TFTP" + echo "Extracting new jar and data" + rm -rf -- "$PATH_TFTP" + mkdir -p "$PATH_TFTP" + tar -x -C "$PATH_TFTP" -f "$TMPDIR/$TGZ_TFTP" || perror "Could not extract $TGZ_TFTP to $PATH_TFTP" + chown -R taskmanager:taskmanager "$PATH_TFTP" + echo "Resetting pxe menu" + mysql -e 'UPDATE openslx.property SET value = "invalid" WHERE name = "server-ip"' || pwarning "Could not reset pxe menu status; manual regeneration of menu required" + echo "TFTP upgrade complete" +fi + +# ********************** lighttpd config ******************* +if [ -e "$TMPDIR/lighttpd.conf" ] && [ -e "/etc/lighttpd/lighttpd.conf" ]; then + echo "* Replacing lighttpd.conf" + cp "$TMPDIR/lighttpd.conf" "/etc/lighttpd/lighttpd.conf" || perror "Could not replace /etc/lighttpd/lighttpd.conf" + restart_service lighttpd + echo "lighttpd config upgrade complete" +fi -# File end exit 0 -# Payload to follow +# File end -- cgit v1.2.3-55-g7522