Fix deploy_service set -e exit swallowing errors in command substitution

Using 'if ! pct exec ... > tmp 2>&1' avoids the bash set -e + $()
interaction where the shell exits inside the subshell before || fires.
Errors are now captured to a temp file and printed via msg_error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-01 20:01:49 +00:00
parent 4fe4e30807
commit 8f5ae3af74

View file

@ -480,17 +480,21 @@ deploy_service() {
local id=$1 repo_name=$2 local_src=$3 dest=$4 local id=$1 repo_name=$2 local_src=$3 dest=$4
if [[ "$USE_FORGEJO" == "true" ]]; then if [[ "$USE_FORGEJO" == "true" ]]; then
local url; url=$(build_clone_url "$repo_name") local url; url=$(build_clone_url "$repo_name")
local out local tmp; tmp=$(mktemp /tmp/hotel-manage-deploy-out-XXXX)
out=$(pct exec "$id" -- bash -c " if ! pct exec "$id" -- bash -c "
if [ -d '${dest}/.git' ]; then if [ -d '${dest}/.git' ]; then
cd '${dest}' && git pull 2>&1 cd '${dest}' && git pull
else else
git clone '${url}' '${dest}' 2>&1 git clone '${url}' '${dest}'
fi fi
" 2>&1) || msg_error "Deploy of ${repo_name} to LXC ${id} failed: " > "$tmp" 2>&1; then
local out; out=$(cat "$tmp"); rm -f "$tmp"
msg_error "Deploy of ${repo_name} to LXC ${id} failed:
${out} ${out}
Debug: pct enter ${id} && git clone ${url//oauth2:*@/} /tmp/test-clone" Debug: pct enter ${id} && git clone ${FORGEJO_BASE}/${repo_name}.git /tmp/test-clone"
fi
rm -f "$tmp"
else else
push_dir "$id" "$local_src" "$dest" push_dir "$id" "$local_src" "$dest"
fi fi