kas-docker: Allow passing multi-word variables into the container

This is complex, not just because we are passing the arguments to the
trace function, but already because they need to be protected in their
structure when unrolling them at the top level. The trick seems to be
using the argument list via set and "$@" to preserve the individual
words. Due to the trace indirection, we additionally need the single
quotes around the variable values.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2018-12-14 18:00:20 +01:00 committed by Daniel Wagner
parent ccc58c7010
commit 5a68998ba7

View File

@ -47,8 +47,8 @@ usage()
trace()
{
[ -n "${VERBOSE}" ] && echo "+ $*"
eval "$*"
[ -n "${VERBOSE}" ] && echo "+ ""$@"
eval "$@"
}
DOCKER_IMAGE=kasproject/kas
@ -178,13 +178,14 @@ if [ -n "${KAS_REPO_REF_DIR}" ]; then
-e KAS_REPO_REF_DIR=${KAS_REPO_REF_DIR}"
fi
set -- ${DOCKER_ARGS}
for var in SHELL TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK \
http_proxy https_proxy ftp_proxy no_proxy; do
if [ -n "$(eval echo \$${var})" ]; then
DOCKER_ARGS="${DOCKER_ARGS} \
-e $var=$(eval echo \$${var})"
set -- "$@" -e "${var}='$(eval echo \$${var})'"
fi
done
trace docker run ${DOCKER_ARGS} ${ISAR_ARGS} ${USER_ARGS} \
trace docker run "$@" ${ISAR_ARGS} ${USER_ARGS} \
${DOCKER_IMAGE} ${CMD} ${KAS_FILE}