LibrePortal/scripts/config/application/application_menu_apps.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

69 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
viewAppConfigs()
{
while true; do
isHeader "Installed Applications"
# Get all installed apps from containers directory
local installed_apps=()
while IFS= read -r app_dir; do
if [ -d "$app_dir" ]; then
local app_name=$(basename "$app_dir")
installed_apps+=("$app_name")
fi
done < <(storageAppDirs)
if [ ${#installed_apps[@]} -eq 0 ]; then
isNotice "No installed applications found."
fi
# Display all installed apps with numbers
for ((i = 0; i < ${#installed_apps[@]}; i++)); do
local app_name="${installed_apps[i]}"
isOption "$((i + 1)). $app_name"
done
echo ""
isOption "x. Exit"
echo ""
isQuestion "Enter app number to configure (or x to exit): "
read -p "" selected_app_number
if [[ "$selected_app_number" == "x" ]]; then
if [[ $config_edited == "true" ]]; then
echo ""
isNotice "Reloading configuration file(s) for Applications."
echo ""
sourceScanFiles "app_configs"
else
isNotice "Exiting..."
echo ""
checkConfigFilesMissingVariables true
crontabSetupBackupScheduler
fi
elif [[ "$selected_app_number" =~ ^[0-9]+$ ]] && [ "$selected_app_number" -ge 1 ] && [ "$selected_app_number" -le ${#installed_apps[@]} ]; then
local index=$((selected_app_number - 1))
local selected_app="${installed_apps[index]}"
# Get the config file for this app
local config_file="$(appDir "$selected_app")/${selected_app}.config"
if [ -f "$config_file" ]; then
$CFG_TEXT_EDITOR "$config_file"
createTouch "$config_file" $sudo_user_name
echo ""
isNotice "Configuration file for '$selected_app' has been updated."
echo ""
else
isNotice "Configuration file for '$selected_app' not found."
echo ""
fi
else
isNotice "Invalid input. Please enter a valid number or 'x' to exit."
echo ""
read -p "Press Enter to continue."
fi
done
}