load_sources.sh calls checkConfigFilesMissingFiles() after init.sh +
variables.sh but BEFORE initilize_files.sh sources the function
manifest. checkConfigFilesMissingFiles uses runInstallOp (in
docker/command/run_privileged.sh) to copy missing config templates —
under LP_LAZY=1 that's an autoload stub that only exists once the
manifest is sourced. So when any template is genuinely missing, the
copy call hits "runInstallOp: command not found" and the file silently
never gets copied.
Symptom on a fresh CLI invocation (foreground or processor subprocess
inheriting LIBREPORTAL_TASK_EXEC=1) where a new config category was
added:
config_check_missing.sh: line 33: runInstallOp: command not found
✓ Success 1 config files were missing and have been added to the
configs folder. ← false success: the count incremented but the
copy itself didn't happen
Fix: source run_privileged.sh directly in load_sources.sh just before
the missing-files check. The file is pure function definitions (runAsManager
/ runFileOp / runFileWrite / runInstallOp / runInstallWrite), no side
effects, ~150 lines — safe to source unconditionally and idempotent
with the eager/lazy load that happens later. Adds <1ms to every CLI
invocation; saves silent failures on the rare path that calls it.
Signed-off-by: librelad <librelad@digitalangels.vip>
69 lines
3.7 KiB
Bash
Executable File
69 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This is used for initial loading
|
|
# The starting point and is the only code that doesnt contain logic requirements
|
|
|
|
# Source "init.sh" and "variables.sh" if they exist, otherwise return an error
|
|
if [ -f "init.sh" ] && [ -f "variables.sh" ]; then
|
|
source "init.sh"
|
|
source "variables.sh"
|
|
else
|
|
# Print an error message for any missing files
|
|
[ ! -f "init.sh" ] && isError " File 'init.sh' does not exist. Unable to source."
|
|
[ ! -f "variables.sh" ] && isError " File 'variables.sh' does not exist. Unable to source."
|
|
echo "Files are missing, please run 'libreportal reset'"
|
|
fi
|
|
|
|
# checkConfigFilesMissingFiles uses runInstallOp (in docker/command/run_privileged.sh)
|
|
# to copy any missing config templates into place. That file's autoload stub
|
|
# isn't defined until the function manifest is sourced inside initilize_files.sh
|
|
# — which we haven't called yet at this point in load_sources. Source the
|
|
# privileged helpers eagerly so the reconciliation can do its work on a fresh
|
|
# install or after a config-template drift. The file is pure function defs;
|
|
# safe to source unconditionally.
|
|
[ -f "${install_scripts_dir}docker/command/run_privileged.sh" ] && \
|
|
source "${install_scripts_dir}docker/command/run_privileged.sh"
|
|
|
|
# Source config check
|
|
if [ -f "${install_scripts_dir}config/core/config_check_missing.sh" ]; then
|
|
source "${install_scripts_dir}config/core/config_check_missing.sh"
|
|
checkConfigFilesMissingFiles;
|
|
else
|
|
# Print an error message for any missing files
|
|
[ ! -f "${install_scripts_dir}config/core/config_check_missing.sh" ] && isError " File '${install_scripts_dir}config/core/config_check_missing.sh' does not exist. Unable to source."
|
|
echo "Files are missing, please run 'libreportal reset'"
|
|
fi
|
|
|
|
# Source the remaining files if they all exist
|
|
if [ -f "${install_scripts_dir}source/loading/check_files.sh" ] && \
|
|
[ -f "${install_scripts_dir}source/loading/initilize_files.sh" ] && \
|
|
[ -f "${install_scripts_dir}source/loading/scan_files.sh" ]; then
|
|
source "${install_scripts_dir}source/loading/check_files.sh"
|
|
source "${install_scripts_dir}source/loading/initilize_files.sh"
|
|
source "${install_scripts_dir}source/loading/scan_files.sh"
|
|
else
|
|
# Print an error message for any missing files
|
|
[ ! -f "${install_scripts_dir}source/loading/check_files.sh" ] && isError " File '${install_scripts_dir}source/loading/check_files.sh' does not exist. Unable to source."
|
|
[ ! -f "${install_scripts_dir}source/loading/initilize_files.sh" ] && isError " File '${install_scripts_dir}source/loading/initilize_files.sh' does not exist. Unable to source."
|
|
[ ! -f "${install_scripts_dir}source/loading/scan_files.sh" ] && isError " File '${install_scripts_dir}source/loading/scan_files.sh' does not exist. Unable to source."
|
|
echo "Files are missing, please run 'libreportal reset'"
|
|
fi
|
|
|
|
# For starting the script
|
|
if [[ $init_run_flag == "true" ]]; then
|
|
# For loading LibrePortal as a long-running process (task processor,
|
|
# WebUI service). Eager loading wins here — the process keeps running,
|
|
# so first call to anything should be hot. LP_LAZY stays unset.
|
|
sourceCheckFiles "run";
|
|
elif [[ $init_run_flag == "false" ]]; then
|
|
# For one-shot CLI invocations. Default LP_LAZY=1 so short commands
|
|
# (`libreportal help`, `peer list`, etc.) only source the ~8 files with
|
|
# top-level side effects + the function manifest stubs, deferring the
|
|
# ~420 pure function libs until something actually calls them. ~34%
|
|
# wall-time savings on a no-op command in measurement (Phase 4 of the
|
|
# lazy-load work). Explicit `LP_LAZY=0 libreportal …` still works for
|
|
# debugging or for catching a stale manifest.
|
|
: "${LP_LAZY:=1}"
|
|
export LP_LAZY
|
|
sourceCheckFiles "cli";
|
|
fi |