From 7e8901a7f6fee2726aa99e351e80c2bbf1c0bb16 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 18 Oct 2024 15:28:55 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- bin/runphp | 9 +- {bin/lib-runphp => runphp}/runphp | 6 +- runphp/runphp.2postamble | 132 ++++++++++++------------- runphp/{update.sh => update-runphp.sh} | 0 4 files changed, 72 insertions(+), 75 deletions(-) rename {bin/lib-runphp => runphp}/runphp (99%) rename runphp/{update.sh => update-runphp.sh} (100%) diff --git a/bin/runphp b/bin/runphp index 3035dfe..4672eab 100755 --- a/bin/runphp +++ b/bin/runphp @@ -61,13 +61,12 @@ if [ -f "$PROJDIR/.runphp.conf" ]; then [ -n "$RUNPHP" ] && exec "$PROJDIR/$RUNPHP" "$@" elif [ -f "$PROJDIR/sbin/runphp" ]; then exec "$PROJDIR/sbin/runphp" "$@" +elif [ -f "$PROJDIR/runphp" ]; then + exec "$PROJDIR/runphp" "$@" fi -[ -n "$DIST" ] || DIST=d12 -[ -x "$MYDIR/$DIST/runphp" ] || die "$DIST: distribution non supportée" - -export RUNPHP_STANDALONE=1 +export RUNPHP_STANDALONE="$NULIBDIR" export RUNPHP_PROJDIR="$PROJDIR" export RUNPHP_REGISTRY="$REGISTRY" export RUNPHP_DIST="$DIST" -"$MYDIR/$DIST/runphp" "$@" +exec "$MYDIR/../runphp/runphp" "$@" diff --git a/bin/lib-runphp/runphp b/runphp/runphp similarity index 99% rename from bin/lib-runphp/runphp rename to runphp/runphp index c66bdd2..22c3692 100755 --- a/bin/lib-runphp/runphp +++ b/runphp/runphp @@ -261,8 +261,6 @@ if [ "$RUNPHP_MODE" != docker ]; then [ -n "$PRIVAREG" ] || PRIVAREG= [ -n "$REGISTRY" ] || REGISTRY=pubdocker.univ-reunion.fr - ## Construire l'image - if [ -n "$RUNPHP_NO_USE_RSLAVE" ]; then UseRslave= elif [ -n "$RUNPHP_USE_RSLAVE" ]; then @@ -294,6 +292,8 @@ if [ "$RUNPHP_MODE" != docker ]; then fi if [ -n "$bootstrap" ]; then + ## Mode bootstrap de l'image ########################################### + BUILD_ARGS=( DIST NDIST REGISTRY @@ -426,6 +426,8 @@ OPTIONS [ -n "$BootstrapOnly" ] && exit 0 else + ## Mode exécution de commande ########################################## + SOPTS=+w:v LOPTS=help,chdir:,verbose,no-use-rslave args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" diff --git a/runphp/runphp.2postamble b/runphp/runphp.2postamble index b16be8f..780f9d2 100644 --- a/runphp/runphp.2postamble +++ b/runphp/runphp.2postamble @@ -21,6 +21,7 @@ if [ -f "$MYDIR/runphp.userconf.local" ]; then source "$MYDIR/runphp.userconf.local" fi +DEFAULT_DIST=d12 if [ -n "$RUNPHP_STANDALONE" ]; then PROJDIR="$RUNPHP_PROJDIR" @@ -29,7 +30,7 @@ if [ -n "$RUNPHP_STANDALONE" ]; then VENDORDIR=vendor BUILDENV0= BUILDENV= - DIST="$RUNPHP_DIST" + DIST="${RUNPHP_DIST:-$DEFAULT_DIST}" IMAGENAME=nulib/ PRIVAREG=docker.io @@ -44,7 +45,7 @@ else [ -n "$VENDORDIR" ] || VENDORDIR=vendor [ -n "$BUILDENV0" ] || BUILDENV0=.build.env.dist [ -n "$BUILDENV" ] || BUILDENV=build.env - [ -n "$DIST" ] || DIST=d12 + [ -n "$DIST" ] || DIST="$DEFAULT_DIST" [ -n "$IMAGENAME" ] || IMAGENAME=nulib/ [ "$COMPOSERPHAR" == none ] && COMPOSERPHAR= @@ -105,31 +106,23 @@ function check_image() { [ -n "$(docker image ls --no-trunc --format '{{.Repository}}:{{.Tag}}' "$image" 2>/dev/null)" ] } -bootstrap= -BootstrapOnly=1 -ComposerInstall= -ForcedBootstrap= -parse_opts=1 -args=() -for arg in "$@"; do - if [ -z "$parse_opts" ]; then - args+=("$arg") - elif [ "$arg" == --bootstrap -o "$arg" == --bs ]; then - bootstrap=1 - elif [ "$arg" == --exec ]; then - BootstrapOnly= - elif [ "$arg" == --composer-install -o "$arg" == --ci ]; then - ComposerInstall=1 - elif [[ "$arg" == -* ]]; then - args+=("$arg") - else - args+=("$arg") - parse_opts= - fi -done -set -- "${args[@]}" +## Arguments initiaux -if [ -z "$RUNPHP_STANDALONE" -a -z "$bootstrap" ]; then +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 @@ -137,27 +130,18 @@ if [ -z "$RUNPHP_STANDALONE" -a -z "$bootstrap" ]; then ForcedBootstrap=1 elif ! diff -q "$PROJDIR/$COMPOSERDIR/composer.lock" "$PROJDIR/.composer.lock.runphp" >&/dev/null; then ForcedBootstrap=1 - elif [ -n "$bootstrap" -a -n "$BootstrapOnly" ]; then - # bootstrap inutile - exit 0 fi - if [ -n "$ForcedBootstrap" ]; then - [ "$RUNPHP_MODE" != docker ] && eecho "== runphp is needed: bootstrapping" - bootstrap=1 - BootstrapOnly= + [ "$RUNPHP_MODE" != docker ] && eecho "== bootstrapping runphp" + Bootstrap=1 + ComposerInstall=1 fi fi if [ "$RUNPHP_MODE" != docker ]; then ############################################################################ # Lancement depuis l'extérieur du container - - # 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 + ############################################################################ ## Charger ~/.dkbuild.env @@ -204,7 +188,6 @@ if [ "$RUNPHP_MODE" != docker ]; then esac } [ -f ~/.dkbuild.env ] && source ~/.dkbuild.env - [ -n "$APT_PROXY" ] || APT_PROXY= [ -n "$APT_MIRROR" ] || APT_MIRROR=default [ -n "$SEC_MIRROR" ] || SEC_MIRROR=default @@ -212,6 +195,15 @@ if [ "$RUNPHP_MODE" != docker ]; then [ -n "$PRIVAREG" ] || PRIVAREG= [ -n "$REGISTRY" ] || REGISTRY=pubdocker.univ-reunion.fr + ## 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 @@ -223,8 +215,9 @@ if [ "$RUNPHP_MODE" != docker ]; then UseRslave=1 fi + # Toujours vérifier l'existence de l'image IMAGE= - if [ -z "$bootstrap" ]; then + if [ -z "$Bootstrap" ]; then if [ -n "$RUNPHP_FORCE_BUILDENVS" ]; then eval "Configs=($RUNPHP_FORCE_BUILDENVS)" for config in "${Configs[@]}"; do @@ -239,11 +232,14 @@ if [ "$RUNPHP_MODE" != docker ]; then after_source_buildenv fi ensure_image - check_image || bootstrap=1 + check_image || Bootstrap=1 fi - if [ -n "$bootstrap" ]; then + Chdir= + 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 @@ -254,8 +250,8 @@ if [ "$RUNPHP_MODE" != docker ]; then TIMEZONE ) - SOPTS=+d:9876543210:c:UjDx:z:r:pw:v - 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,chdir:,verbose,no-use-rslave + 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,no-use-rslave args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" Dist= @@ -272,8 +268,6 @@ if [ "$RUNPHP_MODE" != docker ]; then Pull= NoCache= PlainOutput= - Chdir= - Verbose= while [ $# -gt 0 ]; do case "$1" in --) shift; break;; @@ -282,7 +276,7 @@ if [ "$RUNPHP_MODE" != docker ]; then runphp: construire l'image docker USAGE - $MYNAME --bootstrap [options...] [--exec command [args...]] + $MYNAME --bootstrap [options...] OPTIONS -c, --config build.env @@ -294,11 +288,7 @@ OPTIONS -z, --timezone TIMEZONE -r, --privareg PRIVAREG -p, --push - paramètres pour la consruction de l'image - -w, --chdir CHDIR - aller dans le répertoire spécifié avant de lancer la commande - -v, --verbose - afficher plus d'informations" + paramètres pour la consruction de l'image" exit 0 ;; -d|--dist) shift; Dist="$1";; @@ -313,8 +303,6 @@ OPTIONS -z|--timezone) shift; TIMEZONE="$1";; -r|--privareg) shift; PRIVAREG="$1";; -p|--push) Push=1;; - -w|--chdir) shift; Chdir="$1";; - -v|--verbose) Verbose=1;; --no-use-rslave) UseRslave=;; *) die "$1: option non configurée";; esac @@ -334,14 +322,20 @@ OPTIONS 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" + if [ -n "$RUNPHP_STANDALONE" ]; then + DFDIR="$RUNPHP_STANDALONE" + else + DFDIR="$MYDIR" + fi dockerfiles=( - "$MYDIR/Dockerfile.runphp.local" - "$MYDIR/Dockerfile.runphp$BUILD_FLAVOUR" - "$MYDIR/Dockerfile.runphp" + "$DFDIR/Dockerfile.runphp.local" + "$DFDIR/Dockerfile.runphp$BUILD_FLAVOUR" + "$DFDIR/Dockerfile.runphp" ) for dockerfile in "${dockerfiles[@]}"; do [ -f "$dockerfile" ] && break @@ -370,21 +364,20 @@ OPTIONS docker push "$IMAGE" || exit 1 fi fi - if [ -n "$ComposerInstall" -a ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then - BootstrapOnly= - ForcedBootstrap=1 + 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 - [ -n "$BootstrapOnly" ] && exit 0 + [ -z "$ComposerInstall" ] && exit 0 else ## Mode exécution de commande ########################################## + # Ici, on a déterminé qu'il faut lancer une commande SOPTS=+w:v LOPTS=help,chdir:,verbose,no-use-rslave args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" - Chdir= - Verbose= while [ $# -gt 0 ]; do case "$1" in --) shift; break;; @@ -421,9 +414,9 @@ OPTIONS shift done - if [ -n "$ComposerInstall" -a ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then + if [ -z "$RUNPHP_STANDALONE" -a ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then # Forcer l'installation des dépendances si nécessaire - ForcedBootstrap=1 + ComposerInstall=1 fi fi @@ -478,6 +471,7 @@ OPTIONS else ############################################################################ # Lancement depuis l'intérieur du container + ############################################################################ if [ -n "$DEVUSER_USERENT" ]; then user="${DEVUSER_USERENT%%:*}" @@ -505,7 +499,9 @@ else shift done - if [ "$1" == ci ]; then + if [ -z "$1" ]; then + die "no command specified" + elif [ "$1" == ci ]; then eecho "== installing composer dependencies" composer i elif [ "$1" == cu ]; then @@ -517,6 +513,6 @@ else if [ -n "$chdir" ]; then cd "$chdir" || exit 1 fi - exec "${@:-bash}" + exec "$@" fi fi diff --git a/runphp/update.sh b/runphp/update-runphp.sh similarity index 100% rename from runphp/update.sh rename to runphp/update-runphp.sh