blob: f0c87d69ba8f7b38ea17e58d6059370ae1fafa25 (
plain) (
tree)
|
|
#!/bin/bash
# Needs bash for string manipulation
# -----------------------------------------------------------------------------
#
# Copyright (c) 2012..2018 bwLehrpool-Projektteam
#
# This program/file is free software distributed under the GPL version 2.
# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
#
# If you have any feedback please consult https://bwlehrpool.de and
# send your feedback to bwlehrpool@hs-offenburg.de.
#
# General information about bwLehrpool can be found at https://bwlehrpool.de
#
# -----------------------------------------------------------------------------
#
# First script for initial ramfs for OpenSLX linux stateless clients
#############################################################################
export PATH="$PATH:/opt/openslx/bin:/opt/openslx/sbin"
# Set greeting and add information about the booted system
mkdir -p /run/openslx
declare -rg INFILE=/opt/openslx/etc/issue.template
declare -rg TMPFILE=$(mktemp -p /run/openslx)
declare -rg OUTFILE=/etc/issue
. /opt/openslx/config
# get_dmi_info <class>
get_dmi_info() {
[ -n "$1" ] || return
echo $(dmidecode -s $1 | grep -vP "unknown|filled|^#")
}
# Replace known variables and determine maximum line length
MAX=0
while IFS='' read -r line || [ -n "$line" ]; do
line="${line//"%hostname%"/"$SLX_HOSTNAME"}"
tst="${line//"%minspace%"/}"
tst="${tst//"%space%"/}"
len=${#tst}
[ "$len" -gt "$MAX" ] && MAX=$len
echo "$line"
done < "$INFILE" > "$TMPFILE"
player=$(< /etc/vmware/config grep -m1 '^product.version' | awk -F= '{print $2}')
kernel=$(uname -r)
system_manufacturer="$(get_dmi_info system-manufacturer)"
[ -z "$system_manufacturer" ] && system_manufacturer="$(get_dmi_info baseboard-manufacturer)"
system_product="$(get_dmi_info system-product-name)"
[ -z "$system_product" ] && system_product="$(get_dmi_info baseboard-product-name)"
system="$system_manufacturer $system_product"
[ -z "${system// /}" ] && system="<unknown>"
# Support the boot interface name eventually saved as SLX_PXE_NETIF
# from the new dracut-based stage3, fallback to old eth0 if not set
linkspeed=$(cat /sys/class/net/${SLX_PXE_NETIF:-eth0}/speed)
# Detect if the system is backed by a disk
if slx-tools fs_path_isvolatile /tmp; then
tmpstatus="RAMDISK"
else
tmpstatus="HDD"
fi
tmpstatus="$(slx-tools fs_path_space /tmp | awk '{printf "%.1f", $2 / 1024 / 1024}')GiB ($tmpstatus)"
# netboot version from cmdline, e.g. boot/bwlp/minilinux/1 to "MiniLinux 1"
netboot="$(grep -oP '(?<=slxbase=boot/bwlp/)\S+' /proc/cmdline | tr '/' ' ')"
# capitalize 'm' & 'l'
netboot="${netboot^m}"
netboot="${netboot^^l}"
virtualbox="$( . /usr/lib/virtualbox/scripts/generated.sh; echo $VBOX_VERSION_STRING )"
cat >> "$TMPFILE" <<EOF
System model:%space% $system
Kernel version:%space% $kernel
Netboot version:%space% $netboot
Temporary directory:%space% $tmpstatus
Boot server:%space% $SLX_PXE_SERVER_IP
Client address:%space% $SLX_PXE_CLIENT_IP
EOF
if [ -n "$linkspeed" ]; then
echo "Link speed:%space% ${linkspeed}MBit" >> "$TMPFILE"
fi
if [ -n "$SLX_SHUTDOWN_SCHEDULE" ]; then
echo "Scheduled shutdown:%space% $SLX_SHUTDOWN_SCHEDULE" >> "$TMPFILE"
fi
if [ -n "$SLX_REBOOT_SCHEDULE" ]; then
echo "Scheduled reboot:%space% $SLX_REBOOT_SCHEDULE" >> "$TMPFILE"
fi
if [ -n "$player" ]; then
echo "VMware version:%space% ${player//'"'/}" >> "$TMPFILE"
fi
if [ -n "$virtualbox" ]; then
echo "VirtualBox version:%space% $virtualbox" >> "$TMPFILE"
fi
echo "" >> "$TMPFILE"
# Crop to console width
[ "$MAX" -lt 80 ] && MAX=80
export TERM=linux
T="$( tput cols 2> /dev/console < /dev/console )"
[ -z "$T" ] && T="$( tput cols 2> /dev/tty1 < /dev/tty1 )"
if [ -z "$T" ]; then
T="$( stty size 2> /dev/console < /dev/console )"
[ -z "$T" ] && T="$( stty size 2> /dev/tty1 < /dev/tty1 )"
T="${T#* }"
fi
[ -n "$T" ] && [ "$T" -le "$MAX" ] && MAX=$(( T - 1 ))
unset TERM
# Fix up spacing for right-aligned text
while IFS='' read -r line || [ -n "$line" ]; do
tst=${line/"%space%"/}
tst=${tst/"%minspace%"/}
if [ "${#line}" != "${#tst}" ]; then
space=
while true; do
tst=${line/"%space%"/"$space"}
tst2=${tst/"%minspace%"/"$space"}
if [ "${#tst2}" -ge "$MAX" ]; then
line="${tst/"%minspace%"/"${space:0:-2}"}"
break
elif [ "${#space}" -gt 0 ] && [ "$(( MAX - ${#tst2} ))" -ge "${#space}" ]; then
space="$space$space"
else
space=" $space"
fi
done
fi
echo "${line:0:$MAX}"
done < "$TMPFILE" > "$OUTFILE"
rm -f -- "$TMPFILE"
exit 0
|