nulib/runphp/update-runphp.sh

88 lines
2.1 KiB
Bash
Executable File

#!/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
projdir=
args=(
"Mettre à jour le script runphp"
"[path/to/runphp]"
-d:,--projdir:PROJDIR . "Copier les fichiers pour un projet de l'université de la Réunion"
)
parse_args "$@"; set -- "${args[@]}"
if [ -n "$projdir" ]; then
setx projdir=abspath "$projdir"
set -- "$projdir/sbin/runphp"
fi
runphp="${1:-.}"
[ -d "$runphp" ] && runphp="$runphp/runphp"
setx rundir=dirname -- "$runphp"
[ -d "$rundir" ] || mkdir -p "$rundir"
if [ -f "$runphp" ]; then
ac_set_tmpfile userconf
<"$runphp" awk '
# extraire la configuration depuis le fichier
BEGIN { p = 0 }
/SOF:runphp.userconf:/ { p = 1; next }
/EOF:runphp.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=
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/runphp.userconf" >"$userconf" '
/^BUILDENV0=/s/=.*/=..env.dist/
/^BUILDENV=/s/=.*/=.env/
'
else
initial_config=1
userconf="$MYDIR/runphp.userconf"
fi
(
cat "$MYDIR/runphp.1preamble"
echo
cat "$userconf"
echo
cat "$MYDIR/runphp.2postamble"
) >"$runphp"
[ -x "$runphp" ] || chmod +x "$runphp"
rsync -lpt "$MYDIR/Dockerfile.runphp" "$rundir/"
if [ -n "$projdir" ]; then
if testdiff "$rundir/build" "$MYDIR/build"; then
cp "$MYDIR/build" "$rundir/build"
chmod +x "$rundir/build"
fi
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" ]