From 3e6bb565e033606cb328a00a17797538e12f40ae Mon Sep 17 00:00:00 2001 From: librelad Date: Mon, 25 May 2026 23:44:42 +0100 Subject: [PATCH] refactor(apps): modularize the gluetun providers generator via a per-app refresh hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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_ (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 Signed-off-by: librelad --- .../gluetun/scripts/gluetun_providers.sh | 8 ++++++ scripts/source/files/arrays/files_webui.sh | 1 - scripts/webui/webui_updater.sh | 26 +++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) rename scripts/webui/data/generators/apps/webui_gluetun_providers.sh => containers/gluetun/scripts/gluetun_providers.sh (89%) diff --git a/scripts/webui/data/generators/apps/webui_gluetun_providers.sh b/containers/gluetun/scripts/gluetun_providers.sh similarity index 89% rename from scripts/webui/data/generators/apps/webui_gluetun_providers.sh rename to containers/gluetun/scripts/gluetun_providers.sh index b692898..785112e 100644 --- a/scripts/webui/data/generators/apps/webui_gluetun_providers.sh +++ b/containers/gluetun/scripts/gluetun_providers.sh @@ -78,3 +78,11 @@ webuiGenerateGluetunProviders() { isNotice "Empty gluetun snapshot generated; ignoring." fi } + +# Routine WebUI-update hook (appWebuiRefresh_): 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 +} diff --git a/scripts/source/files/arrays/files_webui.sh b/scripts/source/files/arrays/files_webui.sh index 86f31fd..8ec9064 100755 --- a/scripts/source/files/arrays/files_webui.sh +++ b/scripts/source/files/arrays/files_webui.sh @@ -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" diff --git a/scripts/webui/webui_updater.sh b/scripts/webui/webui_updater.sh index aa05ce4..6bc62a9 100755 --- a/scripts/webui/webui_updater.sh +++ b/scripts/webui/webui_updater.sh @@ -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_ (in containers//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)