From 13fcd0f51cd1fc87cd92260feb60736ee73ceb91 Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 5 Dec 2020 17:00:40 +1100 Subject: [PATCH] Tightened up how we handle volume paths when launching the Docker container. --- run-container.sh | 54 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/run-container.sh b/run-container.sh index 6aaaea8..4f68860 100755 --- a/run-container.sh +++ b/run-container.sh @@ -3,6 +3,28 @@ # --------------------------------------------------------------------- +function get_target { + local type=$1 + local target=$2 + + # check that the target exists + if [ "$type" == "FILE" ]; then + test -f "$target" || return + elif [ "$type" == "DIR" ]; then + test -d "$target" || return + elif [ "$type" == "FILE-OR-DIR" ]; then + ls "$target" >/dev/null 2>&1 || return + fi + + # convert the target to a full path + # FUDGE! I couldn't get the "docker run" command to work with spaces in the volume targets (although printing + # the command out, then copy-and-pasting it into the terminal worked fine) (and no, using ${var@Q} didn't help). + # So, the next best thing is to allow users to create symlinks to the targets :-/ + echo $(realpath --no-symlinks "$target" ) +} + +# --------------------------------------------------------------------- + function print_help { echo "`basename "$0"` {options}" cat </dev/null 2>&1 ; then + target=$( get_target FILE-OR-DIR "$TEMPLATE_PACK" ) + if [ -z "$target" ]; then echo "Can't find the template pack: $TEMPLATE_PACK" exit 1 fi mpoint=/data/template-pack - target=$( readlink -f "$TEMPLATE_PACK" ) TEMPLATE_PACK_VOLUME="--volume $target:$mpoint" TEMPLATE_PACK_ENV="--env DEFAULT_TEMPLATE_PACK=$mpoint --env DEFAULT_TEMPLATE_PACK_TARGET" fi