From 269379f3a2f59274c16cf5d064b967f9984ff39a Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 3 Oct 2019 19:20:32 +0400 Subject: [PATCH] dk: rendre le code overridable --- dk | 118 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 54 deletions(-) diff --git a/dk b/dk index 66042d7..08b53ab 100755 --- a/dk +++ b/dk @@ -1231,61 +1231,32 @@ EOF local_run "$HOST" "$tmpscript" } -function auto_composer() { - local COMPOSER_IMAGE="$DEFAULT_COMPOSER_IMAGE" - local COMPOSER_MACHINE=-u - local COMPOSER_CMD= - local COMPOSER_SETUP= - [ -f .composer.conf ] && source ./.composer.conf - # les premiers arguments peuvent service à redéfinir les variables - while [ $# -gt 0 ]; do - case "$1" in - COMPOSER_IMAGE=*) setv "$1"; shift;; - COMPOSER_MACHINE=*) setv "$1"; shift;; - COMPOSER_CMD=*) setv "$1"; shift;; - COMPOSER_SETUP=*) setv "$1"; shift;; - *) break;; - esac - done - - if [ "$COMPOSER_IMAGE" == none ]; then - # lancement direct - case "$1" in - rootshell|shell|rootbash|bash) - # ewarn parce qu'on est pas root dans ce shell contrairement à ce qui est demandé - ewarn "Lancement d'un shell utilisateur" - bash "$@" - ;; - usershell|ushell|userbash|ubash) - estep "Lancement d'un shell utilisateur" - bash "$@" - ;; - *) - if [ -n "$COMPOSER_CMD" ]; then : - elif [ -x composer.phar ]; then COMPOSER_CMD=./composer.phar - elif [ -x /usr/bin/composer ]; then COMPOSER_CMD=/usr/bin/composer - else - eerror "Impossible de trouver composer" - return 1 - fi - "$COMPOSER_CMD" "$@" - ;; - esac - return $? - fi - - if [ -n "$COMPOSER_MACHINE" -a "$DOCKER_MACHINE_NAME" != "$COMPOSER_MACHINE" ]; then - local -x DOCKER_TLS_VERIFY= DOCKER_HOST= DOCKER_CERT_PATH= DOCKER_MACHINE_NAME= - if [ "$COMPOSER_MACHINE" != -u ]; then - local env - setx env=docker-machine env "$COMPOSER_MACHINE" 2>/dev/null || { - eerror "$COMPOSER_MACHINE: une erreur s'est produite lors de la sélection du noeud avec docker-machine" - return 1 - } - eval "$env" +function default_local_composer() { + # lancement direct + case "$1" in + rootshell|shell|rootbash|bash) + # ewarn parce qu'on est pas root dans ce shell contrairement à ce qui est demandé + ewarn "Lancement d'un shell utilisateur" + bash "$@" + ;; + usershell|ushell|userbash|ubash) + estep "Lancement d'un shell utilisateur" + bash "$@" + ;; + *) + if [ -n "$COMPOSER_CMD" ]; then : + elif [ -x composer.phar ]; then COMPOSER_CMD=./composer.phar + elif [ -x /usr/bin/composer ]; then COMPOSER_CMD=/usr/bin/composer + else + eerror "Impossible de trouver composer" + return 1 fi - fi - + "$COMPOSER_CMD" "$@" + ;; + esac +} +function default_docker_composer() { + # lancement dans un container local user group projdir actualcmd args setx user=id -un; setx user=getent passwd "$user" setx group=id -gn; setx group=getent group "$group" @@ -1375,6 +1346,45 @@ fi ) "${cmd[@]}" } +function local_composer() { default_local_composer "$@"; } +function docker_composer() { default_docker_composer "$@"; } +function auto_composer() { + local COMPOSER_IMAGE="$DEFAULT_COMPOSER_IMAGE" + local COMPOSER_MACHINE=-u + local COMPOSER_CMD= + local COMPOSER_SETUP= + [ -f .composer.conf ] && source ./.composer.conf + # les premiers arguments peuvent service à redéfinir les variables + while [ $# -gt 0 ]; do + case "$1" in + COMPOSER_IMAGE=*) setv "$1"; shift;; + COMPOSER_MACHINE=*) setv "$1"; shift;; + COMPOSER_CMD=*) setv "$1"; shift;; + COMPOSER_SETUP=*) setv "$1"; shift;; + *) break;; + esac + done + + if [ "$COMPOSER_IMAGE" == none ]; then + local_composer "$@" + + else + local PREVIOUS_DOCKER_MACHINE_NAME="$DOCKER_MACHINE_NAME" + if [ -n "$COMPOSER_MACHINE" -a "$DOCKER_MACHINE_NAME" != "$COMPOSER_MACHINE" ]; then + local -x DOCKER_TLS_VERIFY= DOCKER_HOST= DOCKER_CERT_PATH= DOCKER_MACHINE_NAME= + if [ "$COMPOSER_MACHINE" != -u ]; then + local env + setx env=docker-machine env "$COMPOSER_MACHINE" 2>/dev/null || { + eerror "$COMPOSER_MACHINE: une erreur s'est produite lors de la sélection du noeud avec docker-machine" + return 1 + } + eval "$env" + fi + fi + + docker_composer "$@" + fi +} ################################################################################