LibrePortal/containers/moneyapp/scripts/moneyapp_install_hooks.sh
librelad 8b5e02c760 refactor(storage): resolve every app directory through appDir
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>
2026-08-24 04:09:51 +01:00

55 lines
2.2 KiB
Bash

#!/bin/bash
# MoneyApp install hooks — pre-flight requirements + Auth.js callback URL.
moneyapp_install_pre()
{
local app_name="$1"
# Bail out before any compose/config work if global prerequisites are
# missing (currently "domain,traefik"). The helper prints what's
# missing.
if ! appInstallCheckRequirements "$app_name" "$CFG_MONEYAPP_REQUIRES"; then
moneyapp=n
return 1
fi
}
moneyapp_install_post_compose()
{
local app_name="$1"
((menu_number++))
echo ""
echo "---- $menu_number. Resolving Auth.js callback URL (AUTH_URL)."
echo ""
# Auth.js requires a fixed AUTH_URL matching what the browser actually
# hits — otherwise OAuth-style callbacks bounce. Pick:
# * https://<host>.<domain> when traefik is on AND a real domain
# is configured (CFG_DOMAIN_<n>)
# * http://<server-ip>:<port> otherwise (raw port exposure)
local moneyapp_compose_file="$(appDir "$app_name")/docker-compose.yml"
local moneyapp_auth_url=""
# host_setup is built as `<app>.<domain>` — when CFG_DOMAIN_<n> is
# empty it ends up as `<app>.`, a valid-but-broken hostname. Reject
# that explicitly: we want a real TLD before going https.
local _has_real_domain=0
if [[ -n "$host_setup" && "$host_setup" != *. ]] && [[ "$host_setup" == *.* ]]; then
_has_real_domain=1
fi
if [[ "$public" == "true" && $_has_real_domain -eq 1 ]]; then
moneyapp_auth_url="https://$host_setup"
else
local moneyapp_port_pair
moneyapp_port_pair=$(tagsManagerGetTagContent "$moneyapp_compose_file" "PORTS_TAG_1")
local moneyapp_external_port="${moneyapp_port_pair%%:*}"
local moneyapp_host="${public_ip_v4:-localhost}"
moneyapp_auth_url="http://${moneyapp_host}:${moneyapp_external_port}"
if [[ "$public" == "true" && $_has_real_domain -eq 0 ]]; then
isNotice "PORT_1 has traefik=true but no domain configured — falling back to direct port URL."
fi
fi
tagsManagerUpdateUniversalTag "$moneyapp_compose_file" "MONEYAPP_AUTH_URL_TAG" "$moneyapp_auth_url"
isSuccessful "AUTH_URL set to $moneyapp_auth_url"
}