summaryrefslogtreecommitdiffstats
path: root/satellit_upgrader
diff options
context:
space:
mode:
authorSimon Rettberg2016-02-04 13:12:41 +0100
committerSimon Rettberg2016-02-04 13:12:41 +0100
commit539d1d6291891cb2bca0232547290e3412eb055e (patch)
treef229e08165af9ed9a7bc1854357a89ab324d1ef7 /satellit_upgrader
parent[SSPS] Grant sat user SELECT on openslx.location (diff)
downloadsetup-scripts-539d1d6291891cb2bca0232547290e3412eb055e.tar.gz
setup-scripts-539d1d6291891cb2bca0232547290e3412eb055e.tar.xz
setup-scripts-539d1d6291891cb2bca0232547290e3412eb055e.zip
[SSUS] Start work on the satellite server upgrade script
Diffstat (limited to 'satellit_upgrader')
-rwxr-xr-xsatellit_upgrader/installer.template.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/satellit_upgrader/installer.template.sh b/satellit_upgrader/installer.template.sh
new file mode 100755
index 0000000..e5bdd75
--- /dev/null
+++ b/satellit_upgrader/installer.template.sh
@@ -0,0 +1,67 @@
+#!/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
+