refactor(apps): modularize the gluetun providers generator via a per-app refresh hook

Move scripts/webui/data/generators/apps/webui_gluetun_providers.sh ->
containers/gluetun/scripts/gluetun_providers.sh and replace the gluetun-specific
gated call in webui_updater.sh with a generic per-app loop: an installed app may
define appWebuiRefresh_<app> (in its scripts/) for data it wants refreshed on
every WebUI update. gluetun provides appWebuiRefresh_gluetun (a thin wrapper over
webuiGenerateGluetunProviders).

- No gluetun-specific code remains in central WebUI code — it's a true drop-in.
- Install gate preserved + generalized: the loop iterates the manager-owned
  install templates (listable) and tests each app's live compose directly (works
  without list perm on the container-user data dir), so non-users never pay for it.
- webuiGenerateGluetunProviders keeps its name (still called by the installer and
  the gluetun_refresh_providers tool); now sourced via the container scan.
- Regenerate arrays (generator drops out of files_webui).

Loop verified with stubs: only installed apps with a defined hook fire; apps
without a hook are skipped; nothing fires when nothing's installed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
librelad 2026-05-25 23:44:42 +01:00
parent d4778126e4
commit 3e6bb565e0
3 changed files with 23 additions and 12 deletions

View File

@ -78,3 +78,11 @@ webuiGenerateGluetunProviders() {
isNotice "Empty gluetun snapshot generated; ignoring."
fi
}
# Routine WebUI-update hook (appWebuiRefresh_<app>): keep the provider snapshot
# fresh on every WebUI update while gluetun is installed. The installer
# (gluetun.sh) refreshes on first install and the 'gluetun_refresh_providers'
# tool refreshes on demand; this covers the in-between drift.
appWebuiRefresh_gluetun() {
webuiGenerateGluetunProviders
}

View File

@ -8,7 +8,6 @@ webui_scripts=(
"webui/data/generators/apps/webui_app_status.sh"
"webui/data/generators/apps/webui_config_patch.sh"
"webui/data/generators/apps/webui_config.sh"
"webui/data/generators/apps/webui_gluetun_providers.sh"
"webui/data/generators/apps/webui_services.sh"
"webui/data/generators/apps/webui_tools.sh"
"webui/data/generators/backup/webui_backup_app_status.sh"

View File

@ -69,17 +69,21 @@ webuiLibrePortalUpdate() {
local result=$(webuiGenerateAppsToolsConfig)
checkSuccess "Generated apps-tools.json..."
# Only refresh the gluetun provider snapshot when gluetun is
# actually deployed — the upstream servers.json is ~7 MB and
# routine WebUI updates shouldn't burn that bandwidth for users
# who never install gluetun. The gluetun installer itself
# (containers/gluetun/gluetun.sh) refreshes on first install,
# and the Tools action 'gluetun_refresh_providers' lets users
# refresh on demand.
if [[ -f "${containers_dir}gluetun/docker-compose.yml" ]]; then
local result=$(webuiGenerateGluetunProviders)
checkSuccess "Refreshed gluetun provider snapshot..."
fi
# Per-app routine refresh hooks. An installed app may define
# appWebuiRefresh_<app> (in containers/<app>/scripts/) for data it
# wants refreshed on every WebUI update — e.g. gluetun's provider
# snapshot. Gated on the app being installed (its live compose
# exists, tested directly so it works without list perm on the
# container-user-owned data dir), so non-users never pay for it.
local _app _dir _hook
for _dir in "${install_containers_dir}"*/; do
_app="$(basename "$_dir")"
[[ -f "${containers_dir}${_app}/docker-compose.yml" ]] || continue
_hook="appWebuiRefresh_${_app}"
declare -F "$_hook" >/dev/null 2>&1 || continue
local result=$($_hook)
checkSuccess "Refreshed ${_app} WebUI data..."
done
# Generate Backup locations / snapshots / engines / dashboards
local result=$(webuiGenerateBackupLocations && webuiGenerateBackupDashboard && webuiGenerateBackupSnapshots all && webuiGenerateBackupAppStatus && webuiGenerateBackupEngines && webuiGenerateBackupSchema && webuiGenerateBackupPasswords)