LibrePortal/containers/gluetun/scripts/gluetun_route_apps.sh
librelad 98e1a0a05d refactor(apps): per-app post-install hooks + move gluetun/crowdsec logic into their apps
Replace the central app-name if-ladder in app_update_specifics.sh with a generic
dispatcher: each app ships containers/<app>/scripts/<app>_update_specifics.sh
defining appUpdateSpecifics_<app> (live-sourced by the container scan, dispatched
by `declare -F` — same pattern as tools). A hook may set shouldrestart=true. Apps
with no specifics ship no hook.

- Move the adguard/pihole (DNS updater), dashy (conf refresh), focalboard (nobody
  ownership + restart), and libreportal (webui regen) branches to per-app hooks.
- Move scripts/gluetun/gluetun_route_apps.sh -> containers/gluetun/scripts/
  (scripts/gluetun/ removed).
- Move scripts/install/install_crowdsec.sh -> containers/crowdsec/scripts/
  crowdsec_install_host.sh; fix the path note in crowdsec.sh.
- Regenerate arrays (moved files drop out; the per-app files are container-scanned,
  not arrayed).

Dispatch verified with stubs: adguard/pihole/dashy/focalboard/libreportal behave
identically to the old ladder (incl. shouldrestart propagation), apps without a
hook are a clean no-op. The CLI itself had no per-app branches — app-specific CLI
is already the (now fully modular) tools system.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-25 23:38:19 +01:00

98 lines
3.8 KiB
Bash

#!/bin/bash
# Walks installed apps and offers to flip CFG_<APP>_NETWORK to gluetun for each
# eligible one. Honors the curated category list + CFG_REQUIREMENT_GLUETUN_FOR_ALL
# override flag. Skips itself, Traefik, LibrePortal, fail2ban.
gluetunRouteExistingAppsPrompt()
{
local categories_file="${containers_dir}libreportal/frontend/data/apps/gluetun-eligible-categories.json"
local override="${CFG_REQUIREMENT_GLUETUN_FOR_ALL:-false}"
if ! command -v sqlite3 >/dev/null 2>&1 || [[ ! -f "$docker_dir/$db_file" ]]; then
isNotice "Database not available; skipping per-app routing prompt."
return 0
fi
local allow_csv=""
if [[ -f "$categories_file" ]] && command -v jq >/dev/null 2>&1; then
allow_csv=$(jq -r '.categories | join(",")' "$categories_file" 2>/dev/null | tr '[:upper:]' '[:lower:]')
fi
local installed
installed=$(runInstallOp sqlite3 "$docker_dir/$db_file" \
"SELECT name FROM apps WHERE status = 1 AND name NOT IN ('gluetun','libreportal','traefik','fail2ban') ORDER BY name;" 2>/dev/null)
if [[ -z "$installed" ]]; then
isNotice "No other apps installed yet. Skipping."
return 0
fi
local eligible=()
while IFS= read -r app; do
[[ -z "$app" ]] && continue
local cfg_file="${containers_dir}${app}/${app}.config"
[[ -f "$cfg_file" ]] || continue
local category
category=$(grep -E "^CFG_${app^^}_CATEGORY=" "$cfg_file" 2>/dev/null \
| head -1 | cut -d'=' -f2 | tr -d '"' | tr '[:upper:]' '[:lower:]')
local is_eligible="false"
if [[ "$override" == "true" ]]; then
is_eligible="true"
elif [[ -n "$allow_csv" ]]; then
IFS=',' read -ra cats <<< "$allow_csv"
for c in "${cats[@]}"; do
if [[ "$c" == "$category" ]]; then is_eligible="true"; break; fi
done
fi
[[ "$is_eligible" == "true" ]] && eligible+=("$app")
done <<< "$installed"
if [[ ${#eligible[@]} -eq 0 ]]; then
isNotice "No eligible installed apps. (Enable CFG_REQUIREMENT_GLUETUN_FOR_ALL to expose every app.)"
return 0
fi
echo " The following installed apps can be routed through Gluetun:"
for app in "${eligible[@]}"; do
local cfg_file="${containers_dir}${app}/${app}.config"
local current
current=$(grep -E "^CFG_${app^^}_NETWORK=" "$cfg_file" 2>/dev/null | head -1 | cut -d'=' -f2)
[[ -z "$current" ]] && current="default"
echo " - ${app} (current: ${current})"
done
echo ""
isQuestion "Apply gluetun routing now? Tick each app to flip. (y/N): "
local resp
read -rp "" resp
echo ""
case "$resp" in
[yY]*) ;;
*) isNotice "Skipped. You can apply later via the WebUI gluetun page or per-app config."; return 0 ;;
esac
for app in "${eligible[@]}"; do
local cfg_file="${containers_dir}${app}/${app}.config"
local current
current=$(grep -E "^CFG_${app^^}_NETWORK=" "$cfg_file" 2>/dev/null | head -1 | cut -d'=' -f2)
[[ -z "$current" ]] && current="default"
isQuestion " Route '$app' through gluetun? (current: $current) [y/n/skip]: "
local r
read -rp "" r
case "$r" in
[yY]*)
updateConfigOption "CFG_${app^^}_NETWORK" "gluetun" "$cfg_file"
isSuccessful " Set CFG_${app^^}_NETWORK=gluetun. Re-running install for $app..."
dockerInstallApp "$app"
;;
[nN]*)
if [[ "$current" == "gluetun" ]]; then
updateConfigOption "CFG_${app^^}_NETWORK" "default" "$cfg_file"
isSuccessful " Reverted $app to default network. Re-running install..."
dockerInstallApp "$app"
fi
;;
*) ;;
esac
done
}