diff options
Diffstat (limited to 'remote/rootfs')
| -rwxr-xr-x | remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig b/remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig new file mode 100755 index 00000000..bfda70e1 --- /dev/null +++ b/remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig @@ -0,0 +1,67 @@ +#!/bin/bash + +# first a few variables +CONFIG="/mnt/opt/openslx/config" + +# parse kernel command line to determine the URL +URL="$(grep -o -E "slxconfig=\S+" /proc/cmdline | cut -c 11-)" +if [ -z "$URL" ]; then + echo "Error - 'slxconfig=' not found in command line, or empty" + exit 1 +fi + +######################################################################### +# +# Helper function to download given FILE_URL under TARGET_PATH +# +# Usage: +# download $FILE_URL $TARGET_PATH +# + +download() { + [ $# -ne 2 ] && echo "Error - 'download' requires 2 arguements, $# given." \ + && exit 1 + + local FILE_URL="$1" + local TARGET_PATH="$2" + + wget -T 5 -q -O "$TARGET_PATH" "$FILE_URL" + RET=$? + if [ "x$RET" != "x0" ]; then + echo "Error - downloading '$FILE_URL' via wget failed. Exit Code: $RET" + exit 1 + else + echo "Successfully downloaded '$FILE_URL'." + fi + + return 0 +} + +######################################################################### +# +# +# This first part downloads the config containing environment variables +# +# + +[ -e "$CONFIG" ] && grep '^#_RCONFIG_TAG$' "$CONFIG" > /dev/null \ + && echo "Config already fetched." && exit 0 + +download "$URL" "$CONFIG-remote" || exit 1 + +echo "# Config fetched from $URL" >> "$CONFIG" +echo "#_RCONFIG_TAG" >> "$CONFIG" +cat "${CONFIG}-remote" >> "$CONFIG" + +######################################################################### +# +# +# This part downloads the config.tgz and unpacks it to $1 +# +# + +[ -e "$CONFIG.tgz" ] && echo "config.tgz already downloaded." && exit 0 +download "$URL.tgz" "$CONFIG.tgz" || exit 1 + +tar xf "$CONFIG.tgz" -C /mnt || { echo "Could not untar $CONFIG.tgz to /mnt"; exit 1; } +exit 0 |
