summaryrefslogtreecommitdiffstats
path: root/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue
diff options
context:
space:
mode:
authorSimon Rettberg2019-04-10 13:20:04 +0200
committerSimon Rettberg2019-04-10 13:20:04 +0200
commit4648634b1c17df07b50485b598ea0c6d2fe62c3b (patch)
tree94a7dfc06d3dacdd0bbc8f0437d464b05f1c97ad /core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue
parent[slx-issue] Force lines to be no longer than console width (diff)
downloadmltk-4648634b1c17df07b50485b598ea0c6d2fe62c3b.tar.gz
mltk-4648634b1c17df07b50485b598ea0c6d2fe62c3b.tar.xz
mltk-4648634b1c17df07b50485b598ea0c6d2fe62c3b.zip
[slx-issue] Make issue generator even smarter
Diffstat (limited to 'core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue')
-rwxr-xr-xcore/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue26
1 files changed, 18 insertions, 8 deletions
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
index 8165d310..e142b671 100755
--- a/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue
+++ b/core/modules/slx-issue/data/opt/openslx/scripts/openslx-create_issue
@@ -28,9 +28,9 @@ declare -rg OUTFILE=/etc/issue
# 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%"/}"
+ tst="${line//"%minspace%"/}"
+ tst="${tst//"%space%"/}"
len=${#tst}
[ "$len" -gt "$MAX" ] && MAX=$len
echo "$line"
@@ -72,25 +72,35 @@ fi
echo "" >> "$TMPFILE"
# Crop to console width
-T=$( tput cols 2> /dev/console )
+[ "$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 < /dev/console )
+ 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%"/}
- if [ "$(( ${#line} - ${#tst} ))" -eq 7 ]; then
+ tst=${tst/"%minspace%"/}
+ if [ "${#line}" != "${#tst}" ]; then
space=
while true; do
tst=${line/"%space%"/"$space"}
- if [ "${#tst}" -ge "$MAX" ]; then
- line="$tst"
+ 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
- space=" $space"
done
fi
echo "${line:0:$MAX}"