summaryrefslogblamecommitdiffstats
path: root/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue
blob: 8165d310923b99c7f703ee061660957b3dd7aca6 (plain) (tree)
1
2
3
4
5
6
7
8
9
           
                                    
                                                                               
 
                                                 
 

                                                                         
 





                                                                               


                                                                             

                                                          
 


















                                                                                                                                              


                                                                   








                                                                                                  




                                         

                            
                                                                

                                        
                                                                              

                                      
                                                                          

                         
                                                                   



                     







                                                      













                                                         
                             


                              
      
 
#!/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
#############################################################################

# Set greeting and add information about the booted system

declare -rg INFILE=/opt/openslx/etc/issue.template
declare -rg TMPFILE=$(mktemp)
declare -rg OUTFILE=/etc/issue

. /opt/openslx/config

# Replace known variables and determine maximum line length
MAX=0
while IFS='' read -r line || [ -n "$line" ]; do
	line="${line//"%ip%"/"$SLX_PXE_CLIENT_IP"}"
	line="${line//"%hostname%"/"$SLX_HOSTNAME"}"
	tst="${line//"%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="$(dmidecode -s system-manufacturer | grep -vP "unknown|filled|^#") $(dmidecode -s system-product-name | grep -vP "unknown|filled|^#")"
# 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)
tmpstatus=$(grep -m1 ' /tmp ' /proc/mounts | awk '{print $3}')
if [ -z "$tmpstatus" ] || [ "$tmpstatus" = "tmpfs" ]; then
	tmpstatus="RAMDISK"
else
	tmpstatus="HDD"
fi
tmpstatus="$(df -P | grep -m1 ' /tmp$' | awk '{printf "%.1f", $2 / 1024 / 1024}')GiB ($tmpstatus)"

cat >> "$TMPFILE" <<EOF
System model:%space% $system
Kernel version:%space% $kernel
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

echo "" >> "$TMPFILE"

# Crop to console width
T=$( tput cols 2> /dev/console )
if [ -z "$T" ]; then
	T=$( stty size < /dev/console )
	T="${T#* }"
fi
[ -n "$T" ] && [ "$T" -le "$MAX" ] && MAX=$(( T - 1 ))

# Fix up spacing for right-aligned text
while IFS='' read -r line || [ -n "$line" ]; do
	tst=${line/"%space%"/}
	if [ "$(( ${#line} - ${#tst} ))" -eq 7 ]; then
		space=
		while true; do
			tst=${line/"%space%"/"$space"}
			if [ "${#tst}" -ge "$MAX" ]; then
				line="$tst"
				break
			fi
			space=" $space"
		done
	fi
	echo "${line:0:$MAX}"
done < "$TMPFILE" > "$OUTFILE"

rm -f -- "$TMPFILE"
exit 0