From 529bb1c4b20dc6264a0978b0130657c6f8b61425 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 17 Oct 2016 19:05:56 +0200 Subject: [rfs-stage32] Improve /etc/issue generator --- .../data/opt/openslx/scripts/openslx-create_issue | 44 ++++++++++++++++++---- .../rootfs/rootfs-stage32/templates/issue.template | 6 ++- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue index 4d2de8b7..d3086176 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue @@ -1,4 +1,5 @@ -#!/bin/ash +#!/bin/bash +# Needs bash for string manipulation # Copyright (c) 2013, 2014 - bwLehrpool Projekt # Copyright (c) 2012 - OpenSLX GmbH # @@ -14,11 +15,40 @@ ############################################################################# # Set greeting and add information about the booted system -len=$(expr length "$(cat /etc/hostname)") -while [ $len -le 56 ] ; do - space="$space " - len=$(($len + 1)) -done -sed "s/%space%/$space/g" /opt/openslx/etc/issue.template > /etc/issue +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"}" + len=${#line} + [ "$len" -gt "$MAX" ] && MAX=$len + echo "$line" +done < "$INFILE" > "$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/remote/rootfs/rootfs-stage32/templates/issue.template b/remote/rootfs/rootfs-stage32/templates/issue.template index a79797ad..adf1f38e 100644 --- a/remote/rootfs/rootfs-stage32/templates/issue.template +++ b/remote/rootfs/rootfs-stage32/templates/issue.template @@ -1,4 +1,5 @@ - WELCOME TO %space% \n (\l) +-- \l + WELCOME TO %space% %hostname% [%ip%] _____ ______ ______ __ __ _______ __ __ __ / _ | _ | ___| | | | | ____| | | | | | | | | | |_| | |_ | | | | |___ | | / / @@ -6,4 +7,5 @@ | |_| | | | |___| | | | ____| | |___ / / _____/|__| |______|__| |__| |_______|______|__| |__| - NG - %version% (c) + %version% %space% (c) + -- cgit v1.2.3-55-g7522