LibrePortal/scripts/docker/network/network_prune.sh
librelad a3afb2aeae feat(model-a): run app as manager; route bare docker calls through runFileOp
Model A prototype (run start.sh AS the manager, escalate only via helpers):
- check_root.sh: accept the manager user, not root-only (init.sh keeps its own
  install-time root check).
- init.sh: guard the top-level root-check + installer entrypoint with
  BASH_SOURCE!=$0 so it runs ONLY when init.sh is executed directly; when
  start.sh sources it as the manager the entrypoint (and its root check) no
  longer fires.

Also: convert bare daemon-touching 'docker' calls (no helper -> hit the
nonexistent /var/run socket in rootless) to runFileOp docker across
app_status, app_health_*, network_prune, ip_is_available, check_docker_network,
backup_db (db dumps) and crontab_check_processor. cd&&compose rooted-branches
and 'docker compose --version' checks left as-is (rooted-only / no daemon).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 16:53:37 +01:00

25 lines
958 B
Bash
Executable File

#!/bin/bash
dockerPruneAppNetworks()
{
if [[ $CFG_REQUIREMENT_DOCKER_NETWORK_PRUNE == "true" ]]; then
local app_name="$1"
if [ ! -z "$app_name" ]; then
local networks_found=false
# Prune all networks except those containing the specified app_name
for network_id in $(runFileOp docker network ls --quiet); do
network_name=$(runFileOp docker network inspect --format '{{.Name}}' "$network_id")
if [[ "$network_name" == *"$app_name"* ]]; then
local result=$(dockerCommandRun "docker network rm "$network_id"")
checkSuccess "Removing the unused runFileOp docker network - $network_name"
networks_found=true
fi
done
if [ "$networks_found" = false ]; then
isSuccessful "No unused networks found for $app_name"
fi
fi
fi
}