From 9d485e473e368ef50fe98cfdb11bee6095a53a40 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 15 Aug 2013 16:20:44 +0200 Subject: [stage31] move configuration of stage32 into /bin/activate_sysconfig. --- .../debug/data/opt/openslx/bin/debug-report | 98 -------------------- .../rootfs-stage31/data/bin/activate-sysconfig | 67 -------------- .../rootfs-stage31/data/bin/activate_sysconfig | 103 +++++++++++++++++++++ .../rootfs/rootfs-stage31/data/bin/setup-network | 69 -------------- .../rootfs/rootfs-stage31/data/bin/setup_network | 69 ++++++++++++++ remote/rootfs/rootfs-stage31/data/init | 40 +++----- remote/targets/vmware/vmplayer | 1 + 7 files changed, 186 insertions(+), 261 deletions(-) delete mode 100755 remote/modules/debug/data/opt/openslx/bin/debug-report delete mode 100755 remote/rootfs/rootfs-stage31/data/bin/activate-sysconfig create mode 100755 remote/rootfs/rootfs-stage31/data/bin/activate_sysconfig delete mode 100755 remote/rootfs/rootfs-stage31/data/bin/setup-network create mode 100755 remote/rootfs/rootfs-stage31/data/bin/setup_network create mode 120000 remote/targets/vmware/vmplayer (limited to 'remote') diff --git a/remote/modules/debug/data/opt/openslx/bin/debug-report b/remote/modules/debug/data/opt/openslx/bin/debug-report deleted file mode 100755 index 2c3aabe4..00000000 --- a/remote/modules/debug/data/opt/openslx/bin/debug-report +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash - -TOOLS=" - journalctl - systemctl - loginctl - lspci - lsusb - lsmod - mount -" - -URL="http://132.230.8.113/error_report.php" - -if [ "$UID" != "0" ]; then - echo "Debug Reports können nur von root versendet werden" >&2 - exit 1 -fi - -if ! curl -H "Expect:" -f -s -S --connect-timeout 5 "$URL" > /dev/null; then - echo "Kann den Debug-Report-Server in Freiburg nicht erreichen. :-(" >&2 - exit 1 -fi - -rm -rf /tmp/debug-report -mkdir -p /tmp/debug-report/{static,generated} - -if [ ! -d /tmp/debug-report ]; then - echo "FEHLER: Konnte /tmp/debug-report nicht erstellen!" >&2 - exit 1 -fi - -cd /tmp/debug-report - -cat > err-desc < metadata -hwclock >> metadata -date >> metadata -for srv in 132.230.1.9 $SLX_NTP_SERVER 0.de.pool.ntp.org; do - ntpdate -u -q -p 2 -t 1 "$srv" >> metadata && break -done -echo -n "..." - -cp /opt/openslx/config /tmp/udhcpclog static/ 2> /dev/null -echo -n "." - -find /tmp/vmware* -name "*.log" -exec cp {} static/ \; 2> /dev/null -echo -n "." - -cp /var/log/Xorg.0.lo* static/ 2> /dev/null -cp /var/log/{auth.log,kdm.log,syslog,messages,user.log} static/ 2> /dev/null -cp /proc/cpuinfo static/ 2> /dev/null -echo -n "." - -for tool in $TOOLS; do - $tool > "generated/${tool}-out" 2> "generated/${tool}-err" - echo -n "." -done - -ip a > "generated/ip-a-out" 2> "generated/ip-a-err" -echo -n "." - -systemctl status > "generated/systemctl-status-out" 2> "generated/systemctl-status-err" -echo -n "." - -ps aux > "generated/ps-out" 2> "generated/ps-err" -echo -n "." - -echo "..fertig!" - -cd /tmp -rm -f error-report.tar.gz -echo -n "Packe Fehlerbericht ein..." -if ! tar czf error-report.tar.gz debug-report; then - echo "Fehler beim Packen des Berichts!" >&2 - exit 1 -fi -echo "....fertig!" - -echo -n "Lade Fehlerbericht hoch...." -if ! curl -H "Expect:" -f -s -S -F "file=@error-report.tar.gz;filename=report" "$URL" > /dev/null; then - echo "Fehler beim Hochladen des Fehlerberichts :-(" >&2 - exit 1 -fi - -echo "Fehlerbericht erfolgreich versendet!" - 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" </dev/null -ip addr add 127.0.0.1/8 dev lo 2>/dev/null - -echo "Setting up bridge" -BRIDGE="br0" - -# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though -## Flip mac address of original interface - this var is not local so init sees the changes too -#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" -#ip link set addr "$MAC" "$SLAVE" - -mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" - -#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') -IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') - -for LINE in $IP_OUT; do - IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') - IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[a-z]' '[A-Z]') - echo "${IFACE} = ${IFMAC}" - - if [ "x$IFMAC" == "x$MAC" ]; then - brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" - brctl stp "$BRIDGE" 0 - brctl setfd "$BRIDGE" 0.000000000001 - ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" - ip link set dev "$IFACE" up - brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" - - # analyze ip information from the kernel command line and put parts - # of it into several variables - if [ -n "$IPINFO" ] ; then - getip () { - local val="$IPINFO:"; i=$(($1 - 1)); - while [ $i -gt 0 ] ; do - val=${val#*:} ; i=$(($i - 1)); - done; - echo $val|sed "s/:.*//"; - } - CLIENTIP="$(getip 1)" - SERVERIP="$(getip 2)" - GATEWAY="$(getip 3)" - SUBNET_MASK="$(getip 4)" - BROADCAST_ADDRESS="$(ipcalc -s -b "$CLIENTIP" "$SUBNET_MASK" | sed s/.*=//)" - [ -z "$BROADCAST_ADDRESS" ] && BROADCAST_ADDRESS="255.255.255.255" - # we might have an idea of the dns server via preboot - DNS_SERVER="$(getip 5)" - # set static ip address - ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" - ip link set dev "$BRIDGE" up - ip route add default via "$GATEWAY" dev "$BRIDGE" - else - NOIPYET="yes" - fi - fi - # youdev - echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" - # continue... - IFACE="" -done - diff --git a/remote/rootfs/rootfs-stage31/data/bin/setup_network b/remote/rootfs/rootfs-stage31/data/bin/setup_network new file mode 100755 index 00000000..93ecd75f --- /dev/null +++ b/remote/rootfs/rootfs-stage31/data/bin/setup_network @@ -0,0 +1,69 @@ +#!/bin/sh + +echo "Main MAC address is '$MAC'" + +# setup network + +# set up loopback networking +echo "Setting up loopback" +ip link set dev lo up 2>/dev/null +ip addr add 127.0.0.1/8 dev lo 2>/dev/null + +echo "Setting up bridge" +BRIDGE="br0" + +# Following was supposed to prevent scripts from getting confused by multiple interfaces with same MAC - does not work though +## Flip mac address of original interface - this var is not local so init sees the changes too +#MAC="$(echo "$MAC" | awk -F ':' '{printf $1 ":" $2 ":" $5 ":" $3 ":" $6 ":" $4}')" +#ip link set addr "$MAC" "$SLAVE" + +mkdir -p "${FUTURE_ROOT}/etc/udev/rules.d" + +#IP_OUT=$(ip a | sed -r ':a;N;$!ba;s/: ([a-z0-9]+): /####\1####/g;s/ether ([a-f0-9:]+) /####\1####/g'| grep -E -o '####[^ ]+####' | sed 's/#//g' | grep -B 1 ':') +IP_OUT=$(ip a | grep -B 1 "/ether" | sed -r '/^--$/d;$!N;s#^[0-9]+: ([a-z0-9\.:]+): .*?/ether ([0-9a-fA-Z:]+) .*$#\1==\2#') + +for LINE in $IP_OUT; do + IFACE=$(echo "$LINE" | awk -F '==' '{printf $1}') + IFMAC=$(echo "$LINE" | awk -F '==' '{printf $2}' | tr '[a-z]' '[A-Z]') + echo "${IFACE} = ${IFMAC}" + + if [ "x$IFMAC" == "x$MAC" ]; then + brctl addbr "$BRIDGE" || drop_shell "Could not create bridge $BRIDGE" + brctl stp "$BRIDGE" 0 + brctl setfd "$BRIDGE" 0.000000000001 + ip link set addr "$IFMAC" "$BRIDGE" || drop_shell "Could not set mac of $BRIDGE" + ip link set dev "$IFACE" up + brctl addif "$BRIDGE" "$IFACE" || drop_shell "Could not add $IFACE to $BRIDGE" + + # analyze ip information from the kernel command line and put parts + # of it into several variables + if [ -n "$IPINFO" ] ; then + getip () { + local val="$IPINFO:"; i=$(($1 - 1)); + while [ $i -gt 0 ] ; do + val=${val#*:} ; i=$(($i - 1)); + done; + echo $val|sed "s/:.*//"; + } + CLIENTIP="$(getip 1)" + SERVERIP="$(getip 2)" + GATEWAY="$(getip 3)" + SUBNET_MASK="$(getip 4)" + BROADCAST_ADDRESS="$(ipcalc -s -b "$CLIENTIP" "$SUBNET_MASK" | sed s/.*=//)" + [ -z "$BROADCAST_ADDRESS" ] && BROADCAST_ADDRESS="255.255.255.255" + # we might have an idea of the dns server via preboot + DNS_SERVER="$(getip 5)" + # set static ip address + ip addr add "$CLIENTIP/$(ipcalc -s -p "$CLIENTIP" "$SUBNET_MASK" | sed "s/.*=//")" broadcast "$BROADCAST_ADDRESS" dev "$BRIDGE" + ip link set dev "$BRIDGE" up + ip route add default via "$GATEWAY" dev "$BRIDGE" + else + NOIPYET="yes" + fi + fi + # youdev + echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$IFMAC\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$IFACE\"" >> "${FUTURE_ROOT}/etc/udev/rules.d/70-net-boot-nic-name.rules" + # continue... + IFACE="" +done + 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 <