From 6fa1764201644b0dec129d005381ee498962e605 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 19 Aug 2013 16:24:23 +0200 Subject: [rootfs-stage31] changed the way stage3.1 gets the config, config.tgz and stage32.sqfs. Now its given in the kernel cmdline as 'slxsrv' a list of server ips and 'slxbase' a subdirectory of these servers where the config stuff roams. Example: slxsrv='132.230.4.1' and slxbase='u13' would make the scripts download '132.230.4.1/u13/config' and so on. PLEASE ADAPT YOUR CONFIGS BEFORE TRYING THIS OUT --- .../rootfs-stage31/data/bin/activate_sysconfig | 66 ++++++-------------- .../rootfs/rootfs-stage31/data/bin/setup_network | 2 + .../rootfs/rootfs-stage31/data/bin/setup_stage32 | 47 ++++++++++++++ remote/rootfs/rootfs-stage31/data/etc/functions | 71 +++++++++++++++++----- remote/rootfs/rootfs-stage31/data/init | 55 +++++------------ 5 files changed, 140 insertions(+), 101 deletions(-) create mode 100755 remote/rootfs/rootfs-stage31/data/bin/setup_stage32 diff --git a/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig index 0d8d33c4..9c21565a 100755 --- a/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig +++ b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig @@ -1,40 +1,15 @@ #!/bin/bash -# first a few variables -CONFIG="/mnt/opt/openslx/config" +echo "Configuring stage 3.2 ..." -# 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 +# include /etc/functions +. /etc/functions || drop_shell "Could not source /etc/functions." -######################################################################### -# -# 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 -} +# first a few variables +CONFIG="${FUTURE_ROOT}/opt/openslx/config" + +# parse kernel command line to determine the base for the URLs +SLX_BASE=$(read_from_cmdline "slxbase") ######################################################################### # @@ -42,9 +17,9 @@ download() { # fetch_sysconfig() { [ -e "$CONFIG" ] && grep '^#_RCONFIG_TAG$' "$CONFIG" > /dev/null \ - && echo "Config already fetched." && exit 0 + && echo "Config already fetched." && return 0 - download "$URL" "$CONFIG-remote" || exit 1 + download "${SLX_BASE}/config" "${CONFIG}-remote" || return 1 echo "# Config fetched from $URL" >> "$CONFIG" echo "#_RCONFIG_TAG" >> "$CONFIG" @@ -55,11 +30,9 @@ fetch_sysconfig() { # 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 + [ -e "${CONFIG}.tgz" ] && echo "config.tgz already downloaded." && exit 0 - tar xf "$CONFIG.tgz" -C /mnt || { echo "Could not untar $CONFIG.tgz to /mnt"; exit 1; } - exit 0 + download "${SLX_BASE}/config.tgz" "${CONFIG}.tgz" || return 1 } @@ -69,9 +42,8 @@ fetch_config_files() { # 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." + [ ! -e "${CONFIG}" ] && { echo "Cannot update. '$CONFIG' does not exist."; return 1; } + [ ! -e "${CONFIG}.tgz" ] && { echo "Cannot update. '$CONFIG' does not exist."; return 1; } # write IP configuration to $CONFIG cat >> "$CONFIG" </dev/tty1 2>&1' -} - # set PATH correctly export PATH=/bin:/sbin:/usr/bin:/usr/sbin export LD_LIBRARY_PATH=/usr/lib64 +# import common functions +. /etc/functions + # mount the important standard directories mount -n -t tmpfs -o 'mode=755' run "/run" [ ! -f /proc/cpuinfo ] && mount -n -t proc proc /proc @@ -81,44 +77,21 @@ if [ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ]; then plymouthd && plymouth show-splash fi +[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell: before network." -echo "Copying busybox etc. to stage32..." -tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/" +. "/bin/setup_network" || drop_shell "Error setting up network" -[ $DEBUG -ge 4 ] && drop_shell "Requested Debug Shell (before network)." +[ $DEBUG -ge 3 ] && drop_shell "Requested Debug Shell: after network/before configuring." -echo "Setup networking..." # Source script so the variables are still available to us -. "/bin/setup_network" || drop_shell "Error setting up network" +. "/bin/activate_sysconfig" || drop_shell "Could not source /bin/activate_sysconfig" -# mount rootfs -if [ -n "$NFS" ]; then - # mount stage32 per NFS if activated - echo "Mounting stage 3.2 as NFS..." - mount -t nfs -o ro,async,nolock ${NFSSERVER}:${NFSPATH} /rorootfs || drop_shell "Problem mounting NFS-Directory from ${NFSSERVER}:${NFSPATH}." -else - # or per squashfs else - echo "Mounting stage 3.2 as SquashFS..." - mount -t squashfs /mnt/*.sqfs /rorootfs || drop_shell "Problem mounting Squashfs." -fi - -[ $DEBUG -ge 3 ] && drop_shell "Requested Debug Shell: squashfs/nfs mounted, before aufs." - -echo "Building aufs..." -#mount -t overlayfs -o lowerdir=/rorootfs,upperdir=/dev/shm/uniontmp overlayfs /mnt -mount -n -t aufs -o "br:${FUTURE_ROOT}:/rorootfs=ro" none /mnt || drop_shell "Problem building aufs." -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/before configuring." - -# 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 -done +[ $DEBUG -ge 2 ] && drop_shell "Requested Debug Shell: after configuration/before stage32." + +. "/bin/setup_stage32" || drop_shell "Problem setting up stage3.2" + +# copy files needed for stage3.2 to FUTURE_ROOT +[ $DEBUG -ge 1 ] && echo "Copying busybox etc. to stage32..." +tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" "/etc/functions" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/" # one last debug shell if activated [ $DEBUG -ge 1 ] && drop_shell "Requested Debug Shell: before switch_root." -- cgit v1.2.3-55-g7522