From 63d1a87a6cf78c688170715ecdfd87ccaf7c2fec Mon Sep 17 00:00:00 2001 From: Stefan Dinescu Date: Thu, 24 Oct 2019 13:19:16 +0300 Subject: [PATCH] Allow forcing shell prompt option Some commands are designed to leave you in a shell prompt once executed, but it is hard to identify all such commands in the context of remote CLI. In order to allow users to use such commands, they can force the shell option or force disable the shell options using the FORCE_SHELL and FORCE_NO_SHELL variables before the command. The README has been updated with examples on the use of these variables Change-Id: Ica4e155fa21067448b99c4309f4736d39f0a419d Closes-bug: 1849505 Signed-off-by: Stefan Dinescu --- remote_cli/README | 12 ++++++++++++ remote_cli/client_wrapper.sh | 27 +++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/remote_cli/README b/remote_cli/README index 8d963f6..207a620 100644 --- a/remote_cli/README +++ b/remote_cli/README @@ -137,3 +137,15 @@ kubectl config --kubeconfig ${OUTPUT_FILE} use-context stxcluster-default 2. openstack image create --disk-format qcow2 --container-format bare \ --public --file /wd/centos63.qcow2 centos63-image + +7. Some commands used by remote CLI are designed to leave you in a shell prompt. + Examples of such commands are "openstack" or "kubectl exec -ti + -- /bin/bash". There are cases where the mechanism for identifying commands + that should leave you in a shell prompt is not identifying them correctly. + If users encounter such scenarios, they can force the shell or force disable + the shell options using the FORCE_SHELL or FORCE_NO_SHELL variables before + the command. You cannot use both variables at the same time. + + Examples: + - force shell: FORCE_SHELL=true kubectl exec -ti -- /bin/bash + - disable shell: FORCE_NO_SHELL=true kubectl exec -- ls diff --git a/remote_cli/client_wrapper.sh b/remote_cli/client_wrapper.sh index 6374292..521b230 100755 --- a/remote_cli/client_wrapper.sh +++ b/remote_cli/client_wrapper.sh @@ -35,8 +35,27 @@ for exp in $EXPORTS; do fi done -if [ -z "$2" ]; then - exec docker run -ti ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@" -else - exec docker run -t ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@" +if [[ -z "$FORCE_SHELL" ]] || [[ "$FORCE_SHELL" != "true" ]]; then + FORCE_SHELL="false" +fi + +if [[ -z "$FORCE_NO_SHELL" ]] || [[ "$FORCE_NO_SHELL" != "true" ]]; then + FORCE_NO_SHELL="false" +fi + +if [[ "$FORCE_SHELL" == "true" ]] && [[ "$FORCE_NO_SHELL" == "true" ]]; then + echo "Error: cannot set both FORCE_SHELLL and FORCE_NO_SHELL variables at the same time". + echo "Unset one of them and re-run the command" + exit 1 +fi + + +if [[ "$FORCE_SHELL" == "true" ]]; then + exec docker run --rm -ti ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@" +elif [[ "$FORCE_NO_SHELL" == "true" ]]; then + exec docker run --rm -t ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@" +elif [ -z "$2" ]; then + exec docker run --rm -ti ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@" +else + exec docker run --rm -t ${COMMAND_ENV} ${VOLUME_LIST} --workdir /wd ${CLIENT_IMAGE_NAME} "$@" fi