The main sweep — ~260 call sites across ~100 files move from string
concatenation on a single root to appDir/storageAppDirs/storageAppConfigs.
On a single-root install the resolved paths are identical, so this is a
no-op until a location is registered.
Enumerators were the interesting half. `for d in "$containers_dir"/*/`
appears in the menus, the registry/artifact scanners and the DNS setup —
and a shell glob cannot list a rootless 751 tree at all, which is the
same bug config_find_file.sh already documents in a comment. Routing them
through storageAppDirs (which enumerates as the owning user) fixes that
alongside the multi-root work.
Three places needed judgement rather than substitution:
db_app_scan.sh deletes database rows and port allocations for apps whose
folder is missing, and reaps "empty" app dirs. With a storage location
unmounted, every app on it looks exactly like that. Each of those
branches now gates on appStorageAvailable first — an app on an unplugged
drive is skipped with a notice, never deleted.
instance_create.sh rewrites cloned hooks so an instance touches its own
directory instead of the base app's. Its sed matched ${containers_dir}<type>,
which this sweep just replaced with $(appDir <type>) — so it would have
silently stopped redirecting, and an instance would have written to the
original's files (the adguard auth adapter case its own comment warns
about). Now matches both appDir forms, verified against bare, quoted,
unrelated-app, legacy and prose cases.
peer_shell/peer_pull streamed and extracted relative to the primary root.
Both now use the app's own root, and peer_shell keeps a single-root
fallback since it runs as a restricted SSH shell with no LibrePortal env.
Also fixes a pre-existing bug found on the way: webui_app_config.sh
tested "$containers_dir/frontend/data/last_update", one level short of the
real tree under the libreportal app dir, so the WebUI refresh trigger
after a config update has never once fired.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
100 lines
4.0 KiB
Bash
100 lines
4.0 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="$(webuiDir)/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=()
|
|
local app # local: bash is dynamically scoped, and a while-read loop
|
|
# leaves an undeclared name EMPTY in the CALLER's scope at EOF.
|
|
while IFS= read -r app; do
|
|
[[ -z "$app" ]] && continue
|
|
local cfg_file="$(appDir "$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="$(appDir "$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="$(appDir "$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
|
|
}
|