From c0dbebf88d3f26b5e39cf0e122a39c55a4f3537c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 8 Feb 2016 17:42:44 +0100 Subject: [SSUS] Some progress, appending archive works, detecting slxadmin version works --- .gitignore | 2 + satellit_upgrader/installer.template.sh | 67 -------------------------------- satellit_upgrader/pack-update.sh | 41 ++++++++++++++++++++ satellit_upgrader/updater.template.sh | 68 +++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 67 deletions(-) delete mode 100755 satellit_upgrader/installer.template.sh create mode 100755 satellit_upgrader/pack-update.sh create mode 100644 satellit_upgrader/updater.template.sh diff --git a/.gitignore b/.gitignore index 468f13f..9e865ab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *.so /satellit_installer/config/ /satellit_installer/static_files/new_passwords.encrypted +/satellit_upgrader/files/ +/satellit_upgrader/updater.sh diff --git a/satellit_upgrader/installer.template.sh b/satellit_upgrader/installer.template.sh deleted file mode 100755 index e5bdd75..0000000 --- a/satellit_upgrader/installer.template.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -# Use special param to make sure we're running under bash (in case user does "sh install.sh") -[ "x$1" != "x--exec-self" ] && exec /bin/bash "$0" --exec-self "$@" - -IGNORE_ERRORS= -while [ $# -gt 0 ]; do - [ "x$1" = "x--ignore-errors" ] && IGNORE_ERRORS=jup - shift -done - -declare -rg SELFPID=$$ -perror () { - if [ -n "$IGNORE_ERRORS" ]; then - echo "[ERROR] $@" - return 0 - fi - echo "[FATAL] $@" - [ "$$" != "$SELFPID" ] && kill "$SELFPID" - exit 1 -} - -if [ "$UID" != "0" ]; then - perror "Must be running as root" -fi - -# ** Extract value from text file containing key=value pairs -extractfield () { - grep -m1 "^\s*$2\b" "$1" | awk -F '=' '{print $2}' | sed 's/\s//g' -} - -# ** Wrap mysql command line client so we're always using the deb-sys-maint credentials -mysql () { - "$(which mysql)" --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 "$@" -} - -# ** Constants - to be patched by the packaging script -declare -rg TARGET_WEBIF_VERSION="%TARGET_WEBIF_VERSION%" -declare -rg PAYLOAD_OFFSET="%PAYLOAD_OFFSET%" - -# ** 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" -fi -if [ -z "$PAYLOAD_OFFSET" ] || [[ "$PAYLOAD_OFFSET" == %*% ]]; then - perror "Bad upgrader: PAYLOAD_OFFSET not set" -fi - -# ********************************************************** - -# Get current webif version -declare -rg CURRENT_WEBIF_VERSION=$(mysql -e 'SELECT value FROM openslx.property WHERE name = "webif-version" LIMIT 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" - -# 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" - - -# File end -exit 0 -# Payload to follow - diff --git a/satellit_upgrader/pack-update.sh b/satellit_upgrader/pack-update.sh new file mode 100755 index 0000000..71f24b6 --- /dev/null +++ b/satellit_upgrader/pack-update.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +declare -rg SELFPID=$$ +perror () { + if [ -n "$IGNORE_ERRORS" ]; then + echo "[ERROR] $@" + return 0 + fi + echo "[FATAL] $@" + [ "$$" != "$SELFPID" ] && kill "$SELFPID" + exit 1 +} + +#declare -rg TMPDIR=$(mktemp -d) +#[ -d "$TMPDIR" ] || perror "TMPDIR fail." +declare -rg UPDATER="updater.sh" + +cp "updater.template.sh" "$UPDATER" || perror "could not copy template" +chmod +x "$UPDATER" + +# Replace variables +# slxadmin version +echo -n "Includes SLX-Admin: " +if [ -e "files/slx-admin.tar.gz" ]; 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]+') + [ -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" +else + echo "no" +fi +# Last patch: Payload offset +# Calc payload offset, which is tricky as the size changes as we patch +SIZE=$(stat -c %s "$UPDATER") +SIZE=$(( ( $SIZE / 1024 ) * 1024 + 1024 )) +sed -i "s/%PAYLOAD_OFFSET%/${SIZE}/" "$UPDATER" || perror "could not patch payload variable in updater" +# Truncate, append payload +truncate --size="$SIZE" "$UPDATER" || perror "Could not truncate updater to $SIZE bytes" +tar ckz files/* >> "$UPDATER" || perror "Could not append payload to updater" + diff --git a/satellit_upgrader/updater.template.sh b/satellit_upgrader/updater.template.sh new file mode 100644 index 0000000..5f7a4b5 --- /dev/null +++ b/satellit_upgrader/updater.template.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Use special param to make sure we're running under bash (in case user does "sh install.sh") +[ "x$1" != "x--exec-self" ] && exec /bin/bash "$0" --exec-self "$@" + +IGNORE_ERRORS= +while [ $# -gt 0 ]; do + [ "x$1" = "x--ignore-errors" ] && IGNORE_ERRORS=jup + shift +done + +declare -rg SELFPID=$$ +perror () { + if [ -n "$IGNORE_ERRORS" ]; then + echo "[ERROR] $@" + return 0 + fi + echo "[FATAL] $@" + [ "$$" != "$SELFPID" ] && kill "$SELFPID" + exit 1 +} + +if [ "$UID" != "0" ]; then + perror "Must be running as root" +fi + +# ** Extract value from text file containing key=value pairs +extractfield () { + grep -m1 "^\s*$2\b" "$1" | awk -F '=' '{print $2}' | sed 's/\s//g' +} + +# ** Wrap mysql command line client so we're always using the deb-sys-maint credentials +mysql () { + "$(which mysql)" --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 "$@" +} + +# ** Constants - to be patched by the packaging script +declare -rg TARGET_WEBIF_VERSION="%TARGET_WEBIF_VERSION%" +declare -rg PAYLOAD_OFFSET="%PAYLOAD_OFFSET%" + +# ** 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" +fi +if [ -z "$PAYLOAD_OFFSET" ] || [[ "$PAYLOAD_OFFSET" == %*% ]]; then + perror "Bad upgrader: PAYLOAD_OFFSET not set" +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" + +# 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" + +# File end +exit 0 +# Payload to follow + -- cgit v1.2.3-55-g7522