summaryrefslogtreecommitdiffstats
path: root/satellit_upgrader/pack-update.sh
diff options
context:
space:
mode:
authorSimon Rettberg2016-02-08 17:42:44 +0100
committerSimon Rettberg2016-02-08 17:42:44 +0100
commitc0dbebf88d3f26b5e39cf0e122a39c55a4f3537c (patch)
treec14bd599e23ad630720f4f96ad7f8181614cade8 /satellit_upgrader/pack-update.sh
parent[SSUS] Start work on the satellite server upgrade script (diff)
downloadsetup-scripts-c0dbebf88d3f26b5e39cf0e122a39c55a4f3537c.tar.gz
setup-scripts-c0dbebf88d3f26b5e39cf0e122a39c55a4f3537c.tar.xz
setup-scripts-c0dbebf88d3f26b5e39cf0e122a39c55a4f3537c.zip
[SSUS] Some progress, appending archive works, detecting slxadmin version works
Diffstat (limited to 'satellit_upgrader/pack-update.sh')
-rwxr-xr-xsatellit_upgrader/pack-update.sh41
1 files changed, 41 insertions, 0 deletions
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"
+