Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docker): preserve command line argument quotes #286

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading