2024-10-01 12:35:08 +04:00
|
|
|
# TODO Faire une copie de ce script dans un répertoire de l'application web
|
|
|
|
# (dans le répertoire _cli/ par défaut) et modifier les paramétres si nécessaire
|
|
|
|
#-------------------------------------------------------------------------------
|
2024-09-25 17:10:14 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
2024-10-01 12:35:08 +04:00
|
|
|
# S'assurer que le script PHP est lancé avec l'utilisateur www-data
|
|
|
|
# Tous les chemins suivants sont relatifs au répertoire qui contient ce script
|
2024-09-26 08:48:04 +04:00
|
|
|
|
2024-09-26 09:38:54 +04:00
|
|
|
# Chemin relatif de la racine du projet
|
2024-09-26 08:48:04 +04:00
|
|
|
PROJPATH=..
|
|
|
|
|
2024-09-26 09:38:54 +04:00
|
|
|
# Chemin relatif vers le lanceur PHP
|
2024-10-01 12:49:26 +04:00
|
|
|
LAUNCHERPATH=.launcher.php
|
2024-09-26 08:48:04 +04:00
|
|
|
|
2024-09-26 09:38:54 +04:00
|
|
|
# Chemin relatif des scripts PHP wrappés
|
|
|
|
WRAPPEDPATH=
|
2024-09-26 08:48:04 +04:00
|
|
|
|
2024-10-12 08:53:13 +04:00
|
|
|
# Nom du service dans docker-compose.yml
|
|
|
|
COMPOSE_SERVICE=web
|
|
|
|
|
|
|
|
# Montages dans docker-compose.yml
|
|
|
|
# les répertoires relatifs le sont par rapport au répertoire du projet
|
|
|
|
COMPOSE_MOUNTS=(
|
2024-10-12 14:58:48 +04:00
|
|
|
devel:/data/PROJNAME
|
2024-10-12 08:53:13 +04:00
|
|
|
.:/var/www/app
|
|
|
|
)
|
|
|
|
|
2024-09-26 08:48:04 +04:00
|
|
|
###############################################################################
|
2024-10-12 08:53:13 +04:00
|
|
|
|
|
|
|
case "${RUNPHP_MODE:-auto}" in
|
|
|
|
auto)
|
2024-10-12 14:58:48 +04:00
|
|
|
RUNPHP_MODE=
|
|
|
|
[ -f /.dockerenv ] && RUNPHP_MODE=docker
|
|
|
|
[ -z "$RUNPHP_MODE" -a -f /proc/self/mountinfo ] && grep -q ' /docker/' /proc/self/mountinfo && RUNPHP_MODE=docker
|
|
|
|
[ -z "$RUNPHP_MODE" -a -f /proc/1/cgroup ] && grep -q ':/docker/' /proc/1/cgroup && RUNPHP_MODE=docker
|
|
|
|
[ -n "$RUNPHP_MODE" ] || RUNPHP_MODE=host
|
2024-10-12 08:53:13 +04:00
|
|
|
;;
|
|
|
|
docker) RUNPHP_MODE=docker;;
|
|
|
|
host) RUNPHP_MODE=host;;
|
|
|
|
direct) RUNPHP_MODE=direct;;
|
|
|
|
*) RUNPHP_MODE=host;;
|
|
|
|
esac
|
|
|
|
|
2024-10-01 12:35:08 +04:00
|
|
|
MYDIR="$(dirname -- "$0")"
|
|
|
|
MYNAME="$(basename -- "$0")"
|
2024-09-25 17:10:14 +04:00
|
|
|
if [ ! -L "$0" ]; then
|
|
|
|
echo "\
|
2024-10-01 12:37:04 +04:00
|
|
|
$0
|
|
|
|
Ce script doit être lancé en tant que lien symbolique avec un nom de la forme
|
|
|
|
'monscript.php' et lance le script PHP du même nom situé dans le même répertoire
|
2024-10-12 08:53:13 +04:00
|
|
|
avec l'utilisateur www-data"
|
2024-10-01 12:35:08 +04:00
|
|
|
|
2024-10-12 08:53:13 +04:00
|
|
|
if [ "$RUNPHP_MODE" == host ]; then
|
|
|
|
echo "\
|
|
|
|
----------------------------------------
|
2024-10-01 12:49:26 +04:00
|
|
|
Vérification des liens..."
|
2024-10-12 08:53:13 +04:00
|
|
|
cd "$MYDIR"
|
|
|
|
for i in *.php*; do
|
|
|
|
[ -f "$i" ] || continue
|
|
|
|
name="bin/${i%.*}.php"
|
|
|
|
dest="../_cli/_wrapper.sh"
|
|
|
|
link="../bin/${i%.*}.php"
|
|
|
|
if [ -L "$link" ]; then
|
|
|
|
echo "* $name OK"
|
|
|
|
elif [ -e "$link" ]; then
|
|
|
|
echo "* $name KO (not a link)"
|
|
|
|
else
|
|
|
|
echo "* $name NEW"
|
|
|
|
ln -s "$dest" "$link" || exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2024-09-25 17:10:14 +04:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
MYTRUESELF="$(readlink -f "$0")"
|
|
|
|
MYTRUEDIR="$(dirname -- "$MYTRUESELF")"
|
2024-09-26 08:48:04 +04:00
|
|
|
PROJDIR="$(cd "$MYTRUEDIR${PROJPATH:+/$PROJPATH}"; pwd)"
|
2024-10-12 08:53:13 +04:00
|
|
|
|
|
|
|
if [ "$RUNPHP_MODE" == host ]; then
|
2024-10-12 14:58:48 +04:00
|
|
|
projname="$(basename "$PROJDIR")"; projname="${projname%-app}"
|
2024-10-12 08:53:13 +04:00
|
|
|
cwd="$(pwd)"
|
|
|
|
found=
|
|
|
|
workdir=
|
|
|
|
for mounts in "${COMPOSE_MOUNTS[@]}"; do
|
|
|
|
hdir="${mounts%%:*}"
|
|
|
|
hdir="$(cd "$PROJDIR/$hdir"; pwd)"
|
2024-10-12 14:58:48 +04:00
|
|
|
ddir="${mounts#*:}"
|
|
|
|
ddir="${ddir/PROJNAME/$projname}"
|
2024-10-12 08:53:13 +04:00
|
|
|
if [ "$cwd" == "$hdir" ]; then
|
|
|
|
found=1
|
|
|
|
workdir="$ddir"
|
|
|
|
break
|
|
|
|
elif [ "${cwd#$hdir/}" != "$cwd" ]; then
|
|
|
|
found=1
|
|
|
|
workdir="$ddir/${cwd#$hdir/}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -z "$found" ]; then
|
|
|
|
echo "Impossible de mapper le répertoire courant avec les montages du container"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
args=(
|
|
|
|
docker compose run
|
|
|
|
${RUNPHP_BUILD:+--build}
|
|
|
|
--rm
|
|
|
|
--workdir "$workdir"
|
|
|
|
"$COMPOSE_SERVICE"
|
|
|
|
exec "$MYNAME"
|
|
|
|
"$@"
|
|
|
|
)
|
|
|
|
cd "$PROJDIR"
|
|
|
|
exec "${args[@]}"
|
|
|
|
fi
|
|
|
|
|
2024-09-26 09:38:54 +04:00
|
|
|
launcher="$MYTRUEDIR/$LAUNCHERPATH"
|
|
|
|
class="$MYTRUEDIR${WRAPPEDPATH:+/$WRAPPEDPATH}/${MYNAME%.php}.phpc"
|
|
|
|
script="$MYTRUEDIR${WRAPPEDPATH:+/$WRAPPEDPATH}/${MYNAME%.php}.php"
|
2024-09-25 17:10:14 +04:00
|
|
|
|
2024-09-30 16:22:33 +04:00
|
|
|
[ -f /g/init.env ] && source /g/init.env
|
|
|
|
|
2024-09-25 17:10:14 +04:00
|
|
|
www_data="${DEVUSER_USERENT%%:*}"
|
|
|
|
[ -n "$www_data" ] || www_data=www-data
|
|
|
|
|
2024-09-26 09:38:54 +04:00
|
|
|
cmd=(php "$launcher")
|
2024-09-25 17:10:14 +04:00
|
|
|
[ -n "$MEMPROF_PROFILE" ] && cmd+=(-dextension=memprof.so)
|
|
|
|
if [ -f "$class" ]; then
|
|
|
|
cmd+=("$(<"$class")")
|
|
|
|
else
|
|
|
|
cmd+=("$script")
|
|
|
|
fi
|
|
|
|
cmd+=("$@")
|
|
|
|
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
su-exec "$www_data" "${cmd[@]}"
|
|
|
|
else
|
|
|
|
exec "${cmd[@]}"
|
|
|
|
fi
|