diff options
author | Jonathan Bauer | 2018-04-10 12:14:46 +0200 |
---|---|---|
committer | Jonathan Bauer | 2018-04-10 12:14:46 +0200 |
commit | 2f598cf3a032592b81b6e2db1fe947577971a5b8 (patch) | |
tree | 5d59112e58885a708f1c909632abf5b81a0765ec /core/modules/slx-issue | |
parent | Merge branch 'master' of git.openslx.org:openslx-ng/mltk (diff) | |
download | mltk-2f598cf3a032592b81b6e2db1fe947577971a5b8.tar.gz mltk-2f598cf3a032592b81b6e2db1fe947577971a5b8.tar.xz mltk-2f598cf3a032592b81b6e2db1fe947577971a5b8.zip |
[slx-issue] externalize /etc/issue generation
Diffstat (limited to 'core/modules/slx-issue')
6 files changed, 128 insertions, 0 deletions
diff --git a/core/modules/slx-issue/data/etc/systemd/system/sysinit.target.wants/update-etc_issue.service b/core/modules/slx-issue/data/etc/systemd/system/sysinit.target.wants/update-etc_issue.service new file mode 120000 index 00000000..4540789e --- /dev/null +++ b/core/modules/slx-issue/data/etc/systemd/system/sysinit.target.wants/update-etc_issue.service @@ -0,0 +1 @@ +../update-etc_issue.service
\ No newline at end of file diff --git a/core/modules/slx-issue/data/etc/systemd/system/update-etc_issue.service b/core/modules/slx-issue/data/etc/systemd/system/update-etc_issue.service new file mode 100644 index 00000000..bdfab085 --- /dev/null +++ b/core/modules/slx-issue/data/etc/systemd/system/update-etc_issue.service @@ -0,0 +1,10 @@ +[Unit] +Description=Update /etc/issue +After=setup-partitions.service +Before=getty.target shutdown.target +DefaultDependencies=no + +[Service] +Type=oneshot +ExecStart=/opt/openslx/scripts/openslx-create_issue +RemainAfterExit=no diff --git a/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue b/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue new file mode 100755 index 00000000..c70e0356 --- /dev/null +++ b/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue @@ -0,0 +1,87 @@ +#!/bin/bash +# Needs bash for string manipulation +# Copyright (c) 2013, 2014 - bwLehrpool Projekt +# Copyright (c) 2012 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# 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|^#")" +linkspeed=$(cat /sys/class/net/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 +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" + +# 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" +done < "$TMPFILE" > "$OUTFILE" + +rm -f -- "$TMPFILE" + + diff --git a/core/modules/slx-issue/module.build b/core/modules/slx-issue/module.build new file mode 100644 index 00000000..f9ee3f20 --- /dev/null +++ b/core/modules/slx-issue/module.build @@ -0,0 +1,20 @@ +#!/bin/bash +fetch_source() { + : +} + +build() { + : +} + +post_copy() { + # Create issue.template + local DIST=$(lsb_release -sd) + local GITC=$(git rev-parse --short HEAD) + local DATE=$(date "+%Y-%m-%d") + local VERSION=$(echo "bwLehrpool/$DIST $DATE/$GITC" | escape_replace) + mkdir -p "$TARGET_BUILD_DIR/opt/openslx/etc" + sed "s/%version%/$VERSION/g" "$MODULE_DIR/templates/issue.template" > "$TARGET_BUILD_DIR/opt/openslx/etc/issue.template" || perror "Could not create issue template" + +} + diff --git a/core/modules/slx-issue/module.conf b/core/modules/slx-issue/module.conf new file mode 100644 index 00000000..c01ade29 --- /dev/null +++ b/core/modules/slx-issue/module.conf @@ -0,0 +1 @@ +# Nothing diff --git a/core/modules/slx-issue/templates/issue.template b/core/modules/slx-issue/templates/issue.template new file mode 100644 index 00000000..a79797ad --- /dev/null +++ b/core/modules/slx-issue/templates/issue.template @@ -0,0 +1,9 @@ + WELCOME TO %space% \n (\l) + _____ ______ ______ __ __ _______ __ __ __ + / _ | _ | ___| | | | | ____| | | | | | + | | | | |_| | |_ | | | | |___ | | / / + | | | | ___/| _| | | ____ | | | | + | |_| | | | |___| | | | ____| | |___ / / + _____/|__| |______|__| |__| |_______|______|__| |__| - NG + + %version% (c) <OpenSLX.ORG> |