librelad 053a620e22 fix(reliability): split local result=$(cmd) so $? survives for checkSuccess
'local result=$(cmd)' resets $? to 0 (the local builtin's own exit), so the
following checkSuccess always saw success regardless of cmd's real exit — the
mechanism that masked the de-sudo write failures. Split declaration from
assignment ('local result; result=$(cmd)') across all 235 active-code sites
(84 files) so the command's exit reaches checkSuccess. No behaviour change
beyond $? now being accurate (no set -e in runtime code; multi-line
assignments transform safely).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-31 03:09:25 +01:00

56 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
dockerComposeDown()
{
local app_name="$1"
local custom_compose="$2"
local type="$3"
if [[ "$app_name" == "" ]]; then
isError "Something went wrong...No app name provided..."
fi
isHeader "Docker Compose down $app_name"
# Make sure we are able to get the compose file
if [[ $compose_setup == "" ]]; then
setupBasicScanVariables "$app_name"
fi
# Compose file public variable for restarting etc
if [[ $compose_setup == "default" ]]; then
local setup_compose="-f docker-compose.yml"
local compose_file="docker-compose.yml"
elif [[ $compose_setup == "app" ]]; then
local setup_compose="-f docker-compose.yml -f docker-compose.$app_name.yml"
local compose_file="docker-compose.$app_name.yml"
fi
if [[ $custom_compose != "" ]]; then
local setup_compose="-f docker-compose.yml -f $custom_compose"
local compose_file="$custom_compose"
fi
if [[ "$OS_TYPE" == "Ubuntu" || "$OS_TYPE" == "Debian" ]]; then
if [ ! -f "$containers_dir$app_name/$compose_file" ]; then
isNotice "Unable to find the compose file to docker compose down this application."
return 1
fi
# Explicit type arg (CLI dockertype switcher) wins, otherwise the
# configured install type. Every branch ends in a status line so the
# header is never left without output.
local mode="${type:-$CFG_DOCKER_INSTALL_TYPE}"
if [[ $mode == "rootless" ]]; then
local result; result=$(dockerCommandRunInstallUser "cd $containers_dir$app_name && docker compose $setup_compose down" >/dev/null 2>&1)
checkSuccess "Shutting down container for $app_name"
elif [[ $mode == "rooted" ]]; then
local result; result=$(cd "$containers_dir$app_name" && docker compose $setup_compose down >/dev/null 2>&1)
checkSuccess "Shutting down container for $app_name"
else
isNotice "Unknown Docker install type '$mode' — cannot shut down $app_name."
fi
else
isNotice "Unsupported OS '$OS_TYPE' — cannot shut down $app_name."
fi
}