Skip to content

Commit

Permalink
Merge pull request #286 from veraison/greg-bug2
Browse files Browse the repository at this point in the history
fix(docker): preserve command line argument quotes
  • Loading branch information
thomas-fossati authored Dec 10, 2024
2 parents 3095339 + 33e8633 commit 8811732
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
12 changes: 9 additions & 3 deletions deployments/docker/src/manager-dispatcher
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ function clear_logs() {
}

function cocli() {
local cmd="$_utils_dir/cocli $*"
local -a args
for arg in "$@"; do args+=("'$arg'"); done
local cmd="$_utils_dir/cocli ${args[@]}"
/bin/bash -c "$cmd"
}

function evcli() {
local cmd="$_utils_dir/evcli $*"
local -a args
for arg in "$@"; do args+=("'$arg'"); done
local cmd="$_utils_dir/evcli ${args[@]}"
/bin/bash -c "$cmd"
}

function pocli() {
local cmd="$_utils_dir/pocli $*"
local -a args
for arg in "$@"; do args+=("'$arg'"); done
local cmd="$_utils_dir/pocli ${args[@]}"
/bin/bash -c "$cmd"
}

Expand Down
42 changes: 28 additions & 14 deletions deployments/docker/veraison
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# SPDX-License-Identifier: Apache-2.0
set -eo pipefail

# We need to make this a global variable because bash functions cannot return
# arrays.
declare -a translated_args

function status() {
_check_installed jq

Expand Down Expand Up @@ -269,20 +273,26 @@ function kill_tmux_session() {
}

function cocli() {
local -r -a args=$(printf '"%s" ' "$@")
local -r -a translated_args=$(_translate_host_paths "${args[@]}")
local -a args
for arg in "$@"; do args+=("$arg"); done
# Note: calling _translated_host_paths sets translated_args
_translate_host_paths "${args[@]}"
manager cocli "${translated_args[@]}"
}

function evcli() {
local -r -a args=$(printf '"%s" ' "$@")
local -r -a translated_args=$(_translate_host_paths "${args[@]}")
local -a args
for arg in "$@"; do args+=("$arg"); done
# Note: calling _translated_host_paths sets translated_args
_translate_host_paths "${args[@]}"
manager evcli "${translated_args[@]}"
}

function pocli() {
local -r -a args=$(printf '"%s" ' "$@")
local -r -a translated_args=$(_translate_host_paths "${args[@]}")
local -a args
for arg in "$@"; do args+=("$arg"); done
# Note: calling _translated_host_paths sets translated_args
_translate_host_paths "${args[@]}"
manager pocli "${translated_args[@]}"
}

Expand Down Expand Up @@ -384,29 +394,33 @@ function _strip_color() {
echo "$*" | sed -r "s/$_bash_color//g"
}

# Note: this function manipulates the global variable "translated_args"
function _translate_host_paths() {
local -r split_args=$(echo "$@" | sed 's/=\// \//g')
local -a split_args
for arg in "$@"; do
split_args+=("$(echo "$arg" | sed 's/=\// \//g')")
done

for part in $split_args; do
translated_args=()

for part in "${split_args[@]}"; do
if [[ $part == /* ]]; then
local -r realpart=$(realpath -q "$part")
local realpart=$(realpath -q "$part")
if [[ "$OSTYPE" == "darwin"* ]]; then
# Terrible, horrible, no good, very bad CLUDGE for MocOS X:
# On MacOS, all top-level locations in the file system are in
# fact symlinks (or something) to locations under /host_mnt/.
# These do not get resolved by realpath, so we have to do it
# manually. Hopefully, this doesn't break for different MacOS
# versions...
ammended+=("${_host_root}/host_mnt$realpart")
translated_args+=("${_host_root}/host_mnt$realpart")
else
ammended+=("$_host_root$realpart")
translated_args+=("$_host_root$realpart")
fi
else
ammended+=("$part")
translated_args+=("$part")
fi
done

echo "${ammended[@]}";
}

_this_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down

0 comments on commit 8811732

Please sign in to comment.