From 5c5e649721b2cf7c0c82dadb4c84dfb72bc0f516 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 31 Mar 2016 16:34:57 +0200 Subject: [kdm-theme-bwlp] Patch theme with warnings about suboptimal hw config --- .../data/etc/systemd/system/hardware-stats.service | 2 +- .../opt/openslx/scripts/systemd-hardware_stats | 28 ++++++++-- .../etc/systemd/system/kdm-hwinfo-warnings.service | 9 ++++ .../kdm-hwinfo-warnings.service | 1 + .../openslx/scripts/systemd-kdm_hwinfo_warnings | 61 ++++++++++++++++++++++ .../share/desktop/themes/kdm/bwlehrpool/theme.xml | 8 +++ 6 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 remote/modules/kdm-theme-bwlp/data/etc/systemd/system/kdm-hwinfo-warnings.service create mode 120000 remote/modules/kdm-theme-bwlp/data/etc/systemd/system/multi-user.target.wants/kdm-hwinfo-warnings.service create mode 100755 remote/modules/kdm-theme-bwlp/data/opt/openslx/scripts/systemd-kdm_hwinfo_warnings diff --git a/remote/modules/hardware-stats/data/etc/systemd/system/hardware-stats.service b/remote/modules/hardware-stats/data/etc/systemd/system/hardware-stats.service index c28e75a5..ca31c695 100644 --- a/remote/modules/hardware-stats/data/etc/systemd/system/hardware-stats.service +++ b/remote/modules/hardware-stats/data/etc/systemd/system/hardware-stats.service @@ -1,7 +1,7 @@ [Unit] Description=Gather statistics about this machine and send to boot server DefaultDependencies=no -After=tmp.target multi-user.target +After=tmp.target Wants=tmp.target [Service] diff --git a/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats b/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats index 0331cada..eee38a7b 100755 --- a/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats +++ b/remote/modules/hardware-stats/data/opt/openslx/scripts/systemd-hardware_stats @@ -8,6 +8,20 @@ export LANG=C export LC_ALL=C +mktemp() { + /bin/mktemp && return 0 + /opt/openslx/bin/mktemp && return 0 + local FN DIR + for DIR in "tmp" "tmp" "tmp" "run/user/$UID" "run"; do + FN="/${DIR}/${RANDOM}-${$}-${UID}-$(date +%N)" + [ -e "$FN" ] && continue + touch "$FN" || continue + chmod 0600 "$FN" || continue + echo "$FN" + return 0 + done +} + if [ -z "$SLX_REMOTE_LOG" ]; then echo "No remote log url given, will not report" exit 1 @@ -25,8 +39,6 @@ if [ "${#BOOTIF}" -ne "20" ]; then fi MAC=${BOOTIF:3} -which dmidecode || sleep 5 - # 2) Get machine UUID, with fallback to MAC address if it fails for some reason UUID=$(dmidecode -s system-uuid) if [ "${#UUID}" -ne "36" ]; then @@ -100,12 +112,14 @@ done ID44=$(( $ID44 / 1058576 )) # we'd rather underreport # 9) check smart values +FDISK=$(mktemp) +fdisk -l > "$FDISK" BADSECTORS=0 if which smartctl; then ALLSMART=$(mktemp) FILE=$(mktemp) [ -z "$FILE" ] && FILE="/tmp/smartctl.$$.$RANDOM.$RANDOM" - for dev in $(fdisk -l | grep -o '^Disk /dev/\S*:' | cut -c 6-); do + for dev in $(cat "$FDISK" | grep -o '^Disk /dev/\S*:' | cut -c 6-); do dev=${dev:0:-1} smartctl -i -H -A -f "brief" "$dev" > "$FILE" || continue echo "NEXTHDD=$dev" >> "$ALLSMART" @@ -151,7 +165,6 @@ fi # n) Dump raw data to a file DATAFILE=$(mktemp) -[ -z "$DATAFILE" ] && DATAFILE="/root/power-stats.$$" cat > "$DATAFILE" <<-EOF ############################### CPU ##################################### Sockets: $(grep '^physical id' /proc/cpuinfo | sort -u | wc -l) @@ -159,7 +172,7 @@ Real cores: $CPUCORES Virtual cores: $(grep '^processor' /proc/cpuinfo | sort -u | wc -l) ######################## Partition tables ############################### EOF -fdisk -l >> "$DATAFILE" +cat "$FDISK" >> "$DATAFILE" cat >> "$DATAFILE" <<-EOF ############################ PCI ID ##################################### EOF @@ -181,10 +194,15 @@ EOF [ -n "$ALLSMART" ] && rm -f -- "$ALLSMART" # Put some info in local file for later use +HDDCOUNT=0 +for size in $(cat "$FDISK" | grep -E '^Disk /dev.*[0-9]{11,} bytes' | grep -o -E '[0-9]{11,}'); do + [ "$size" -gt 50000000000 ] && HDDCOUNT=$(( HDDCOUNT + 1 )) +done cat > "/run/hwinfo" < "$TMP" + local DATA= + build_replacement_xml + awk -v r="$DATA" '{gsub(/REPLACE_MARKER/,r)}1' "$TMP" > "$THEME_FILE" +} + +build_replacement_xml() { + local TEMPLATE=' + + + _TEXT_ +' + . "/run/hwinfo" + local CONTACT_RZ= + # Warning: add_replace_xml doesn't escape <>& (XML), and also doesn't escape , and & (sed), so e.g. < should be written as \< + if [ "$HW_KVM" = "DISABLED" ]; then + add_replace_xml "ff0000" "64Bit-Gast-Support (VT-x oder AMD-V) ist im BIOS deaktiviert. 64Bit VMs können nicht gestartet werden." + CONTACT_RZ=jau + elif [ "$HW_KVM" = "UNSUPPORTED" ]; then + add_replace_xml "000000" "CPU hat keinen 64Bit-Gast-Support (VT-x oder AMD-V). 64Bit VMs können nicht gestartet werden." + fi + if [ -n "$HW_MBRAM" ] && [ "$HW_MBRAM" -lt 3400 ]; then + local GB=$(( ( HW_MBRAM + 300 ) / 1024 )) + add_replace_xml "000000" "Dieser PC hat wenig RAM (${GB}GB). Die Leistung von VM-Sitzungen wird nicht optimal sein." + fi + if [ "$HW_ID44" = "0" ]; then + add_replace_xml "000000" "Keine ID44-Partition gefunden. VMs bekommen wenig RAM zugewiesen." + if [ "$HW_HDDCOUNT" = "0" ]; then + add_replace_xml "000000" " * Keine Festplatte erkannt; eine Festplatte wird empfohlen, wenn Sie VMs nutzen wollen" + elif [ -n "$HW_HDDCOUNT" ]; then + CONTACT_RZ=klar + fi + if [ -n "$HW_MBRAM" ] && [ "$HW_MBRAM" -lt 4500 ]; then + add_replace_xml "ff0000" " * Da der PC wenig RAM hat, ist die Einrichtung einer ID44-Partition dringend zu empfehlen" + fi + elif [ -n "$HW_ID44" ] && [ "$HW_ID44" -lt 10000 ]; then + add_replace_xml "000000" "Die ID44-Partition ist sehr klein. VM-Sitzungen könnten nach einiger Zeit aus Speichermangel abstürzen." + CONTACT_RZ=fjeden + fi + if [ -n "$CONTACT_RZ" ]; then + add_replace_xml "000000" " -- " + add_replace_xml "000000" " -- Wenden Sie sich ggf. an den bwLehrpool-Support Ihres Rechenzentrums -- " + fi +} + +add_replace_xml() { + [ -z "$DATA" ] && DATA=$(echo "$TEMPLATE" | sed "s,_COLOR_,#000000,;s,_TEXT_,Hinweise für den Admin/Hardware-Betreuer:,") + DATA="$DATA $(echo "$TEMPLATE" | sed "s,_COLOR_,#$1,;s,_TEXT_,$2,")" +} + + + +patch_kdm_theme + diff --git a/remote/modules/kdm-theme-bwlp/data/usr/share/desktop/themes/kdm/bwlehrpool/theme.xml b/remote/modules/kdm-theme-bwlp/data/usr/share/desktop/themes/kdm/bwlehrpool/theme.xml index 5de73ea6..6aaac6b3 100644 --- a/remote/modules/kdm-theme-bwlp/data/usr/share/desktop/themes/kdm/bwlehrpool/theme.xml +++ b/remote/modules/kdm-theme-bwlp/data/usr/share/desktop/themes/kdm/bwlehrpool/theme.xml @@ -175,6 +175,14 @@ KDM-OpenSLX-Theme + + + + + + + +