aboutsummaryrefslogtreecommitdiff
path: root/pxeflatten
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-08-09 10:12:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-08-09 10:12:30 +0200
commit90a5772d2466e6443b6fa632b3cb979e4346d22a (patch)
tree1d583108a094ebffd04e43817c5c3440a58e1878 /pxeflatten
parent2fd87d0c656fb1806b33ef3fcec7e8c7f52779a4 (diff)
Add pxelinux configuration flattening script
Diffstat (limited to 'pxeflatten')
-rwxr-xr-xpxeflatten40
1 files changed, 40 insertions, 0 deletions
diff --git a/pxeflatten b/pxeflatten
new file mode 100755
index 0000000..cb80218
--- /dev/null
+++ b/pxeflatten
@@ -0,0 +1,40 @@
+#! /usr/bin/env bash
+
+# Flatten a multi-line PXELINUX config file ignoring comments/blank lines.
+#
+# The text that appears after the 'append' clause in PXELINUX config files
+# must all be on a single line. There is no support even for line
+# continuation. This makes managing complex configurations a pain.
+#
+# To help with this situation, this script will take a milt-line file (or
+# stdin if none is specified) and write flattened, single line output into
+# stdout ignoring #-comments and blank lines while at it.
+#
+# If you have prepared your PXELINUX config file so that the 'append' clause
+# is the last line without a trailing newline (but with a trailing space),
+# then you can do:
+#
+# pxeflatten pxeconfig >>pxelinux.cfg/default
+#
+usage="usage: $0 [<file>]"
+
+owd="$(pwd)"
+trap "{ cd '$owd'; exit 1; }" ERR
+set -o errtrace # Trap in functions.
+
+function info () { echo "$*" 1>&2; }
+function error () { info "$*"; exit 1; }
+
+if [ -z "$1" ]; then
+ input="-"
+else
+ input="$1"
+fi
+
+s=
+l=
+while read l || [ -n "$l" ]; do
+ echo -n "$s$l"
+ s=" "
+done < <(sed -e '/^\s*#/d;/^\s*$/d;s/\s\s*/ /g' "$input")
+echo # Final newline.