nulib/support/update-rundk.sh

88 lines
2.1 KiB
Bash
Raw Normal View History

2024-04-19 11:46:31 +04:00
#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source "$(dirname "$0")/../load.sh" || exit 1
2024-04-19 11:46:31 +04:00
projdir=
2024-04-19 11:46:31 +04:00
args=(
"Mettre à jour le script rundk"
"[path/to/rundk]"
2024-05-15 15:35:30 +04:00
-d:,--projdir:PROJDIR . "Copier les fichiers pour un projet de l'université de la Réunion"
2024-04-19 11:46:31 +04:00
)
parse_args "$@"; set -- "${args[@]}"
if [ -n "$projdir" ]; then
setx projdir=abspath "$projdir"
set -- "$projdir/sbin/rundk"
fi
2024-04-19 11:46:31 +04:00
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"
initial_config=
2024-05-15 15:35:30 +04:00
elif [ -n "$projdir" ]; then
# forcer BUILDENV0=..env.dist et BUILDENV=.env pour les projets de
# l'université de la Réunion
initial_config=1
ac_set_tmpfile userconf
sed <"$MYDIR/rundk.userconf" >"$userconf" '
/^BUILDENV0=/s/=.*/=..env.dist/
/^BUILDENV=/s/=.*/=.env/
'
2024-04-19 11:46:31 +04:00
else
initial_config=1
2024-05-15 15:35:30 +04:00
userconf="$MYDIR/rundk.userconf"
2024-04-19 11:46:31 +04:00
fi
(
cat "$MYDIR/rundk.1preamble"
echo
cat "$userconf"
echo
cat "$MYDIR/rundk.2postamble"
) >"$rundk"
[ -x "$rundk" ] || chmod +x "$rundk"
2024-04-19 11:53:37 +04:00
rsync -lpt "$MYDIR/Dockerfile.rundk" "$rundir/"
if [ -n "$projdir" ]; then
2024-05-16 10:08:29 +04:00
if testdiff "$rundir/build" "$MYDIR/build"; then
cp "$MYDIR/build" "$rundir/build"
chmod +x "$rundir/build"
fi
2024-05-12 18:17:25 +04:00
if [ ! -f "$projdir/..env.dist" ]; then
sed <"$MYDIR/dot-build.env.dist" >"$projdir/..env.dist" '
/^IMAGENAME=/s/=.*\//='"$(basename -- "$projdir")"'\//
'
initial_config=1
fi
fi
[ -n "$initial_config" ]