fix(docker): support Bash 3.2 in docker-setup.sh (#9441)

* fix(docker): use Bash 3.2-compatible upsert_env in docker-setup.sh

* refactor(docker): simplify argument handling in write_extra_compose function

* fix(docker): add bash 3.2 regression coverage (#9441) (thanks @mateusz-michalik)

---------

Co-authored-by: Sebastian <19554889+sebslight@users.noreply.github.com>
This commit is contained in:
Mateusz Michalik
2026-02-11 01:55:43 +11:00
committed by GitHub
parent 2914cb1d48
commit 6731c6a1cd
3 changed files with 122 additions and 81 deletions

View File

@@ -56,7 +56,6 @@ COMPOSE_ARGS=()
write_extra_compose() {
local home_volume="$1"
shift
local -a mounts=("$@")
local mount
cat >"$EXTRA_COMPOSE_FILE" <<'YAML'
@@ -71,7 +70,7 @@ YAML
printf ' - %s:/home/node/.openclaw/workspace\n' "$OPENCLAW_WORKSPACE_DIR" >>"$EXTRA_COMPOSE_FILE"
fi
for mount in "${mounts[@]}"; do
for mount in "$@"; do
printf ' - %s\n' "$mount" >>"$EXTRA_COMPOSE_FILE"
done
@@ -86,7 +85,7 @@ YAML
printf ' - %s:/home/node/.openclaw/workspace\n' "$OPENCLAW_WORKSPACE_DIR" >>"$EXTRA_COMPOSE_FILE"
fi
for mount in "${mounts[@]}"; do
for mount in "$@"; do
printf ' - %s\n' "$mount" >>"$EXTRA_COMPOSE_FILE"
done
@@ -111,7 +110,12 @@ if [[ -n "$EXTRA_MOUNTS" ]]; then
fi
if [[ -n "$HOME_VOLUME_NAME" || ${#VALID_MOUNTS[@]} -gt 0 ]]; then
write_extra_compose "$HOME_VOLUME_NAME" "${VALID_MOUNTS[@]}"
# Bash 3.2 + nounset treats "${array[@]}" on an empty array as unbound.
if [[ ${#VALID_MOUNTS[@]} -gt 0 ]]; then
write_extra_compose "$HOME_VOLUME_NAME" "${VALID_MOUNTS[@]}"
else
write_extra_compose "$HOME_VOLUME_NAME"
fi
COMPOSE_FILES+=("$EXTRA_COMPOSE_FILE")
fi
for compose_file in "${COMPOSE_FILES[@]}"; do
@@ -129,7 +133,9 @@ upsert_env() {
local -a keys=("$@")
local tmp
tmp="$(mktemp)"
declare -A seen=()
# Use a delimited string instead of an associative array so the script
# works with Bash 3.2 (macOS default) which lacks `declare -A`.
local seen=" "
if [[ -f "$file" ]]; then
while IFS= read -r line || [[ -n "$line" ]]; do
@@ -138,7 +144,7 @@ upsert_env() {
for k in "${keys[@]}"; do
if [[ "$key" == "$k" ]]; then
printf '%s=%s\n' "$k" "${!k-}" >>"$tmp"
seen["$k"]=1
seen="$seen$k "
replaced=true
break
fi
@@ -150,7 +156,7 @@ upsert_env() {
fi
for k in "${keys[@]}"; do
if [[ -z "${seen[$k]:-}" ]]; then
if [[ "$seen" != *" $k "* ]]; then
printf '%s=%s\n' "$k" "${!k-}" >>"$tmp"
fi
done