From 2adaaf5d1e00c72371901a03e8b01d261850da93 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 19 Sep 2024 21:53:19 +0400 Subject: [PATCH] support _rundk --- runphp/build | 12 ++++++++++++ runphp/dot-build.env.dist | 3 +++ runphp/runphp.2postamble | 28 +++++++++------------------- runphp/template.sh | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/runphp/build b/runphp/build index 721940a..863e807 100755 --- a/runphp/build +++ b/runphp/build @@ -59,6 +59,18 @@ function build_check_env() { template_process_userfiles if [ -n "$updated" ]; then + setx user=id -un + setx userent=getent passwd "$user" + setx userent=qval "$userent" + setx groupent=getent group "$(id -gn)" + setx groupent=qval "$groupent" + sed -i " +s/^#_RUNDK_/_RUNDK_/ +s/^_RUNDK_USER=.*/_RUNDK_USER=${user//\//\\\/}/ +s/^_RUNDK_USERENT=.*/_RUNDK_USERENT=${userent//\//\\\/}/ +s/^_RUNDK_GROUPENT=.*/_RUNDK_GROUPENT=${groupent//\//\\\/}/ +" "$PROJDIR/$BUILDENV" + enote "IMPORTANT: Veuillez faire le paramétrage en éditant le fichier $BUILDENV ${EDITOR:-nano} $BUILDENV ENSUITE, vous pourrez relancer la commande" diff --git a/runphp/dot-build.env.dist b/runphp/dot-build.env.dist index a347ec7..725d233 100644 --- a/runphp/dot-build.env.dist +++ b/runphp/dot-build.env.dist @@ -17,3 +17,6 @@ PRIVAREG= REGISTRY=pubdocker.univ-reunion.fr DIST=d12 IMAGENAME=runphp +#_RUNDK_USER=user +#_RUNDK_USERENT=user:x:1000:1000:User,,,:/home/user:/bin/bash +#_RUNDK_GROUPENT=user:x:1000: diff --git a/runphp/runphp.2postamble b/runphp/runphp.2postamble index 53ed5a2..858253e 100644 --- a/runphp/runphp.2postamble +++ b/runphp/runphp.2postamble @@ -175,9 +175,9 @@ if [ -z "$_RUNDK_IN_DOCKER" ]; then ## Construire l'image - if [ -n "$RUNDK_NO_USE_RSLAVE" ]; then + if [ -n "$RUNPHP_NO_USE_RSLAVE" ]; then UseRslave= - elif [ -n "$RUNDK_USE_RSLAVE" ]; then + elif [ -n "$RUNPHP_USE_RSLAVE" ]; then UseRslave=1 elif [ -e /proc/sys/fs/binfmt_misc/WSLInterop ]; then # pas de mount propagation sous WSL @@ -188,8 +188,8 @@ if [ -z "$_RUNDK_IN_DOCKER" ]; then IMAGE= if [ -z "$bootstrap" ]; then - if [ -n "$RUNDK_FORCE_BUILDENVS" ]; then - eval "Configs=($RUNDK_FORCE_BUILDENVS)" + if [ -n "$RUNPHP_FORCE_BUILDENVS" ]; then + eval "Configs=($RUNPHP_FORCE_BUILDENVS)" for config in "${Configs[@]}"; do source "$config" || exit 1 done @@ -225,8 +225,8 @@ if [ -z "$_RUNDK_IN_DOCKER" ]; then args="$(getopt -n "$MYNAME" -o "$SOPTS" -l "$LOPTS" -- "$@")" || exit 1; eval "set -- $args" Dist= - if [ -n "$RUNDK_FORCE_BUILDENVS" ]; then - eval "Configs=($RUNDK_FORCE_BUILDENVS)" + 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 @@ -356,7 +356,7 @@ OPTIONS --) shift; break;; --help) eecho "\ -runphp: construire l'image docker +runphp: lancer une commande dans docker USAGE $MYNAME ci|cu|composer @@ -388,20 +388,17 @@ OPTIONS done if [ -n "$ComposerInstall" -a ! -f "$PROJDIR/$VENDORDIR/nulib/php/load.sh" ]; then + # Forcer l'installation des dépendances si nécessaire ForcedBootstrap=1 fi fi ## Lancer la commande - uid="$(id -u)" - gid="$(id -g)" args=( run -it --rm --name "runphp-$(basename -- "$1")-$$" -e _RUNDK_IN_DOCKER=1 - -e _RUNDK_UID="$uid" - -e _RUNDK_GID="$gid" ) for arg in "${!PROXY_VARS[@]}"; do args+=(--e "$arg=${PROXY_VARS[$arg]}") @@ -427,7 +424,7 @@ OPTIONS args+=(-w "$(pwd)") # lancer avec l'utilisateur courant - if [ $uid -ne 0 ]; then + 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 user="$(id -un)" @@ -453,13 +450,6 @@ else ############################################################################ # Lancement depuis l'intérieur du container - # Ajouter les informations utilisateur le cas échéant - if [ -n "$_RUNDK_USERENT" ]; then - grep -q "^$_RUNDK_USER:" /etc/passwd || echo "$_RUNDK_USERENT" >>/etc/passwd - fi - if [ -n "$_RUNDK_GROUPENT" ]; then - grep -q "^$_RUNDK_GROUP:" /etc/group || echo "$_RUNDK_GROUPENT" >>/etc/group - fi if [ -n "$_RUNDK_USER" ]; then user="$_RUNDK_USER" export _RUNDK_USER= diff --git a/runphp/template.sh b/runphp/template.sh index 233c527..c836bca 100755 --- a/runphp/template.sh +++ b/runphp/template.sh @@ -5,7 +5,7 @@ RUNPHP=sbin/runphp MYDIR="$(dirname -- "$0")"; MYNAME="$(basename -- "$0")" -if [ -z "$_RUNPHP_IN_DOCKER" ]; then +if [ -z "$_RUNDK_IN_DOCKER" ]; then "$MYDIR/$RUNPHP" --bs --ue --ci || exit 1 exec "$MYDIR/$RUNPHP" "$0" "$@" fi