LibrePortal/scripts/cli/commands/system/cli_system_commands.sh
librelad 3031c6cab9 feat(system): "Reclaim space" action on the Storage page
Adds a `libreportal system reclaim` CLI command and an orange "Reclaim
space" button on /admin/config/system/storage (the v2 prune control the
page always hinted at).

Scope is deliberately SAFE: build cache + dangling (untagged) images
only (docker builder prune -f + docker image prune -f via the
rootless-aware runFileOp). It never touches volumes (app data) or
tagged/in-use images, so nothing an app relies on is removed.

Wiring mirrors system_update: a systemReclaim() action + system_reclaim
route case run the command verbatim through the task processor. The
button confirms via showConfirmation, shows a spinner, and re-reads
storage usage as the prune lands. Button styled with --status-warning to
match the Reclaimable stat it sits under, with a note clarifying scope.

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-28 18:50:27 +01:00

54 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# System Commands Handler
# Handles all system subcommands by calling core functions
# Reclaim Docker disk space — SAFE scope only: build cache + dangling
# (untagged) images. Never prunes volumes (app data) or tagged/in-use images,
# so nothing an app relies on is removed. runFileOp targets the correct daemon
# (rootless: as the install user with DOCKER_HOST set).
reclaimDockerSpace()
{
isHeader "Reclaiming Docker Space"
isNotice "Safe scope: build cache + dangling images only (no volumes, no in-use images)."
local cache_out image_out
cache_out=$(runFileOp docker builder prune -f 2>&1)
checkSuccess "Pruned build cache"
echo "$cache_out" | grep -i "Total:" | sed 's/^/ /'
image_out=$(runFileOp docker image prune -f 2>&1)
checkSuccess "Pruned dangling images"
echo "$image_out" | grep -i "Total reclaimed space" | sed 's/^/ /'
isSuccessful "Reclaim complete"
}
cliHandleSystemCommands()
{
local action="$initial_command2"
case "$action" in
"status")
tagsValidateShowSystemStatus
;;
"update")
checkUpdates
;;
"reset")
runReinstall
;;
"reclaim")
reclaimDockerSpace
;;
*)
isNotice "Invalid system command: $action"
cliShowSystemHelp
;;
esac
}