From 1448e18fe6ce4b1de79598ea48b8ee2a89d7d260 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 13 Feb 2025 08:57:23 +0400 Subject: [PATCH] travailler directement sur runphp --- runphp/dot-build.env.dist | 2 +- runphp/runphp | 2 +- runphp/runphp.1preamble | 18 -- runphp/runphp.2postamble | 534 -------------------------------------- runphp/runphp.userconf | 29 --- runphp/update-runphp.sh | 87 +++++-- 6 files changed, 61 insertions(+), 611 deletions(-) delete mode 100644 runphp/runphp.1preamble delete mode 100644 runphp/runphp.2postamble delete mode 100644 runphp/runphp.userconf diff --git a/runphp/dot-build.env.dist b/runphp/dot-build.env.dist index e8202f8..7baed50 100644 --- a/runphp/dot-build.env.dist +++ b/runphp/dot-build.env.dist @@ -16,6 +16,6 @@ PRIVAREG= REGISTRY=pubdocker.univ-reunion.fr/dist DIST=d12 -IMAGENAME=runphp +IMAGENAME=nulib/ #DEVUSER_USERENT=user:x:1000:1000:User,,,:/home/user:/bin/bash #DEVUSER_GROUPENT=user:x:1000: diff --git a/runphp/runphp b/runphp/runphp index ad4dc8a..815aa8c 100755 --- a/runphp/runphp +++ b/runphp/runphp @@ -33,7 +33,7 @@ BUILDENV0= BUILDENV= # Listes des images que le script build construit automatiquement -BUILD_IMAGES=() +BUILD_IMAGES=(php-apache mariadb10) BUILD_FLAVOUR= ## En ce qui concerne DIST et IMAGENAME, les valeurs dans BUILDENV prennent le diff --git a/runphp/runphp.1preamble b/runphp/runphp.1preamble deleted file mode 100644 index f290705..0000000 --- a/runphp/runphp.1preamble +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 -# Script permettant de lancer une commande dans docker et/ou de bootstrapper -# l'utilisation de nulib dans un projet PHP -# Les fichiers suivants doivent être copiés à un endroit quelconque du projet: -# - runphp (ce script, à générer avec update-runphp.sh) -# - Dockerfile.runphp -# Les fichiers suivants peuvent être intégrés dans le projet comme exemples: -# - dot-build.env.dist (à renommer en .build.env.dist) -# - dot-dkbuild.env.dist (indiquer qu'il faut le copier en ~/.dkbuild.env) -# Par défaut, ce script assume que runphp est copié dans le répertoire sbin/ -# du projet, et que le fichier composer.json et le répertoire vendor/ sont à la -# racine du projet. Le cas échéant, modifier les valeurs ci-dessous -(return 0 2>/dev/null) && _sourced=1 || _sourced= - -############################################################################### -# Modifier les valeurs suivantes si nécessaire -#SOF:runphp.userconf:ne pas modifier cette ligne diff --git a/runphp/runphp.2postamble b/runphp/runphp.2postamble deleted file mode 100644 index 07c847e..0000000 --- a/runphp/runphp.2postamble +++ /dev/null @@ -1,534 +0,0 @@ -#EOF:runphp.userconf:ne pas modifier cette ligne -################################################################################ - -# Ne pas modifier à partir d'ici - -if [ -n "$_sourced" ]; then - if [ "${0#-}" != "$0" ]; then - # sourcé depuis la ligne de commande - MYSELF="${BASH_SOURCE[1]}" - else - # sourcé depuis un script - MYSELF="${BASH_SOURCE[0]}" - fi - MYDIR="$(cd "$(dirname -- "$MYSELF")"; pwd)" - MYNAME="$(basename -- "$MYSELF")" -else - MYDIR="$(cd "$(dirname -- "$0")"; pwd)" - MYNAME="$(basename -- "$0")" -fi -if [ -f "$MYDIR/runphp.userconf.local" ]; then - source "$MYDIR/runphp.userconf.local" -fi - -DEFAULT_DIST=d12 -if [ -n "$RUNPHP_STANDALONE" ]; then - PROJDIR="$RUNPHP_PROJDIR" - - COMPOSERDIR=. - COMPOSERPHAR= - VENDORDIR=vendor - BUILDENV0= - BUILDENV= - DIST="${RUNPHP_DIST:-$DEFAULT_DIST}" - IMAGENAME=nulib/ - - PRIVAREG=docker.io - REGISTRY="$RUNPHP_REGISTRY" - - [ -n "$RUNPHP_BUILD_FLAVOUR" ] && BUILD_FLAVOUR="$RUNPHP_BUILD_FLAVOUR" - -else - [ -n "$PROJDIR" ] || PROJDIR="$(dirname -- "$MYDIR")" - [ "${PROJDIR#/}" != "$PROJDIR" ] || PROJDIR="$(cd "$MYDIR/$PROJDIR"; pwd)" - - [ -n "$COMPOSERDIR" ] || COMPOSERDIR=. - [ -n "$COMPOSERPHAR" ] || COMPOSERPHAR=sbin/composer.phar - [ -n "$VENDORDIR" ] || VENDORDIR=vendor - [ -n "$BUILDENV0" ] || BUILDENV0=.build.env.dist - [ -n "$BUILDENV" ] || BUILDENV=build.env - [ -n "$DIST" ] || DIST="$DEFAULT_DIST" - [ -n "$IMAGENAME" ] || IMAGENAME=nulib/ - - [ "$COMPOSERPHAR" == none ] && COMPOSERPHAR= - [ "$BUILDENV0" == none ] && BUILDENV0= - [ "$BUILDENV" == none ] && BUILDENV= -fi -[ "$BUILD_FLAVOUR" == none ] && BUILD_FLAVOUR= - -function after_source_buildenv() { - NDIST="${DIST#d}" -} -after_source_buildenv - -[ -n "$_sourced" ] && return 0 - -function eecho() { echo "$*" 1>&2; } -function eerror() { eecho "ERROR: $*"; } -function die() { [ $# -gt 0 ] && eerror "$*"; exit 1; } -function is_defined() { [ -n "$(declare -p "$1" 2>/dev/null)" ]; } -function in_path() { [ -n "$1" -a -x "$(which "$1" 2>/dev/null)" ]; } -function composer() { - cd "$PROJDIR/$COMPOSERDIR" || exit 1 - if [ -n "$COMPOSERPHAR" -a -x "$PROJDIR/$COMPOSERPHAR" ]; then - "$PROJDIR/$COMPOSERPHAR" "$@" - elif in_path composer; then - command composer "$@" - elif [ -x /usr/bin/composer ]; then - /usr/bin/composer "$@" - elif [ -x /usr/local/bin/composer ]; then - /usr/local/bin/composer "$@" - else - die "impossible de trouver composer" - fi - if [ -z "$RUNPHP_STANDALONE" -a -f composer.lock ]; then - cp composer.lock "$PROJDIR/.composer.lock.runphp" - fi -} -function ensure_image() { - local dfdir suffix dockerfiles dockerfile - local privareg imagename - if [ -z "$Image" ]; then - [ -n "$RUNPHP_STANDALONE" ] && dfdir="$RUNPHP_STANDALONE/runphp" || dfdir="$MYDIR" - dockerfiles=( - "_local:$dfdir/Dockerfile.runphp.local" - "${BUILD_FLAVOUR//+/_}:$dfdir/Dockerfile.runphp$BUILD_FLAVOUR" - ":$dfdir/Dockerfile.runphp" - ) - for dockerfile in "${dockerfiles[@]}"; do - suffix="${dockerfile%:*}" - dockerfile="${dockerfile##*:}" - [ -f "$dockerfile" ] && break - done - Dockerfile="$dockerfile" - - [[ "$IMAGENAME" == */ ]] && imagename=runphp || imagename="${IMAGENAME%/*}/runphp" - privareg="$PRIVAREG" - if [ "$imagename" == runphp ]; then - [ -z "$privareg" -o "$privareg" == docker.io ] && privareg=docker.io/library - else - [ -z "$privareg" ] && privareg=docker.io - fi - Image="$privareg/$imagename$suffix:$DIST" - fi -} -function check_image() { - local image="$Image" - for prefix in docker.io/library/ docker.io; do - if [ "${image#$prefix}" != "$image" ]; then - image="${image#$prefix}" - break - fi - done - [ -n "$(docker image ls --no-trunc --format '{{.Repository}}:{{.Tag}}' "$image" 2>/dev/null)" ] -} - -## Arguments initiaux - -Bootstrap= -ComposerInstall= -if [ "$1" == --runphp-bootstrap -o "$1" == --bs ]; then - Bootstrap=1 - shift -elif [ "$1" == --runphp-exec ]; then - Bootstrap= - shift -elif [ "$1" == --runphp-install -o "$1" == --ci ]; then - ComposerInstall=1 - shift -fi - -ForcedBootstrap= -if [ -z "$Bootstrap" -a -z "$RUNPHP_STANDALONE" ]; then - # si vendor/ n'existe pas, alors on doit faire bootstrap - if [ ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then - ForcedBootstrap=1 - elif [ ! -f "$PROJDIR/.composer.lock.runphp" ]; then - ForcedBootstrap=1 - elif ! diff -q "$PROJDIR/$COMPOSERDIR/composer.lock" "$PROJDIR/.composer.lock.runphp" >&/dev/null; then - ForcedBootstrap=1 - fi - if [ -n "$ForcedBootstrap" ]; then - [ "$RUNPHP_MODE" != docker ] && eecho "== bootstrapping runphp" - Bootstrap=1 - ComposerInstall=1 - fi -fi - -if [ "$RUNPHP_MODE" != docker ]; then - ############################################################################ - # Lancement depuis l'extérieur du container - ############################################################################ - - ## Charger ~/.dkbuild.env - - APT_PROXY= - APT_MIRROR= - SEC_MIRROR= - TIMEZONE= - PRIVAREG= - REGISTRY= - PROFILE= - HOST_MAPPINGS=() - function default_profile() { - PROFILE="$1" - } - function profile() { - local profile - for profile in "$@"; do - [ "$profile" == "$PROFILE" ] && return 0 - done - return 1 - } - function setenv() { - eval "export $1" - } - function default() { - local command="$1"; shift - local nv n v - case "$command" in - docker) - for nv in "$@"; do - [[ "$nv" == *=* ]] || continue - n="${nv%%=*}" - v="${nv#*=}" - case "$n" in - host-mappings) - read -a ns <<<"$v" - for v in "${ns[@]}"; do - HOST_MAPPINGS+=("$v") - done - ;; - esac - done - ;; - esac - } - [ -f ~/.dkbuild.env ] && source ~/.dkbuild.env - [ -n "$APT_PROXY" ] || APT_PROXY= - [ -n "$APT_MIRROR" ] || APT_MIRROR=default - [ -n "$SEC_MIRROR" ] || SEC_MIRROR=default - [ -n "$TIMEZONE" ] || TIMEZONE=Europe/Paris - [ -n "$PRIVAREG" ] || PRIVAREG= - [ -n "$REGISTRY" ] || REGISTRY=pubdocker.univ-reunion.fr/dist - - ## Charger la configuration - - # Recenser les valeur de proxy - declare -A PROXY_VARS - for var in {HTTPS,ALL,NO}_PROXY {http,https,all,no}_proxy; do - is_defined "$var" && PROXY_VARS[${var,,}]="${!var}" - done - - # Paramètres de montage - if [ -n "$RUNPHP_NO_USE_RSLAVE" ]; then - UseRslave= - elif [ -n "$RUNPHP_USE_RSLAVE" ]; then - UseRslave=1 - elif [ -e /proc/sys/fs/binfmt_misc/WSLInterop ]; then - # pas de mount propagation sous WSL - UseRslave= - else - UseRslave=1 - fi - - # Toujours vérifier l'existence de l'image - Image= - if [ -z "$Bootstrap" ]; then - if [ -n "$RUNPHP_FORCE_BUILDENVS" ]; then - eval "Configs=($RUNPHP_FORCE_BUILDENVS)" - for config in "${Configs[@]}"; do - source "$config" || exit 1 - done - after_source_buildenv - elif [ -n "$BUILDENV" -a -f "$PROJDIR/$BUILDENV" ]; then - source "$PROJDIR/$BUILDENV" || exit 1 - after_source_buildenv - elif [ -n "$BUILDENV0" -a -f "$PROJDIR/$BUILDENV0" ]; then - source "$PROJDIR/$BUILDENV0" || exit 1 - after_source_buildenv - fi - ensure_image - check_image || Bootstrap=1 - fi - - Chdir= - Verbose="$RUNPHP_VERBOSE" - if [ -n "$Bootstrap" ]; then - ## Mode bootstrap de l'image ########################################### - # Ici, on a déterminé que l'image doit être construite - - BUILD_ARGS=( - DIST NDIST - REGISTRY - APT_PROXY - APT_MIRROR - SEC_MIRROR - TIMEZONE - ) - - SOPTS=+d:9876543210:c:UjDx:z:r:p - LOPTS=help,dist:,d19,d18,d17,d16,d15,d14,d13,d12,d11,d10,config:,ue,unless-exists,pull,nc,no-cache,po,plain-output,apt-proxy:,timezone:,privareg:,push,ci,no-use-rslave - args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" - - Dist= - if [ -n "$RUNPHP_FORCE_BUILDENVS" ]; then - eval "Configs=($RUNPHP_FORCE_BUILDENVS)" - elif [ -n "$BUILDENV" -a -f "$PROJDIR/$BUILDENV" ]; then - Configs=("$PROJDIR/$BUILDENV") - elif [ -n "$BUILDENV0" -a -f "$PROJDIR/$BUILDENV0" ]; then - Configs=("$PROJDIR/$BUILDENV0") - else - Configs=() - fi - UnlessExists= - Pull= - NoCache= - PlainOutput= - while [ $# -gt 0 ]; do - case "$1" in - --) shift; break;; - --help) - eecho "\ -runphp: construire l'image docker - -USAGE - $MYNAME --bootstrap [options...] - -OPTIONS - -c, --config build.env - --unless-exists - -U, --pull - -j, --no-cache - -D, --plain-output - -x, --apt-proxy APT_PROXY - -z, --timezone TIMEZONE - -r, --privareg PRIVAREG - -p, --push - paramètres pour la consruction de l'image" - exit 0 - ;; - -d|--dist) shift; Dist="$1";; - -[0-9]) Dist="d1${1#-}";; - --d*) Dist="${1#--}";; - -c|--config) shift; Configs+="$1";; - --ue|--unless-exists) UnlessExists=1;; - -U|--pull) Pull=1;; - -j|--nc|--no-cache) NoCache=1;; - -D|--po|--plain-output) PlainOutput=1;; - -x|--apt-proxy) shift; APT_PROXY="$1";; - -z|--timezone) shift; TIMEZONE="$1";; - -r|--privareg) shift; PRIVAREG="$1";; - -p|--push) Push=1;; - --ci) ComposerInstall=1;; - --no-use-rslave) UseRslave=;; - *) die "$1: option non configurée";; - esac - shift - done - - for config in "${Configs[@]}"; do - if [ "$config" == none ]; then - Configs=() - break - fi - done - if [ ${#Configs[*]} -gt 0 ]; then - for config in "${Configs[@]}"; do - source "$config" || exit 1 - done - after_source_buildenv - fi - [ -n "$Dist" ] && DIST="$Dist" - - ensure_image - check_image && exists=1 || exists= - if [ -z "$UnlessExists" -o -z "$exists" ]; then - eecho "== Building $Image" - args=( - -f "$Dockerfile" - ${Pull:+--pull} - ${NoCache:+--no-cache} - ${BuildPlain:+--progress plain} - -t "$Image" - ) - for arg in "${BUILD_ARGS[@]}"; do - args+=(--build-arg "$arg=${!arg}") - done - for arg in "${!PROXY_VARS[@]}"; do - args+=(--build-arg "$arg=${PROXY_VARS[$arg]}") - done - for host in "${HOST_MAPPINGS[@]}"; do - args+=(--add-host "$host") - done - mkdir -p /tmp/runphp-build - docker build "${args[@]}" /tmp/runphp-build || exit 1 - - if [ -n "$Push" -a -n "$PRIVAREG" ]; then - eecho "== Pushing $Image" - docker push "$Image" || exit 1 - fi - fi - if [ -z "$RUNPHP_STANDALONE" -a ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then - # Forcer l'installation des dépendances si nécessaire - ComposerInstall=1 - fi - [ -z "$ComposerInstall" -o -n "$UnlessExists" ] && exit 0 - - else - ## Mode exécution de commande ########################################## - # Ici, on a déterminé qu'il faut lancer une commande - - SOPTS=+w: - LOPTS=help,chdir:,no-use-rslave - args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" - - while [ $# -gt 0 ]; do - case "$1" in - --) shift; break;; - --help) - eecho "\ -runphp: lancer une commande dans un environnement PHP déterminé - -USAGE - $MYNAME ci|cu|composer - $MYNAME [options] command [args...] - -COMMANDES COMPOSER - ci - cu - installer/mettre à jour les dépendances du projet avec composer - composer [args...] - lancer composer avec les arguments spécifiés. - -pour les commandes ci-dessus, l'option --chdir est ignorée: le répertoire -courant est forcé au répertoire du projet composer - -OPTIONS - -w, --chdir CHDIR - aller dans le répertoire spécifié avant de lancer la commande" - exit 0 - ;; - -w|--chdir) shift; Chdir="$1";; - --no-use-rslave) UseRslave=;; - *) die "$1: option non configurée";; - esac - shift - done - - if [ -z "$RUNPHP_STANDALONE" -a ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then - # Forcer l'installation des dépendances si nécessaire - ComposerInstall=1 - fi - fi - - ## Lancer la commande - - args=( - run -it --rm - --name "runphp-$(basename -- "$1")-$$" - -e RUNPHP_MODE=docker - ) - for arg in "${!PROXY_VARS[@]}"; do - args+=(-e "$arg=${PROXY_VARS[$arg]}") - done - if [ -n "$RUNPHP_STANDALONE" ]; then - args+=( - -e "RUNPHP_STANDALONE=$RUNPHP_STANDALONE" - -e "RUNPHP_PROJDIR=$PROJDIR" - ) - fi - for host in "${HOST_MAPPINGS[@]}"; do - args+=(--add-host "$host") - done - - # monter le répertoire qui contient $PROJDIR - mount_composer= - mount_runphp=1 - if [ -z "$PROJDIR" -o "${PROJDIR#$HOME/}" != "$PROJDIR" -o "$PROJDIR" == "$HOME" ]; then - # bind mount $HOME - args+=(-v "$HOME:$HOME${UseRslave:+:rslave}") - [ -n "$RUNPHP_STANDALONE" ] && - [ "${RUNPHP_STANDALONE#$HOME/}" != "$RUNPHP_STANDALONE" ] && - mount_runphp= - else - # bind mount uniquement le répertoire du projet - args+=(-v "$PROJDIR:$PROJDIR${UseRslave:+:rslave}") - mount_composer=1 - [ "$RUNPHP_STANDALONE" == "$PROJDIR" ] && mount_runphp= - fi - if [ -n "$mount_composer" -a -d "$HOME/.composer" ]; then - # monter la configuration de composer - args+=(-v "$HOME/.composer:$HOME/.composer") - fi - if [ -n "$RUNPHP_STANDALONE" -a -n "$mount_runphp" ]; then - args+=(-v "$RUNPHP_STANDALONE:$RUNPHP_STANDALONE") - fi - args+=(-w "$(pwd)") - - # lancer avec l'utilisateur courant - if [ $(id -u) -ne 0 ]; then - # si c'est un utilisateur lambda, il faut monter les informations - # nécessaires. composer est déjà monté via $HOME - args+=( - -e DEVUSER_USERENT="$(getent passwd "$(id -un)")" - -e DEVUSER_GROUPENT="$(getent group "$(id -gn)")" - ) - fi - - args+=( - "$Image" - exec "$0" ${Chdir:+-w "$Chdir"} - ) - [ -n "$ComposerInstall" ] && set -- ci - [ -n "$Verbose" ] && eecho "\$ docker ${args[*]} $*" - exec docker "${args[@]}" "$@" - -else - ############################################################################ - # Lancement depuis l'intérieur du container - ############################################################################ - - if [ -n "$DEVUSER_USERENT" ]; then - user="${DEVUSER_USERENT%%:*}" - export DEVUSER_USERENT= - export DEVUSER_GROUPENT= - if in_path su-exec; then - exec su-exec "$user" "$0" "$@" - else - exec runuser -u "$user" -- "$0" "$@" - fi - fi - - SOPTS=+w: - LOPTS=chdir: - args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" - - chdir= - action= - while [ $# -gt 0 ]; do - case "$1" in - --) shift; break;; - -w|--chdir) shift; chdir="$1";; - *) die "$1: option non configurée";; - esac - shift - done - - if [ -z "$1" ]; then - die "no command specified" - elif [ "$1" == ci ]; then - eecho "== installing composer dependencies" - composer i - elif [ "$1" == cu ]; then - eecho "== upgrading composer dependencies" - composer u - elif [ "$1" == composer ]; then - "$@" - else - if [ -n "$chdir" ]; then - cd "$chdir" || exit 1 - fi - exec "$@" - fi -fi diff --git a/runphp/runphp.userconf b/runphp/runphp.userconf deleted file mode 100644 index b849b4b..0000000 --- a/runphp/runphp.userconf +++ /dev/null @@ -1,29 +0,0 @@ -# répertoire du projet. ce chemin doit être absolu. s'il est relatif, il est -# exprimé par rapport au répertoire de ce script -PROJDIR= - -# composer: répertoire du projet composer (celui qui contient le fichier -# composer.json), chemin de composer.phar et répertoire vendor. ces chemins -# doivent être relatifs à $PROJDIR -COMPOSERDIR= -COMPOSERPHAR= -VENDORDIR= - -# fichier de configuration pour le build -BUILDENV0= -BUILDENV= - -# Listes des images que le script build construit automatiquement -BUILD_IMAGES=(php-apache mariadb10) -BUILD_FLAVOUR= - -## En ce qui concerne DIST et IMAGENAME, les valeurs dans BUILDENV prennent le -## dessus. si BUILDENV *n'est pas* utilisé, ces valeurs peuvent être spécifiées -## ici - -# version de debian à utiliser pour l'image -# d12=php8.2, d11=php7.4, d10=php7.3 -DIST= - -# Nom de base de l'image (sans le registry), e.g prefix/ -IMAGENAME= diff --git a/runphp/update-runphp.sh b/runphp/update-runphp.sh index c17a544..05403fe 100755 --- a/runphp/update-runphp.sh +++ b/runphp/update-runphp.sh @@ -2,6 +2,44 @@ # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 source "$(dirname "$0")/../load.sh" || exit 1 +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" +} + projdir= args=( "Mettre à jour le script runphp" @@ -16,58 +54,51 @@ if [ -n "$projdir" ]; then fi runphp="${1:-.}" -[ -d "$runphp" ] && runphp="$runphp/runphp" +if [ -d "$runphp" ]; then + runphp="$runphp/runphp" +elif [ ! -e "$runphp" ]; then + [ "${runphp%/runphp}" != "$runphp" ] || runphp="$runphp/runphp" +fi +setx runphp=abspath "$runphp" setx rundir=dirname -- "$runphp" +[ "$rundir" == "$MYDIR" ] && exit 0 [ -d "$rundir" ] || mkdir -p "$rundir" +# 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 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" + parse_runphp "$runphp" "" "$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" ' + sed <"$conf" >"$userconf" ' /^BUILDENV0=/s/=.*/=..env.dist/ /^BUILDENV=/s/=.*/=.env/ ' + initial_config=1 else + userconf="$conf" initial_config=1 - userconf="$MYDIR/runphp.userconf" fi +# (Re)construire le fichier destination ( - cat "$MYDIR/runphp.1preamble" + cat "$preamble" echo cat "$userconf" echo - cat "$MYDIR/runphp.2postamble" + cat "$postamble" ) >"$runphp" [ -x "$runphp" ] || chmod +x "$runphp"