dk: rendre le code overridable

This commit is contained in:
Jephté Clain 2019-10-03 19:20:32 +04:00
parent aae3703558
commit 269379f3a2
1 changed files with 64 additions and 54 deletions

74
dk
View File

@ -1231,24 +1231,7 @@ EOF
local_run "$HOST" "$tmpscript" local_run "$HOST" "$tmpscript"
} }
function auto_composer() { function default_local_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 # lancement direct
case "$1" in case "$1" in
rootshell|shell|rootbash|bash) rootshell|shell|rootbash|bash)
@ -1271,21 +1254,9 @@ function auto_composer() {
"$COMPOSER_CMD" "$@" "$COMPOSER_CMD" "$@"
;; ;;
esac 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_docker_composer() {
fi # lancement dans un container
fi
local user group projdir actualcmd args local user group projdir actualcmd args
setx user=id -un; setx user=getent passwd "$user" setx user=id -un; setx user=getent passwd "$user"
setx group=id -gn; setx group=getent group "$group" setx group=id -gn; setx group=getent group "$group"
@ -1375,6 +1346,45 @@ fi
) )
"${cmd[@]}" "${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
}
################################################################################ ################################################################################