From bd6b54e904485783cb0352483798609b6822ad91 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Dec 2018 12:56:13 +0200 Subject: Improve pxeflatten script to support combining multiple files --- pxeflatten | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/pxeflatten b/pxeflatten index cb80218..78a5c84 100755 --- a/pxeflatten +++ b/pxeflatten @@ -6,17 +6,22 @@ # 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 +# To help with this situation, this script will take a milti-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), +# is the last line without a trailing newline (and without a trailing space), # then you can do: # # pxeflatten pxeconfig >>pxelinux.cfg/default # -usage="usage: $0 []" +# Options: +# +# -n +# Don't write trailing newline (useful for appending multiple configs). +# +usage="usage: $0 [-n] []" owd="$(pwd)" trap "{ cd '$owd'; exit 1; }" ERR @@ -25,16 +30,40 @@ set -o errtrace # Trap in functions. function info () { echo "$*" 1>&2; } function error () { info "$*"; exit 1; } +nl=true + +while [ "$#" -gt 0 ]; do + case "$1" in + -n) + nl= + shift + ;; + -*) + error "unknown option: $1" + ;; + --) + shift + break + ;; + *) + break + ;; + esac +done + if [ -z "$1" ]; then input="-" else input="$1" fi -s= l= while read l || [ -n "$l" ]; do - echo -n "$s$l" - s=" " + echo -n " $l" done < <(sed -e '/^\s*#/d;/^\s*$/d;s/\s\s*/ /g' "$input") -echo # Final newline. + +# Final newline. +# +if [ "$nl" ]; then + echo +fi -- cgit v1.1