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

118
dk
View File

@ -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
}
################################################################################