diff options
author | Simon Rettberg | 2016-02-09 17:49:56 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-02-09 17:49:56 +0100 |
commit | 1c558f5bff8f1f9a17778babf0979b6668f2db3d (patch) | |
tree | 5c537169664e766a6676408008e51a948edd3e2e /satellit_upgrader | |
parent | [SSUS] Some progress, appending archive works, detecting slxadmin version works (diff) | |
download | setup-scripts-1c558f5bff8f1f9a17778babf0979b6668f2db3d.tar.gz setup-scripts-1c558f5bff8f1f9a17778babf0979b6668f2db3d.tar.xz setup-scripts-1c558f5bff8f1f9a17778babf0979b6668f2db3d.zip |
[SSUS] Finish update functionality for slx-admin
Diffstat (limited to 'satellit_upgrader')
-rwxr-xr-x | satellit_upgrader/pack-update.sh | 14 | ||||
-rw-r--r-- | satellit_upgrader/updater.template.sh | 40 |
2 files changed, 49 insertions, 5 deletions
diff --git a/satellit_upgrader/pack-update.sh b/satellit_upgrader/pack-update.sh index 71f24b6..33bbfc5 100755 --- a/satellit_upgrader/pack-update.sh +++ b/satellit_upgrader/pack-update.sh @@ -11,9 +11,17 @@ perror () { exit 1 } +patchtgz () { + [ -z "$1" ] && perror "patchtgz call failure" + local VARNAME="$1" + local VALUE="$2" + sed -i "s,%${VARNAME}%,${VALUE},g" "$UPDATER" || perror "could not patchtgz $VARNAME in updater" +} + #declare -rg TMPDIR=$(mktemp -d) #[ -d "$TMPDIR" ] || perror "TMPDIR fail." declare -rg UPDATER="updater.sh" +declare -rg TGZ_SLXADMIN="files/slx-admin.tar.gz" cp "updater.template.sh" "$UPDATER" || perror "could not copy template" chmod +x "$UPDATER" @@ -21,14 +29,16 @@ chmod +x "$UPDATER" # Replace variables # slxadmin version echo -n "Includes SLX-Admin: " -if [ -e "files/slx-admin.tar.gz" ]; then +if [ -e "$TGZ_SLXADMIN" ]; then echo "yes" - VERS=$(tar -xOf "files/slx-admin.tar.gz" "inc/database.inc.php" | grep -A3 'function getExpectedSchemaVersion' | grep -o -E 'return [0-9]+' | grep -o -E '[0-9]+') + VERS=$(tar -xOf "$TGZ_SLXADMIN" "inc/database.inc.php" | grep -A3 'function getExpectedSchemaVersion' | grep -o -E 'return [0-9]+' | grep -o -E '[0-9]+') [ -n "$VERS" ] || perror "Could not extract slx-admin version!" echo "Version: $VERS" sed -i "s/%TARGET_WEBIF_VERSION%/${VERS}/" "$UPDATER" || perror "could not patch slxadmin version in updater" + patchtgz "TGZ_SLXADMIN" "$TGZ_SLXADMIN" else echo "no" + patchtgz "TGZ_SLXADMIN" fi # Last patch: Payload offset # Calc payload offset, which is tricky as the size changes as we patch 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 |