diff options
author | Simon Rettberg | 2017-07-12 14:12:48 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-07-12 14:12:48 +0200 |
commit | c70af5479c890b109ffa12617def457e49f7baf1 (patch) | |
tree | e655d3fc498646a674dd437768ec074aab8d0746 | |
parent | [rfs-stage31] init: Create /tmp early, unmount before switchroot (diff) | |
download | mltk-c70af5479c890b109ffa12617def457e49f7baf1.tar.gz mltk-c70af5479c890b109ffa12617def457e49f7baf1.tar.xz mltk-c70af5479c890b109ffa12617def457e49f7baf1.zip |
[init, etc] Pass system-uuid when fetching config & config.tgz
Also save the system-uuid for later use in stage32+, which changed
locations from /run to /etc - modules got updated accordingly
14 files changed, 117 insertions, 36 deletions
diff --git a/core/modules/hardware-stats/data/etc/X11/Xsetup.d/99-detect-screens b/core/modules/hardware-stats/data/etc/X11/Xsetup.d/99-detect-screens index 879cfe96..74f77621 100644 --- a/core/modules/hardware-stats/data/etc/X11/Xsetup.d/99-detect-screens +++ b/core/modules/hardware-stats/data/etc/X11/Xsetup.d/99-detect-screens @@ -11,7 +11,7 @@ bash <<"HEREDOC" . /opt/openslx/config [ -z "$SLX_REMOTE_LOG" ] && exit 0 - UUID=$( cat /run/system-uuid ) + UUID=$( cat /etc/system-uuid ) [ -z "$UUID" ] && exit 0 XRANDR=$( mktemp ) TMP=$( mktemp ) diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update b/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update index df8dab45..8a8bc642 100755 --- a/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update +++ b/core/modules/hardware-stats/data/opt/openslx/scripts/cron-system_usage_update @@ -1,11 +1,11 @@ #!/bin/ash -[ -r "/run/system-uuid" ] || exit 0 +[ -r "/etc/system-uuid" ] || exit 0 . /opt/openslx/config [ -z "$SLX_REMOTE_LOG" ] && exit 0 -UUID=$(cat "/run/system-uuid") +UUID=$(cat "/etc/system-uuid") [ -z "$UUID" ] && exit 1 diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/shutdown-system_usage_update b/core/modules/hardware-stats/data/opt/openslx/scripts/shutdown-system_usage_update index dc9f8f73..ce474fa2 100755 --- a/core/modules/hardware-stats/data/opt/openslx/scripts/shutdown-system_usage_update +++ b/core/modules/hardware-stats/data/opt/openslx/scripts/shutdown-system_usage_update @@ -3,7 +3,7 @@ . /opt/openslx/config [ -z "$SLX_REMOTE_LOG" ] && exit 0 -UUID=$(cat /run/system-uuid) +UUID=$(cat /etc/system-uuid) [ -z "$UUID" ] && exit 1 diff --git a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats index 618326aa..9e959ecb 100755 --- a/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats +++ b/core/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats @@ -78,30 +78,13 @@ fi MAC=${BOOTIF:3} # 2) Get machine UUID, with fallback to MAC address if it fails for some reason, or if the UUID is blacklisted -UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr '[a-z]' '[A-Z]') +UUID=$(cat /etc/system-uuid) +if [ -z "$UUID" ] || [ "${#UUID}" -ne "36" ]; then + UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr '[a-z]' '[A-Z]') +fi if [ "${#UUID}" -ne "36" ]; then echo "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..." UUID="000000000000000-$BOOTIF" -else - # Got UUID, check blacklist - DIR="/opt/openslx/hardware-stats/bad-uuid.d" - TMPLIST=$(mktemp) - BADLIST="/run/bad-uuids" - for file in "$DIR"/*; do - [ -f "$file" ] || continue - # 11111111-2222-3333-4444-555555555555 - < "$file" tr '[a-z]' '[A-Z]' | grep -Po '[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{12}' - done | tee "$TMPLIST" > "$BADLIST" - # Also add flipped version of bad uuids. Found some of them through googling and discovered that sometimes - # users report them in a different order. UUIDs use different endianness for the first three blocks than - # the remaining two, but some tools seem to ignore that fact. - < "$BADLIST" sed -r 's/^(..)(..)(..)(..)\-(..)(..)\-(..)(..)\-([0-9A-F]{4}\-[0-9A-F]{12})$/\4\3\2\1-\6\5-\8\7-\9/' >> "$TMPLIST" - # Finally make unique - sort -u "$TMPLIST" > "$BADLIST" - if grep -Fxq "$UUID" "$BADLIST"; then - echo "WARNING: UUID is blacklisted as potentially not being unique, using MAC fallback" - UUID="000000000000000-$BOOTIF" - fi fi # 3) Uptime in seconds @@ -299,7 +282,6 @@ for DELAY in 1 1 0; do --data-urlencode "badsectors=$BADSECTORS" --data-urlencode "systemmodel=$MODEL" \ --data-urlencode "data@$DATAFILE" "$SLX_REMOTE_LOG" | grep -q "RESULT=0"; then rm -f -- "$DATAFILE" - echo "$UUID" > "/run/system-uuid" START=$(( $RANDOM % 5 )) cat > "/etc/cron.d/usage_stats" <<-EOF # Update usage statistics on server diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc index 9db578c1..668dfa86 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc @@ -85,10 +85,39 @@ setup_fallback() { readonly VM_DISKFILE_RO } +setup_jambo() { + declare -r CMDLOG="$TMPDIR/sshfs.jambo" + declare -rg CLIENTPARTITION_ADMIN="/var/lib/vmware_admin" + #declare -r UPLOAD_KEYFILE="/var/lib/uploaduser" + #sudo -n sshfs "uploaduser@$JAMBOSERVER:/vms/bwlehrpool_store" "$CLIENTPARTITION_ADMIN" -o allow_other -o PreferredAuthentications=publickey -o IdentityFile="$UPLOAD_KEYFILE" -o IdentitiesOnly=yes &> "$CMDLOG" + sudo -n sshfs "uploaduser@$JAMBOSERVER:/vms/bwlehrpool_store" "$CLIENTPARTITION_ADMIN" -o allow_other -o PreferredAuthentications=publickey &> "$CMDLOG" + RET=$? + if [ "$RET" != "0" ]; then + writelog "SSHFS Failed + $(cat "$CMDLOG")" + EXIT_TYPE="user" EXIT_REASON="Schreibbarer VM-Speicher konnte nicht eingebunden werden. Adminmodus fehlgeschlagen." cleanexit 1 + fi + declare -rg VM_DISKFILE_RW="$CLIENTPARTITION_ADMIN/$SRC_IMG_RELATIVE" +} + ## MAIN PART / Sanity checks ## setup_image_access() { writelog "Setting up virtual hard disk access for virtualizer/emulator ..." + + if [ "$VMCHOOSER_ADMIN_MODE" = "TRUE" ] && [ -n "$SLX_JAMBOSERVER" ]; then + setup_jambo + writelog "\tVM disk file RW:\t\t$VM_DISKFILE_RW" + if ! [ -s "$VM_DISKFILE_RW" ]; then + writelog ".... not found!" + EXIT_TYPE="user" EXIT_REASON="Schreibbare VM nicht gefunden. Adminmodus fehlgeschlagen." cleanexit 1 + fi + if ! [ -w "$VM_DISKFILE_RW" ]; then + writelog ".... not writable!" + EXIT_TYPE="user" EXIT_REASON="VM-Image auf schreibbarem VM-Speicher nicht schreibbar. Adminmodus fehlgeschlagen." cleanexit 1 + fi + return 0 + fi unset VM_DISKFILE_RO declare -g VM_DISKFILE_RO diff --git a/core/modules/system-uuid/data/bin/get-uuid b/core/modules/system-uuid/data/bin/get-uuid new file mode 100755 index 00000000..30ef3cf9 --- /dev/null +++ b/core/modules/system-uuid/data/bin/get-uuid @@ -0,0 +1,40 @@ +#!/bin/ash + +eval $(grep -Eo BOOTIF=\\S+ /proc/cmdline) +if [ "${#BOOTIF}" -ne "20" ]; then + echo "Getting MAC from /proc/cmdline failed, using 'ip a'..." + BOOTIF=01-$(ip a | grep -A 1 ': br0' | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) + if [ "${#BOOTIF}" -ne "20" ]; then + echo "FAIL FAIL FAIL" + BOOTIF="99-88-77-66-55-44-33" + fi +fi + +UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr '[a-z]' '[A-Z]') +if [ "${#UUID}" -ne "36" ]; then + echo "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..." + UUID="000000000000000-$BOOTIF" +else + # Got UUID, check blacklist + DIR="/opt/openslx/bad-uuid.d" + TMPLIST=$(mktemp) + BADLIST=$(mktemp) + for file in "$DIR"/*; do + [ -f "$file" ] || continue + # 11111111-2222-3333-4444-555555555555 + < "$file" tr '[a-z]' '[A-Z]' | grep -Eo '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' + done | tee "$TMPLIST" > "$BADLIST" + # Also add flipped version of bad uuids. Found some of them through googling and discovered that sometimes + # users report them in a different order. UUIDs use different endianness for the first three blocks than + # the remaining two, but some tools seem to ignore that fact. + < "$BADLIST" sed -r 's/^(..)(..)(..)(..)\-(..)(..)\-(..)(..)\-([0-9A-F]{4}\-[0-9A-F]{12})$/\4\3\2\1-\6\5-\8\7-\9/' >> "$TMPLIST" + # Finally make unique + sort -u "$TMPLIST" > "$BADLIST" + if grep -Fxq "$UUID" "$BADLIST"; then + echo "WARNING: UUID is blacklisted as potentially not being unique, using MAC fallback" + UUID="000000000000000-$BOOTIF" + fi + rm -f -- "$TMPLIST" "$BADLIST" +fi + +echo "$UUID" > "/run/system-uuid" diff --git a/core/modules/hardware-stats/data/opt/openslx/hardware-stats/bad-uuid.d/00-default b/core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default index aaf59a7d..aaf59a7d 100644 --- a/core/modules/hardware-stats/data/opt/openslx/hardware-stats/bad-uuid.d/00-default +++ b/core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default diff --git a/core/modules/system-uuid/module.build b/core/modules/system-uuid/module.build new file mode 100644 index 00000000..3c6eb632 --- /dev/null +++ b/core/modules/system-uuid/module.build @@ -0,0 +1,13 @@ +#!/bin/bash +fetch_source() { + : +} + +build() { + : +} + +post_copy() { + : +} + diff --git a/core/modules/system-uuid/module.conf b/core/modules/system-uuid/module.conf new file mode 100644 index 00000000..805ff2c4 --- /dev/null +++ b/core/modules/system-uuid/module.conf @@ -0,0 +1,4 @@ +#!/bin/bash +REQUIRED_MODULES=" + dmidecode +" diff --git a/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig b/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig index ec98ff70..f9363758 100644 --- a/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig +++ b/core/rootfs/rootfs-stage31/data/inc/activate_sysconfig @@ -9,11 +9,11 @@ CONFIG="${FUTURE_ROOT}/opt/openslx/config" # # This function downloads the config containing environment variables # -fetch_sysconfig() { +fetch_text_config() { [ -e "$CONFIG" ] && grep -E '^#_RCONFIG_TAG$' "$CONFIG" > /dev/null \ && echo "Config already fetched." && return 0 - download "${SLX_BASE_PATH}/config" "${CONFIG}-remote" || return 1 + download "${SLX_BASE_PATH}/config$UUID_URL" "${CONFIG}-remote" || return 1 echo "# Config fetched from $URL" >> "$CONFIG" echo "#_RCONFIG_TAG" >> "$CONFIG" @@ -23,10 +23,10 @@ fetch_sysconfig() { # # This function downloads the config.tgz and unpacks it to $TARGET_PATH <-- no it doesn't! # -fetch_config_files() { +fetch_config_tgz() { [ -e "${CONFIG}.tgz" ] && echo "config.tgz already downloaded." && return 0 - download "${SLX_BASE_PATH}/config.tgz" "${CONFIG}.tgz" + download "${SLX_BASE_PATH}/config.tgz$UUID_URL" "${CONFIG}.tgz" } @@ -34,7 +34,7 @@ fetch_config_files() { # # This function updates the downloaded config with the IP information # received from /inc/setup_network <-- plus 500 other things -update_sysconfig() { +merge_text_config() { # sanity checks [ ! -e "${CONFIG}" ] && { echo "Cannot update. '$CONFIG' does not exist."; return 1; } @@ -95,7 +95,17 @@ HEREEND # MAIN PART # -fetch_sysconfig || drop_shell "Could not download remote config" +# Determine machine uuid, save for later +get-uuid +if [ -e "/run/system-uuid" ]; then + UUID=$(cat "/run/system-uuid") + if [ -n "$UUID" ]; then + UUID_URL="?uuid=$UUID" + fi + cp "/run/system-uuid" "${FUTURE_ROOT}/etc/system-uuid" +fi + +fetch_text_config || drop_shell "Could not download remote config" if ! ash -n "${CONFIG}-remote"; then echo -e "\n\tFATAL: Could not download configuration!" echo -e "\tAborting boot since the system would be in an unusable state." @@ -108,7 +118,7 @@ if ! ash -n "${CONFIG}-remote"; then echo b > /proc/sysrq-trigger fi . "${CONFIG}-remote" || drop_shell "Could not source remote config" -fetch_config_files || drop_shell "Could not download config.tgz" -update_sysconfig || drop_shell "Could not update sysconfig" +fetch_config_tgz || drop_shell "Could not download config.tgz" +merge_text_config || drop_shell "Could not update sysconfig" true diff --git a/core/rootfs/rootfs-stage31/module.conf b/core/rootfs/rootfs-stage31/module.conf index 70ef6734..49d49a56 100644 --- a/core/rootfs/rootfs-stage31/module.conf +++ b/core/rootfs/rootfs-stage31/module.conf @@ -5,6 +5,7 @@ REQUIRED_BINARIES=" REQUIRED_MODULES=" busybox kernel + system-uuid " REQUIRED_KERNEL_MODULES=" kernel/drivers/net/ethernet/*.ko diff --git a/core/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog b/core/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog index 09cb9b79..f1ee4816 100755 --- a/core/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog +++ b/core/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog @@ -78,8 +78,8 @@ else fi UUID= -if [ -s /run/system-uuid ]; then - UUID=$(cat /run/system-uuid) +if [ -s /etc/system-uuid ]; then + UUID=$(cat /etc/system-uuid) fi submitlog () { diff --git a/core/targets/stage31/dmidecode b/core/targets/stage31/dmidecode new file mode 120000 index 00000000..608c2bb5 --- /dev/null +++ b/core/targets/stage31/dmidecode @@ -0,0 +1 @@ +../../modules/dmidecode
\ No newline at end of file diff --git a/core/targets/stage31/system-uuid b/core/targets/stage31/system-uuid new file mode 120000 index 00000000..83bcac51 --- /dev/null +++ b/core/targets/stage31/system-uuid @@ -0,0 +1 @@ +../../modules/system-uuid
\ No newline at end of file |