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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#!/bin/sh
# file: src/src2conf
# copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2001-2020)
# license: GNU General Public License, version 3
# description: src2conf - build .conf from .conf.src
. $(dirname $0)/bootcdconf.lib
usage()
{
cat <<END
$(basename $0) [--without <varslist>] <conf>
<conf> bootcd2disk.conf|bootcdwrite.conf
<varslist> comma separated list of variables defined in <conf>
that will be ignored
Write <conf> with vars defined in <conf>.src to stdout.
END
[ ! "$1" ] || err "$1"
}
err()
{
echo "ERROR: src2conf: $1" >&2
exit 1
}
# catfile <file>
catfile()
{
[ -f $1 ] || err "No file $1"
cat $1
}
# src2conf <src> <program> <conf>
src2conf()
{
local src program conf re vars i i2 c
src="$1"
program="$2"
conf="$3"
re="^### conf.src"
vars="$(list_$conf)"
# checks
for i in conf.start conf.end; do
[ "$(catfile "$src" | grep "$re $i$")" ] || err "src2conf: missing <$re $i>"
done
for i in $(catfile "$src" | sed -E -n -e "s/$re (\S+)$/\1/p" |
grep -v -e "^conf.start$" -e "^conf.end$"); do
[ "$(echo " $vars " | grep " $i ")" ] || err "src2conf $src $program $conf: bad line <$re $i>"
done
# start
[ ! "$without" ] || vars="$(echo " $vars " | eval "sed $without" | sed -e "s/ $//" -e "s/^ //")"
for i in conf.start $vars; do
i2="$(echo "$i" | sed -e "s/#$/hash/" -e "s/()$//")"
[ "$i2" = "conf.start" ] || printbefore_${program}_${i2}
re_i="$(echo "$i" | sed "s/()/\\\\(\\\\)/")"
c="$(catfile "$src" | gawk '/'"$re $re_i$"'/ { ok=1; next } /'"$re "'/ {ok=0; next} { if(ok) {print} }')"
if [ "$c" ]; then
[ "$i" = "conf.start" ] || echo "#"
echo "$c"
echo "#"
else
echo "#"
fi
done
}
without=""
while [ $# -gt 1 ]; do
if [ "$1" = "--without" ]; then
without="$(echo " $2 " | sed -e "s/,/ /g" | sed -E -e "s|(\S+)|-e \"s/ \1 / /\"|g" | sed -e "s/ $//" -e "s/^ //")"
shift 2
fi
done
if [ $# -ne 1 ]; then
usage
exit 1
fi
name="$1"
[ "$(echo "$name" | cut -d. -f3)" = "conf" ] &&
program="$(echo "$name" | cut -d. -f2)" ||
program="$(echo "$name" | cut -d. -f1)"
[ "$(echo " bootcdwrite bootcd2disk " | grep " $program ")" ] ||
err "progam=<$program> shoud be: bootcdwrite or bootcd2disk"
src2conf $1.src $program ${program}conf
|