nulib/support/update-rundk.sh

55 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source /etc/nulib.sh || exit 1
args=(
"Mettre à jour le script rundk"
"[path/to/rundk]"
)
parse_args "$@"; set -- "${args[@]}"
rundk="${1:-.}"
[ -d "$rundk" ] && rundk="$rundk/rundk"
setx rundir=dirname -- "$rundk"
[ -d "$rundir" ] || mkdir -p "$rundir"
if [ -f "$rundk" ]; then
ac_set_tmpfile userconf
<"$rundk" awk '
# extraire la configuration depuis le fichier
BEGIN { p = 0 }
/SOF:rundk.userconf:/ { p = 1; next }
/EOF:rundk.userconf:/ { p = 0; next }
p == 1 { print }
' | awk '
# mettre en forme le fichier: pas de lignes vides avant et après
BEGIN { p = 0; have_pending = 0; pending = "" }
$0 != "" { p = 1 }
p == 1 {
if ($0 != "") {
if (have_pending) print pending
print
have_pending = 0
pending = ""
} else {
if (!have_pending) have_pending = 1
else pending = pending "\n"
}
}
' >"$userconf"
else
userconf="$MYDIR/rundk.userconf"
fi
(
cat "$MYDIR/rundk.1preamble"
echo
cat "$userconf"
echo
cat "$MYDIR/rundk.2postamble"
) >"$rundk"
[ -x "$rundk" ] || chmod +x "$rundk"
rsync -lpt "$MYDIR/Dockerfile.rundk" "$rundir/"