summaryrefslogtreecommitdiffstats
path: root/remote/rootfs
diff options
context:
space:
mode:
authorJonathan Bauer2013-08-15 16:20:44 +0200
committerJonathan Bauer2013-08-15 16:20:44 +0200
commit9d485e473e368ef50fe98cfdb11bee6095a53a40 (patch)
tree1610123cf2b0c3de4a372b99ca8967a23c538d52 /remote/rootfs
parentupdate stage4 filter list (diff)
downloadtm-scripts-9d485e473e368ef50fe98cfdb11bee6095a53a40.tar.gz
tm-scripts-9d485e473e368ef50fe98cfdb11bee6095a53a40.tar.xz
tm-scripts-9d485e473e368ef50fe98cfdb11bee6095a53a40.zip
[stage31] move configuration of stage32 into /bin/activate_sysconfig.
Diffstat (limited to 'remote/rootfs')
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/activate-sysconfig67
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/activate_sysconfig103
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/setup_network (renamed from remote/rootfs/rootfs-stage31/data/bin/setup-network)0
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/init40
4 files changed, 116 insertions, 94 deletions
diff --git a/remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig b/remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig
deleted file mode 100755
index bfda70e1..00000000
--- a/remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/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
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..0d8d33c4
--- /dev/null
+++ b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig
@@ -0,0 +1,103 @@
+#!/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 function downloads the config containing environment variables
+#
+fetch_sysconfig() {
+ [ -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 function downloads the config.tgz and unpacks it to $TARGET_PATH
+#
+fetch_config_files() {
+ [ -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
+}
+
+
+#########################################################################
+#
+# This function updates the downloaded config with the IP information
+# received from /bin/setup_network
+update_sysconfig() {
+ # sanity checks
+ [ ! -e "$CONFIG" ] && { echo "Cannot update $CONFIG: file does not exist!"; exit 1; }
+ [ -z "$CLIENTIP" -o -z "$SERVERIP" -o -z "$BRIDGEMAC" -o -z "$GATEWAY" -o -z "$DNS_SERVER" ] \
+ && echo "Something seems wrong with the IP information read from /bin/setup_network ... going on."
+
+ # write IP configuration to $CONFIG
+cat >> "$CONFIG" <<HEREEND
+# IP Config written in stage31
+SLX_PXE_CLIENT_IP='$CLIENTIP'
+SLX_PXE_SERVER_IP='$SERVERIP'
+SLX_PXE_GATEWAY='$GATEWAY'
+SLX_PXE_DNS='$DNS_SERVER'
+SLX_PXE_MAC='$BRIDGEMAC'
+HEREEND
+
+ # setup hardware clock
+ . /mnt/opt/openslx/config
+ if [ "x$SLX_BIOS_CLOCK" == "xlocal" ]; then
+ hwclock -s -l
+ elif [ "x$SLX_BIOS_CLOCK" == "xutc" ]; then
+ hwclock -s -u
+ fi
+}
+
+
+#########################################################################
+#
+# MAIN PART
+#
+
+fetch_sysconfig || exit 1
+fetch_config_files || exit 1
+update_sysconfig || exit 1
diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup-network b/remote/rootfs/rootfs-stage31/data/bin/setup_network
index 93ecd75f..93ecd75f 100755
--- a/remote/rootfs/rootfs-stage31/data/bin/setup-network
+++ b/remote/rootfs/rootfs-stage31/data/bin/setup_network
diff --git a/remote/rootfs/rootfs-stage31/data/init b/remote/rootfs/rootfs-stage31/data/init
index db394c8d..8b971081 100755
--- a/remote/rootfs/rootfs-stage31/data/init
+++ b/remote/rootfs/rootfs-stage31/data/init
@@ -88,7 +88,7 @@ tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" | tar -xp -C "${FUTURE_ROOT}/opt/o
[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell (before network)."
echo "Setup networking..." # Source script so the variables are still available to us
-. "/bin/setup_network" || echo "Error setting up network"
+. "/bin/setup_network" || drop_shell "Error setting up network"
# mount rootfs
if [ -n "$NFS" ]; then
@@ -110,41 +110,27 @@ mkdir -p /mnt/opt/openslx/uniontmp /mnt/tmp
mount -n --move "$FUTURE_ROOT" /mnt/opt/openslx/uniontmp || drop_shell "Problem moving uniontmp."
FUTURE_ROOT="/mnt"
-[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after aufs'ing."
+[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after aufs'ing/before configuring."
-# Download config if available
-/bin/activate-sysconfig 2> /dev/null
-if [ ! -e /mnt/opt/openslx/config ]; then
- sleep 1
- /bin/activate-sysconfig
-fi
-if [ -e /mnt/opt/openslx/config ]; then
- . /mnt/opt/openslx/config
- if [ "x$SLX_BIOS_CLOCK" == "xlocal" ]; then
- hwclock -s -l
- elif [ "x$SLX_BIOS_CLOCK" == "xutc" ]; then
- hwclock -s -u
+# Download config. Try 5 times with increasing sleeps.
+for TIMEOUT in 1 2 3 4 5; do
+ if [ ! -e /mnt/opt/openslx/config ]; then
+ /bin/activate_sysconfig
+ sleep $TIMEOUT
fi
-fi
-
-# create ip config
-cat >> /mnt/opt/openslx/config <<HEREEND
-# IP Config written in stage31
-SLX_PXE_CLIENT_IP='$CLIENTIP'
-SLX_PXE_SERVER_IP='$SERVERIP'
-SLX_PXE_GATEWAY='$GATEWAY'
-SLX_PXE_DNS='$DNS_SERVER'
-SLX_PXE_MAC='$BRIDGEMAC'
-HEREEND
+done
+# one last debug shell if activated
[ $DEBUG -ge 1 ] && drop_shell "Requested Debug Shell: before switch_root."
+# tell plymouth about the immediate rootfs switch
+[ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ] && plymouth update-root-fs --new-root-dir=/mnt
+
+# unmount filesystems
for mnt in proc sys run ; do
umount -n "$mnt"
done
echo "Switching root...."
unset BOOT_IMAGE initrd
-[ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ] && plymouth update-root-fs --new-root-dir=/mnt
-# new style of pivoting (switch_root or run-init)
exec /sbin/switch_root -c /dev/console /mnt /usr/lib/systemd/systemd