LibrePortal/scripts/webui/data/utils/webui_app_log.sh
librelad 2d24a764a8 refactor(storage): route elevation tests and the WebUI tree through paths.sh
Two mechanical sweeps, no behaviour change on a single-root install.

The 14 `[[ "$p" == "$containers_dir"* ]]` prefix tests that decide
manager-vs-container-user elevation become pathIsContainerData, so a file
on a second storage root is no longer misclassified as manager-owned —
which would have written it with the wrong owner and failed later, far
from the cause. The 65 references to the WebUI's own tree become
webuiDir(), which is pinned to the primary root by design.

Two traps found while doing it:

run_privileged.sh is sourced directly by init.sh without paths.sh, so it
needs a fallback. Defining one named pathIsContainerData was wrong:
generate_function_manifest.sh indexes top-level definitions, and the
resulting autoload stub would have shadowed the real multi-root
implementation with the primary-only fallback — silently classifying
every file on a second disk as manager-owned, which is exactly the bug
this sweep exists to prevent. Renamed to _runCfgIsContainerPath, which
delegates when the real one is loaded.

setup_lock.sh built its path in a top-level assignment, so it was
evaluated at source time and needed the file flagged eager. Made it a
function instead: the path resolves on call, and the file drops off
LP_EAGER_FILES entirely.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-24 04:04:19 +01:00

34 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
webuiUpdateAppLog()
{
local app_name=$1
local type=$2 # install or uninstall
# Create logs directory if it doesn't exist
local log_dir="$(webuiDir)/frontend/logs"
local apps_dir="${log_dir}/apps"
if [ ! -d "$apps_dir" ]; then
local result; result=$(createFolders "loud" $sudo_user_name $log_dir $apps_dir)
checkSuccess "Creating frontend logs folder"
fi
local log_file="${apps_dir}/${app_name}.log"
# Handle different log types
if [[ "$type" == "install" ]]; then
# Create WebUI log file if it doesn't exist
if [ ! -f "${log_file}" ]; then
createTouch "$log_file" $sudo_user_name "silent"
echo "=== LibrePortal Installation Started at $(date) ===" | runFileWrite "${log_file}" > /dev/null
fi
elif [[ "$type" == "uninstall" ]]; then
# Remove app log file via runFileOp (as the container-data owner) with
# -f: the log can be write-protected, and a bare rm prompts
# interactively for write-protected files, which hangs an unattended
# deploy (the uninstall phase of a 'full' redeploy).
if [ -f "${log_file}" ]; then
local result; result=$(runFileOp rm -f "${log_file}")
checkSuccess "Removed ${app_name}.log"
fi
fi
}