summaryrefslogtreecommitdiffstats
path: root/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/openslx-create_issue
blob: d3086176439bccfab32f9c4a3e90d35e2dc7bd48 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/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"}"
	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"