#!/bin/bash sourceInitilize() { local flag="$1" # We will only show the header for the full app if [[ $flag == "run" ]]; then isHeader "Loading LibrePortal Startup Files" isNotice "If you are experiencing loading issues..." isNotice "Please run the following : 'libreportal reset'" fi # Directory containing the files to source recursively local file_list_directory="${install_scripts_dir}source/files" # Check if the directory exists if [ -d "$file_list_directory" ]; then # Use find to get a list of all files (excluding directories) in the directory and its subdirectories local file_list=$(find "$file_list_directory" -type f -name "*.sh") # Loop through each file in the file list while IFS= read -r file; do # Source the file source "$file" done <<< "$file_list" else echo "Directory $file_list_directory does not exist. Unable to start!" fi # For loading files needed for the full app or CLI if [[ $flag == "run" ]]; then source "${install_scripts_dir}source/files/app_files.sh" files_to_source=("${files_libreportal_app[@]}") elif [[ $flag == "cli" ]]; then source "${install_scripts_dir}source/files/cli_files.sh" files_to_source=("${files_libreportal_cli[@]}") fi # Checking for missing files. If LP_LOAD_TRACE=1, every source is timed # and logged to ${LP_LOAD_TRACE_FILE:-/tmp/libreportal-load-trace..log} # — used by `libreportal debug load-trace` to pinpoint where the startup # second goes. Each line: \t. Zero overhead when # the env var is not set (one `[[` per file). if [[ "$LP_LOAD_TRACE" == "1" ]]; then : "${LP_LOAD_TRACE_FILE:=/tmp/libreportal-load-trace.$$.log}" export LP_LOAD_TRACE_FILE : > "$LP_LOAD_TRACE_FILE" fi for file_to_source in "${files_to_source[@]}"; do if [ ! -f "${install_scripts_dir}${file_to_source}" ]; then isNotice "Missing file: ${install_scripts_dir}${file_to_source}" else if [[ "$LP_LOAD_TRACE" == "1" ]]; then local _t0=$EPOCHREALTIME source "${install_scripts_dir}${file_to_source}" local _t1=$EPOCHREALTIME # ms with 3 decimals. EPOCHREALTIME is `.`; awk # handles the float arithmetic without needing bc. local _ms _ms=$(awk -v a="$_t0" -v b="$_t1" 'BEGIN{printf "%.3f", (b-a)*1000}') printf '%s\t%s\n' "$_ms" "$file_to_source" >> "$LP_LOAD_TRACE_FILE" else source "${install_scripts_dir}${file_to_source}" fi fi done # Loading of all files sourceScanFiles "libreportal_configs"; sourceScanFiles "app_configs"; sourceScanFiles "containers"; }