From 77f6383ff873ae3d4d07cfab9b127dd16dcb2338 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 30 Jan 2014 14:43:21 +0100 Subject: [rfs] moved /etc/functions.inc to /inc/functions since we have that include directory :) --- .../rootfs/rootfs-stage31/data/etc/functions.inc | 91 ---------------------- remote/rootfs/rootfs-stage31/data/inc/functions | 91 ++++++++++++++++++++++ remote/rootfs/rootfs-stage31/data/init | 4 +- .../opt/openslx/scripts/systemd-setup_slx_addons | 2 +- 4 files changed, 94 insertions(+), 94 deletions(-) delete mode 100644 remote/rootfs/rootfs-stage31/data/etc/functions.inc create mode 100644 remote/rootfs/rootfs-stage31/data/inc/functions (limited to 'remote') diff --git a/remote/rootfs/rootfs-stage31/data/etc/functions.inc b/remote/rootfs/rootfs-stage31/data/etc/functions.inc deleted file mode 100644 index ce510aac..00000000 --- a/remote/rootfs/rootfs-stage31/data/etc/functions.inc +++ /dev/null @@ -1,91 +0,0 @@ -######################################################################### -# -# COMMON HELPER FUNCTIONS -# - -######################################################################### -# -# Function to drop a debug shell with an error message. -# -# Usage: -# drop_shell "This is your error message." -# -drop_shell() { - [ $# -gt 0 ] && echo $@ - echo "CTRL + D will continue booting." - setsid sh -c 'exec sh /dev/tty1 2>&1' -} - -######################################################################### -# -# Helper function to parse parameter named OPTION from the kernel command line (/proc/cmdline) -# -# Usage: -# read_from_cmdline OPTION -# -read_from_cmdline(){ - [ $# -ne 1 ] && echo "Error - 'read_from_cmdline' requires 1 argument, $# given." && exit 1 - - local OPTION="$1" - local VALUE="" - - VALUE="$(grep -o -E "${OPTION}=\S+" /proc/cmdline | cut -c $((${#OPTION}+2))-)" - if [ -z "$VALUE" ]; then - echo "Error - '${OPTION}=' not found in command line, or empty" - return 1 - else - echo "$VALUE" - fi -} - -######################################################################### -# -# Helper function to download given FILE_URL from servers in 'slxsrv' -# as given through the kernel command line. File will be saved under TARGET_PATH -# -# Usage: -# download FILE_URL TARGET_PATH -# -# Example: -# download "config" "/opt/openslx/config" -# -# Note: -# FILE_URL can have subpath, e.g. "ubuntu-13.04-x64/config" -# -download() { - [ $# -ne 2 ] && echo "Error - 'download' requires 2 arguments, $# given." && return 1 - - if [ -e "${FUTURE_ROOT}/opt/openslx/config" ]; then - . "${FUTURE_ROOT}/opt/openslx/config" || echo "Error - could not source '${FUTURE_ROOT}/opt/openslx/config'" - else - # read SLX_KCL_SERVERS from cmdline since we didn't get it from the config file. - SLX_KCL_SERVERS="$(read_from_cmdline "slxsrv" | tr ',' ' ')" - echo "SLX_KCL_SERVERS='$SLX_KCL_SERVERS'" >> "${FUTURE_ROOT}/opt/openslx/config" - fi - - local FILE_URL="$1" - local TARGET_PATH="$2" - - # Shuffle server list - local SERVERS=$(for SERVER in $SLX_CONFIG_SERVERS $SLX_KCL_SERVERS; do echo "$RANDOM $SERVER"; done | sort -u | sed -r 's/^[0-9]+ //') - - for TIMEOUT in 1 1 4 4 10; do - for SERVER in $SERVERS; do - rm -f "$TARGET_PATH" - wget -T 5 -q -O "$TARGET_PATH" "http://${SERVER}/${FILE_URL}" - RET=$? - if [ "x$RET" != "x0" -o ! -e "$TARGET_PATH" ]; then - echo "Error - downloading 'http://$SERVER/$FILE_URL' via wget failed. Exit Code: $RET" - usleep 50000 # 50ms - else - echo "Successfully downloaded 'http://${SERVER}/$FILE_URL'." - return 0 - fi - done - echo "Trying again in $(($TIMEOUT * 250)) ms..." - usleep $(($TIMEOUT * 250000)) - done - # Max retries reached, no success :-( - return 1 -} - diff --git a/remote/rootfs/rootfs-stage31/data/inc/functions b/remote/rootfs/rootfs-stage31/data/inc/functions new file mode 100644 index 00000000..ce510aac --- /dev/null +++ b/remote/rootfs/rootfs-stage31/data/inc/functions @@ -0,0 +1,91 @@ +######################################################################### +# +# COMMON HELPER FUNCTIONS +# + +######################################################################### +# +# Function to drop a debug shell with an error message. +# +# Usage: +# drop_shell "This is your error message." +# +drop_shell() { + [ $# -gt 0 ] && echo $@ + echo "CTRL + D will continue booting." + setsid sh -c 'exec sh /dev/tty1 2>&1' +} + +######################################################################### +# +# Helper function to parse parameter named OPTION from the kernel command line (/proc/cmdline) +# +# Usage: +# read_from_cmdline OPTION +# +read_from_cmdline(){ + [ $# -ne 1 ] && echo "Error - 'read_from_cmdline' requires 1 argument, $# given." && exit 1 + + local OPTION="$1" + local VALUE="" + + VALUE="$(grep -o -E "${OPTION}=\S+" /proc/cmdline | cut -c $((${#OPTION}+2))-)" + if [ -z "$VALUE" ]; then + echo "Error - '${OPTION}=' not found in command line, or empty" + return 1 + else + echo "$VALUE" + fi +} + +######################################################################### +# +# Helper function to download given FILE_URL from servers in 'slxsrv' +# as given through the kernel command line. File will be saved under TARGET_PATH +# +# Usage: +# download FILE_URL TARGET_PATH +# +# Example: +# download "config" "/opt/openslx/config" +# +# Note: +# FILE_URL can have subpath, e.g. "ubuntu-13.04-x64/config" +# +download() { + [ $# -ne 2 ] && echo "Error - 'download' requires 2 arguments, $# given." && return 1 + + if [ -e "${FUTURE_ROOT}/opt/openslx/config" ]; then + . "${FUTURE_ROOT}/opt/openslx/config" || echo "Error - could not source '${FUTURE_ROOT}/opt/openslx/config'" + else + # read SLX_KCL_SERVERS from cmdline since we didn't get it from the config file. + SLX_KCL_SERVERS="$(read_from_cmdline "slxsrv" | tr ',' ' ')" + echo "SLX_KCL_SERVERS='$SLX_KCL_SERVERS'" >> "${FUTURE_ROOT}/opt/openslx/config" + fi + + local FILE_URL="$1" + local TARGET_PATH="$2" + + # Shuffle server list + local SERVERS=$(for SERVER in $SLX_CONFIG_SERVERS $SLX_KCL_SERVERS; do echo "$RANDOM $SERVER"; done | sort -u | sed -r 's/^[0-9]+ //') + + for TIMEOUT in 1 1 4 4 10; do + for SERVER in $SERVERS; do + rm -f "$TARGET_PATH" + wget -T 5 -q -O "$TARGET_PATH" "http://${SERVER}/${FILE_URL}" + RET=$? + if [ "x$RET" != "x0" -o ! -e "$TARGET_PATH" ]; then + echo "Error - downloading 'http://$SERVER/$FILE_URL' via wget failed. Exit Code: $RET" + usleep 50000 # 50ms + else + echo "Successfully downloaded 'http://${SERVER}/$FILE_URL'." + return 0 + fi + done + echo "Trying again in $(($TIMEOUT * 250)) ms..." + usleep $(($TIMEOUT * 250000)) + done + # Max retries reached, no success :-( + return 1 +} + diff --git a/remote/rootfs/rootfs-stage31/data/init b/remote/rootfs/rootfs-stage31/data/init index 250767e3..fe521ddb 100755 --- a/remote/rootfs/rootfs-stage31/data/init +++ b/remote/rootfs/rootfs-stage31/data/init @@ -16,7 +16,7 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin # import common functions -. "/etc/functions.inc" +. "/inc/functions" # mount the important standard directories busybox mount -n -t tmpfs -o 'mode=755' run "/run" @@ -86,7 +86,7 @@ done # copy files needed for stage3.2 to FUTURE_ROOT echo "Copying busybox etc. to stage32..." -tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" "/etc/functions.inc" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/" +tar -cp "/bin" "/sbin" "/usr/bin" "/usr/sbin" "/inc/functions" | tar -xp -C "${FUTURE_ROOT}/opt/openslx/" # set the SLX_ROOT_PASS if given in config if [ ! -z "$SLX_ROOT_PASS" ]; then diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_slx_addons b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_slx_addons index f1253602..c7ce64b9 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_slx_addons +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_slx_addons @@ -20,7 +20,7 @@ [ -z "${SLX_ADDONS}" ] && { echo "No addons configured. Nothing to do :-)."; exit 0; } # source functions.inc for the download function -. /opt/openslx/etc/functions.inc || { echo "functions.inc not found!"; exit 1337; } +. /opt/openslx/inc/functions || { echo "/opt/openslx/inc/functions not found!"; exit 1337; } # quick fix for the missing FUTURE_ROOT needed by /opt/openslx/etc/functions.inc export FUTURE_ROOT="/" -- cgit v1.2.3-55-g7522