2024-11-25 14:10:13 +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
|
|
|
|
|
2025-02-13 08:57:23 +04:00
|
|
|
function parse_runphp() {
|
|
|
|
local runphp="$1" preamble="$2" conf="$3" postamble="$4"
|
|
|
|
local conf0
|
|
|
|
ac_set_tmpfile conf0
|
|
|
|
# extraire la configuration depuis le fichier
|
|
|
|
<"$runphp" awk -v preamble="$preamble" -v conf="$conf0" -v postamble="$postamble" '
|
|
|
|
BEGIN { out = preamble }
|
|
|
|
{
|
|
|
|
if ($0 ~ /SOF:runphp.userconf:/) {
|
|
|
|
if (out != "") print >out
|
|
|
|
out = conf
|
|
|
|
} else if ($0 ~ /EOF:runphp.userconf:/) {
|
|
|
|
out = postamble
|
|
|
|
if (out != "") print >out
|
|
|
|
} else {
|
|
|
|
if (out != "") print >out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
# mettre en forme le fichier conf: pas de lignes vides avant et après
|
|
|
|
<"$conf0" >"$conf" awk '
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
ac_clean "$conf0"
|
|
|
|
}
|
|
|
|
|
2024-11-25 14:10:13 +04:00
|
|
|
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:-.}"
|
2025-02-13 08:57:23 +04:00
|
|
|
if [ -d "$runphp" ]; then
|
|
|
|
runphp="$runphp/runphp"
|
|
|
|
elif [ ! -e "$runphp" ]; then
|
|
|
|
[ "${runphp%/runphp}" != "$runphp" ] || runphp="$runphp/runphp"
|
|
|
|
fi
|
2024-11-25 14:10:13 +04:00
|
|
|
|
2025-02-13 08:57:23 +04:00
|
|
|
setx runphp=abspath "$runphp"
|
2024-11-25 14:10:13 +04:00
|
|
|
setx rundir=dirname -- "$runphp"
|
2025-02-13 08:57:23 +04:00
|
|
|
[ "$rundir" == "$MYDIR" ] && exit 0
|
2024-11-25 14:10:13 +04:00
|
|
|
[ -d "$rundir" ] || mkdir -p "$rundir"
|
|
|
|
|
2025-02-13 08:57:23 +04:00
|
|
|
# Tout d'abord, isoler chaque partie du fichier local
|
|
|
|
ac_set_tmpfile preamble
|
|
|
|
ac_set_tmpfile conf
|
|
|
|
ac_set_tmpfile postamble
|
|
|
|
parse_runphp "$MYDIR/runphp" "$preamble" "$conf" "$postamble"
|
|
|
|
|
|
|
|
# Puis analyser le fichier destination
|
2024-11-25 14:10:13 +04:00
|
|
|
if [ -f "$runphp" ]; then
|
|
|
|
ac_set_tmpfile userconf
|
2025-02-13 08:57:23 +04:00
|
|
|
parse_runphp "$runphp" "" "$userconf" ""
|
2024-11-25 14:10:13 +04:00
|
|
|
initial_config=
|
|
|
|
|
|
|
|
elif [ -n "$projdir" ]; then
|
|
|
|
# forcer BUILDENV0=..env.dist et BUILDENV=.env pour les projets de
|
|
|
|
# l'université de la Réunion
|
|
|
|
ac_set_tmpfile userconf
|
2025-02-13 08:57:23 +04:00
|
|
|
sed <"$conf" >"$userconf" '
|
2024-11-25 14:10:13 +04:00
|
|
|
/^BUILDENV0=/s/=.*/=..env.dist/
|
|
|
|
/^BUILDENV=/s/=.*/=.env/
|
|
|
|
'
|
2025-02-13 08:57:23 +04:00
|
|
|
initial_config=1
|
2024-11-25 14:10:13 +04:00
|
|
|
|
|
|
|
else
|
2025-02-13 08:57:23 +04:00
|
|
|
userconf="$conf"
|
2024-11-25 14:10:13 +04:00
|
|
|
initial_config=1
|
|
|
|
fi
|
|
|
|
|
2025-02-13 08:57:23 +04:00
|
|
|
# (Re)construire le fichier destination
|
2024-11-25 14:10:13 +04:00
|
|
|
(
|
2025-02-13 08:57:23 +04:00
|
|
|
cat "$preamble"
|
2024-11-25 14:10:13 +04:00
|
|
|
echo
|
|
|
|
cat "$userconf"
|
|
|
|
echo
|
2025-02-13 08:57:23 +04:00
|
|
|
cat "$postamble"
|
2024-11-25 14:10:13 +04:00
|
|
|
) >"$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
|
|
|
|
if [ ! -f "$projdir/.runphp.conf" ]; then
|
|
|
|
sed <"$MYDIR/dot-runphp.conf" >"$projdir/.runphp.conf" '
|
|
|
|
/^RUNPHP=/s/=.*/=sbin\/runphp/
|
|
|
|
'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$initial_config" ]
|