'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>
40 lines
1.4 KiB
Bash
40 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
dockerRemoveAppImages()
|
|
{
|
|
local app_name="$1"
|
|
|
|
if [[ -z "$app_name" ]]; then
|
|
isNotice "No app name provided. Unable to remove Docker images."
|
|
return
|
|
fi
|
|
|
|
isNotice "Removing Docker images for '$app_name'. Please wait..."
|
|
|
|
local compose_dir="$containers_dir$app_name"
|
|
local compose_file="$compose_dir/docker-compose.yml"
|
|
local compose_images=""
|
|
|
|
if [[ -f "$compose_file" ]]; then
|
|
if [[ $CFG_DOCKER_INSTALL_TYPE == "rootless" ]]; then
|
|
compose_images=$(dockerCommandRunInstallUser "cd $compose_dir && docker compose config --images" 2>/dev/null)
|
|
elif [[ $CFG_DOCKER_INSTALL_TYPE == "rooted" ]]; then
|
|
compose_images=$(cd "$compose_dir" && docker compose config --images 2>/dev/null)
|
|
fi
|
|
fi
|
|
|
|
local matched_images=$(dockerCommandRun "docker images --format '{{.Repository}}:{{.Tag}}' | grep -E '(^|/)${app_name}(-|_|:|$)'" 2>/dev/null)
|
|
|
|
local all_images=$(printf "%s\n%s\n" "$compose_images" "$matched_images" | sort -u | grep -v '^$' | grep -v '<none>')
|
|
|
|
if [[ -z "$all_images" ]]; then
|
|
isNotice "No Docker images found for '$app_name'."
|
|
return
|
|
fi
|
|
|
|
while IFS= read -r image; do
|
|
local result; result=$(dockerCommandRun "docker rmi -f '$image'" >/dev/null 2>&1)
|
|
checkSuccess "Removed Docker image '$image'"
|
|
done <<< "$all_images"
|
|
}
|