From 1c558f5bff8f1f9a17778babf0979b6668f2db3d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 9 Feb 2016 17:49:56 +0100 Subject: [SSUS] Finish update functionality for slx-admin --- satellit_upgrader/updater.template.sh | 40 ++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'satellit_upgrader/updater.template.sh') diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh index 5f7a4b5..427d288 100644 --- a/satellit_upgrader/updater.template.sh +++ b/satellit_upgrader/updater.template.sh @@ -36,8 +36,12 @@ mysql () { # ** Constants - to be patched by the packaging script declare -rg TARGET_WEBIF_VERSION="%TARGET_WEBIF_VERSION%" +declare -rg TGZ_SLXADMIN="%TGZ_SLXADMIN%" declare -rg PAYLOAD_OFFSET="%PAYLOAD_OFFSET%" +# ** Constants - hardcoded or determined at runtime +declare -rg PATH_SLXADMIN="/srv/openslx/www/slx-admin" + # ** Check if constants have been filled, bail out otherwise if [ -z "$TARGET_WEBIF_VERSION" ] || [[ "$TARGET_WEBIF_VERSION" == %*% ]]; then perror "Bad upgrader: TARGET_WEBIF_VERSION not set" @@ -51,16 +55,46 @@ fi # Get current webif version declare -rg CURRENT_WEBIF_VERSION=$(mysql -e 'SELECT value FROM openslx.property WHERE name = "webif-version" LIMIT 1' | tail -n 1) [ -z "$CURRENT_WEBIF_VERSION" ] && perror "Could not determine current webif version" -[ "$CURRENT_WEBIF_VERSION" -le "$TARGET_WEBIF_VERSION" ] || perror "This update seems to be older than the server version you're currently running" +if [ "$TARGET_WEBIF_VERSION" = "missing" ] || [ "$CURRENT_WEBIF_VERSION" -le "$TARGET_WEBIF_VERSION" ]; then + : +else + perror "This update seems to be older than the server version you're currently running" +fi -# Extract payload +# ************** Extract payload *************************** TMPDIR=$(mktemp -d) [ -z "$TMPDIR" ] && perror "Could not create temporary directory for installer" dd "bs=$PAYLOAD_OFFSET" "if=$0" skip=1 | tar -z -x -C "$TMPDIR" RET=$? [ "$RET" -ne 0 ] && perror "Extracting installer payload failed with exit code $RET" -echo "SLX-Admin: $CURRENT_WEBIF_VERSION -> $TARGET_WEBIF_VERSION" +# ********************************************************** + +# ************************** SLX-Admin ********************* +if [ -n "$TGZ_SLXADMIN" ]; then + [ -e "$TMPDIR/$TGZ_SLXADMIN" ] || perror "$TGZ_SLXADMIN missing from payload." + echo "* SLX-Admin: $CURRENT_WEBIF_VERSION -> $TARGET_WEBIF_VERSION" + # Cheap hack: extract, then delete, extract again to get rid of old unused files. If the extraction fails, we don't leave + # the user with a broken webif, because we didn't remove the directories yet + tar -x -C "$PATH_SLXADMIN" -f "$TMPDIR/$TGZ_SLXADMIN" || perror "Could not extract $TGZ_SLXADMIN to $PATH_SLXADMIN" + rm -rf -- "$PATH_SLXADMIN/inc" "$PATH_SLXADMIN/apis" "$PATH_SLXADMIN/modules" "$PATH_SLXADMIN/templates" + tar -x -C "$PATH_SLXADMIN" -f "$TMPDIR/$TGZ_SLXADMIN" + rm -- "$PATH_SLXADMIN/config.php.example" + chmod -R go+rX-w,u+rwX "$PATH_SLXADMIN" + chown -R root:root "$PATH_SLXADMIN" + chmod 0640 "$PATH_SLXADMIN/config.php" + chown root:www-data "$PATH_SLXADMIN/config.php" + curl -s "http://localhost/slx-admin/api.php?do=update" > /dev/null + curl -s "http://localhost/slx-admin/api.php?do=update" | grep -q 'Up to date' || perror "Updating the web interface database failed" + echo "Web interface upgrade complete" +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" + # File end exit 0 -- cgit v1.2.3-55-g7522