summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2013-08-20 18:22:07 +0200
committerSimon Rettberg2013-08-20 18:22:07 +0200
commitca81cd9be7eee8b94cc9280c71fdaca1e6fffdbd (patch)
tree9c66deb577342d8a0918821dbdcaab5e38c46b3e
parent[setup_target] Make sure /var/run is just a symlink to /run (diff)
parent[rootfs-stage31] activate plymouth with 'splash' in the kcl. (Removed the DEB... (diff)
downloadtm-scripts-ca81cd9be7eee8b94cc9280c71fdaca1e6fffdbd.tar.gz
tm-scripts-ca81cd9be7eee8b94cc9280c71fdaca1e6fffdbd.tar.xz
tm-scripts-ca81cd9be7eee8b94cc9280c71fdaca1e6fffdbd.zip
Merge branch 'master' of simonslx:openslx-ng/tm-scripts
-rw-r--r--data/basic.nocopy1
-rw-r--r--remote/modules/busybox/openslx-busybox-config2
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/activate_sysconfig69
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/setup_network2
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/bin/setup_stage3247
-rw-r--r--remote/rootfs/rootfs-stage31/data/etc/functions90
-rwxr-xr-xremote/rootfs/rootfs-stage31/data/init58
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_slx_addons27
-rwxr-xr-xserver/export_target11
9 files changed, 200 insertions, 107 deletions
diff --git a/data/basic.nocopy b/data/basic.nocopy
index 6ed33d4c..6423384b 100644
--- a/data/basic.nocopy
+++ b/data/basic.nocopy
@@ -21,7 +21,6 @@
/var/cache/nscd
*~
*.bak
-*.git*
*.pid
*.tmp
*tm-scripts*
diff --git a/remote/modules/busybox/openslx-busybox-config b/remote/modules/busybox/openslx-busybox-config
index dcf2759b..115c0003 100644
--- a/remote/modules/busybox/openslx-busybox-config
+++ b/remote/modules/busybox/openslx-busybox-config
@@ -211,7 +211,7 @@ CONFIG_DD=y
# CONFIG_FEATURE_DD_IBS_OBS is not set
CONFIG_DF=y
# CONFIG_FEATURE_DF_FANCY is not set
-# CONFIG_DIRNAME is not set
+CONFIG_DIRNAME=y
# CONFIG_DOS2UNIX is not set
# CONFIG_UNIX2DOS is not set
CONFIG_DU=y
diff --git a/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig
index 0d8d33c4..6192137a 100755
--- a/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig
+++ b/remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig
@@ -1,40 +1,16 @@
#!/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_KCL_SERVERS=$(read_from_cmdline "slxsrv")
+SLX_BASE_PATH=$(read_from_cmdline "slxbase")
#########################################################################
#
@@ -42,9 +18,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_PATH}/config" "${CONFIG}-remote" || return 1
echo "# Config fetched from $URL" >> "$CONFIG"
echo "#_RCONFIG_TAG" >> "$CONFIG"
@@ -55,11 +31,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_PATH}/config.tgz" "${CONFIG}.tgz" || return 1
}
@@ -69,11 +43,10 @@ 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
+ # write IP and SLX_SERVER configuration to $CONFIG
cat >> "$CONFIG" <<HEREEND
# IP Config written in stage31
SLX_PXE_CLIENT_IP='$CLIENTIP'
@@ -84,12 +57,14 @@ SLX_PXE_MAC='$BRIDGEMAC'
HEREEND
# setup hardware clock
- . /mnt/opt/openslx/config
+ . "${CONFIG}"
if [ "x$SLX_BIOS_CLOCK" == "xlocal" ]; then
hwclock -s -l
elif [ "x$SLX_BIOS_CLOCK" == "xutc" ]; then
hwclock -s -u
fi
+
+ tar xf "${CONFIG}.tgz" -C "${FUTURE_ROOT}" || { echo "Could not untar ${CONFIG}.tgz to ${FUTURE_ROOT}"; return 1; }
}
@@ -98,6 +73,6 @@ HEREEND
# MAIN PART
#
-fetch_sysconfig || exit 1
-fetch_config_files || exit 1
-update_sysconfig || exit 1
+fetch_sysconfig
+fetch_config_files
+update_sysconfig
diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup_network b/remote/rootfs/rootfs-stage31/data/bin/setup_network
index 93ecd75f..8e070bdf 100755
--- a/remote/rootfs/rootfs-stage31/data/bin/setup_network
+++ b/remote/rootfs/rootfs-stage31/data/bin/setup_network
@@ -1,5 +1,7 @@
#!/bin/sh
+echo "Setting up network..."
+
echo "Main MAC address is '$MAC'"
# setup network
diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup_stage32 b/remote/rootfs/rootfs-stage31/data/bin/setup_stage32
new file mode 100755
index 00000000..151617bc
--- /dev/null
+++ b/remote/rootfs/rootfs-stage31/data/bin/setup_stage32
@@ -0,0 +1,47 @@
+#!/bin/bash
+#
+# This script sets up the stage 3.2.
+# - downloads/mounts stage32.sqfs
+# - merge it with current rootfs through aufs
+# - will not download, if the "nfs=" is used in the
+# kernel command line
+#
+#########################################################################
+#
+# first check if an NFS-share was given per command line
+#
+if [ -n "$NFS" ]; then
+ 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}." \
+ || return 1
+ return 0
+fi
+
+#########################################################################
+#
+# MAIN PART
+#
+
+echo "Setting up stage 3.2 ..."
+
+# include /etc/functions
+. /etc/functions
+
+# parse kernel command line to determine the URL of the stage3.2
+SLX_BASE_PATH="$(read_from_cmdline "slxbase")"
+STAGE32_TARGET_PATH="/stage32.sqfs"
+STAGE32_MOUNT_POINT="/rorootfs"
+
+# try to download it
+download "${SLX_BASE_PATH}/stage32.sqfs" "$STAGE32_TARGET_PATH" || return 1
+
+# try to mount it at STAGE32_MOUNT_POINT
+echo "Mounting stage 3.2 as SquashFS..."
+mount -t squashfs "$STAGE32_TARGET_PATH" "$STAGE32_MOUNT_POINT" || drop_shell "Problem mounting Squashfs."
+
+echo "Building aufs ..."
+mount -n -t aufs -o "br:${FUTURE_ROOT}:${STAGE32_MOUNT_POINT}=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"
diff --git a/remote/rootfs/rootfs-stage31/data/etc/functions b/remote/rootfs/rootfs-stage31/data/etc/functions
new file mode 100644
index 00000000..37bb7d89
--- /dev/null
+++ b/remote/rootfs/rootfs-stage31/data/etc/functions
@@ -0,0 +1,90 @@
+#########################################################################
+#
+# 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 >/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"
+
+ for TIMEOUT in 1 2 3 4 5; do
+ for SERVER in $SLX_CONFIG_SERVERS $SLX_KCL_SERVERS; do
+ wget -T 5 -q -O "$TARGET_PATH" "http://${SERVER}/${FILE_URL}"
+ RET=$?
+ if [ "x$RET" != "x0" ]; then
+ echo "Error - downloading 'http://$SERVER/$FILE_URL' via wget failed. Exit Code: $RET"
+ echo "Trying again in $(($TIMEOUT * 500)) ms..."
+ [ $TIMEOUT -eq 5 ] && drop_shell "Max timeouts reached. Dropping shell..."
+ usleep $(($TIMEOUT * 500000))
+ else
+ [ "x$DEBUG" != "x" ] && echo "Successfully downloaded 'http://${SERVER}/$FILE_URL'."
+ return 0
+ fi
+ done
+ done
+
+ # check if it actually worked
+ if [ ! -e $TARGET_PATH ]; then
+ echo "Error - $TARGET_PATH does not exists. Downloading '$FILE_URL' from '$SERVER_LIST' failed."
+ return 1
+ fi
+}
diff --git a/remote/rootfs/rootfs-stage31/data/init b/remote/rootfs/rootfs-stage31/data/init
index 8b971081..35e898b5 100755
--- a/remote/rootfs/rootfs-stage31/data/init
+++ b/remote/rootfs/rootfs-stage31/data/init
@@ -12,17 +12,13 @@
# First script for initial ramfs for OpenSLX linux stateless clients
#############################################################################
-# debug shell
-drop_shell() {
- [ $# -gt 0 ] && echo $@
- echo "CTRL + D will continue booting."
- setsid sh -c 'exec sh </dev/tty1 >/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
@@ -76,49 +72,27 @@ done
[ "$DEBUG" -ge 1 ] && echo "0" >/proc/sys/kernel/printk || echo "4 4 1 7" >/proc/sys/kernel/printk
# start plymouth if activated
-if [ "x$SPLASH" == "x1" -a "x$DEBUG" != "x1" ]; then
+if [ "x$SPLASH" == "x1" ]; then
echo "Starting plymouth..."
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/"
+#echo 'blacklist pcspkr' >> /mnt/etc/modprobe.d/blacklist.conf
# one last debug shell if activated
[ $DEBUG -ge 1 ] && drop_shell "Requested Debug Shell: before switch_root."
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 b6f04d55..a3350424 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
@@ -6,27 +6,32 @@
#
#
-# This script requires the addon to setup as its first parameter
-
-[ "x$1" == "x" ] && { echo "$0 requires the addon as parameter. None given." && exit 1; }
-ADDON="$1"
+. /opt/openslx/etc/functions
+export FUTURE_ROOT="/"
# read openslx config
. /opt/openslx/config
-[ -z "${SLX_ADDONS_BASE_URL}" ] && { echo "SLX_ADDONS_BASE_URL is not set in /opt/openslx/config." && exit 1; }
-[ -z "${SLX_ADDONS_LIST}" ] && { echo "SLX_ADDONS_LIST is not set in /opt/openslx/config." && exit 1; }
+[ -z "${SLX_ADDONS}" ] && { echo "SLX_ADDONS is not set in /opt/openslx/config." && exit 1; }
+if [ -z "${SLX_CONFIG_SERVERS}" ]; then
+ echo "SLX_CONFIG_SERVERS is not set in /opt/openslx/config. Will only try the base servers from the cmdline."
+ if [ -z "${SLX_KCL_SERVERS}" ]; then
+ SLX_KCL_SERVERS=$(read_from_cmdline "slxsrv")
+ fi
+fi
+
+# read base slx servers from cmdline
+SLX_BASE_PATH=$(read_from_cmdline "slxbase")
SLX_BASE_MNT="/opt/openslx/mnt"
SYS_TMP="/tmp"
-for ADDON in ${SLX_ADDONS_LIST}; do
+for ADDON in ${SLX_ADDONS}; do
# download the addon from the given URL
- local ADDON_TARGET_PATH="${SYS_TMP}/$(basename $(echo ${ADDON})).sqfs"
- echo "Downloading $SLX_ADDONS_BASE_URL/${ADDON}.sqfs to ${ADDON_TARGET_PATH}"
- wget -T 5 -q -O "${ADDON_TARGET_PATH}" "${SLX_ADDONS_BASE_URL}/${ADDON}.sqfs"|| { echo "Failed to download." && exit 1; }
+ ADDON_TARGET_PATH="${SYS_TMP}/$(basename $(echo ${ADDON})).sqfs"
+ download "${SLX_BASE_PATH}/${ADDON}.sqfs" "${ADDON_TARGET_PATH}"
# now mount it to $SLX_MNT/<addon-name>
- local ADDON_MOUNT_POINT="${SLX_BASE_MNT}/$(basename $(echo ${ADDON})|awk -F "." '{print $1}')"
+ ADDON_MOUNT_POINT="${SLX_BASE_MNT}/$(basename $(echo ${ADDON})|awk -F "." '{print $1}')"
mkdir -p "$ADDON_MOUNT_POINT"
echo "Mounting ${ADDON_TARGET_PATH} to ${ADDON_MOUNT_POINT}"
mount -t squashfs "$ADDON_TARGET_PATH" ${ADDON_MOUNT_POINT} || { echo "Failed to mount." && exit 1; }
diff --git a/server/export_target b/server/export_target
index 575ce565..7ab7a11d 100755
--- a/server/export_target
+++ b/server/export_target
@@ -60,12 +60,13 @@ generate_stage32() {
local TOOL_STR="${TOOL_STR} generate_stage32:"
[ ! -d "${STAGE32_SQFS_DIR}" ] && mkdir -p "${STAGE32_SQFS_DIR}"
[ -e "${STAGE32_SQFS_DIR}/${TARGET}.sqfs" ] && rm "${STAGE32_SQFS_DIR}/${TARGET}.sqfs"
- pinfo "Writing '${TARGET}.sqfs' to '${STAGE32_SQFS_DIR}/${TARGET}.sqfs'"
- mksquashfs "${SERVER_BUILD_DIR}/${TARGET}" "${STAGE32_SQFS_DIR}/${TARGET}.sqfs" -comp xz -b 1M -no-recovery >&6 || perror "mksquashfs failed ($?)."
- pinfo "Wrapping squashFS in initramfs-stage32"
- generate_initramfs "${SERVER_BOOT_DIR}/stage32_sqfs" "./mnt/${TARGET}.sqfs" "${SERVER_BOOT_DIR}/initramfs-${TARGET}"
+ pinfo "Writing '${TARGET}.sqfs' to '${SERVER_BOOT_DIR}/${TARGET}.sqfs'"
+ mksquashfs "${SERVER_BUILD_DIR}/${TARGET}" "${SERVER_BOOT_DIR}/${TARGET}.sqfs" -comp xz -b 1M -no-recovery >&6 || perror "mksquashfs failed ($?)."
+ pinfo "Created '${SERVER_BOOT_DIR}/${TARGET}.sqfs'."
+ #pinfo "Wrapping squashFS in initramfs-stage32"
+ #generate_initramfs "${SERVER_BOOT_DIR}/stage32_sqfs" "./mnt/${TARGET}.sqfs" "${SERVER_BOOT_DIR}/initramfs-${TARGET}"
# cleanup
- [ -d "${SERVER_BOOT_DIR}/stage32_sqfs" ] && rm -rf ${SERVER_BOOT_DIR}/stage32_sqfs
+ #[ -d "${SERVER_BOOT_DIR}/stage32_sqfs" ] && rm -rf ${SERVER_BOOT_DIR}/stage32_sqfs
}
generate_stage31() {