Introduce scripts/source/paths.sh as the canonical path resolver for three independently-relocatable roots: LP_SYSTEM_DIR manager-owned control plane (configs/logs/install/db/ssl/ssh/migrate) LP_CONTAINERS_DIR container-user-owned live app data LP_BACKUPS_DIR container-user-owned backup repos (own mount-able) Roots come from the environment when set (install bakes them; CLI/app inherit from init.sh), else default to /libreportal-*. A transitional compat default keeps EXISTING installs (legacy single /docker tree, by config marker) on /docker until a deliberate reinstall, so deploying this never strands a running box. - init.sh derives the same vars inline (self-contained for the bare /root/init.sh reinstall case); paths.sh mirrors it for the standalone task/check processors, which now self-locate their scripts dir and source it. - Replace functional /docker literals with the derived vars across runtime, install, backup, crontab, crowdsec/restic, headscale, and reinstall paths; clean the inert '== /docker/containers/*' guard fallbacks to the variable form. - backend: CONTAINERS_DIR now from LP_CONTAINERS_DIR (compose env, filled at generation via a new CONTAINERS_DIR_TAG), legacy-safe default for un-recreated containers. - backup default path falls back to the backups root; exclude paths.sh from the sourced-file arrays (bootstrap file, sourced explicitly). The CLI-wrapper heredoc + root helpers still reference /docker; those get baked in phase 3. No layout/ownership change yet (phase 2). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
142 lines
5.3 KiB
Bash
Executable File
142 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Generate arrays script - automatically creates files_*.sh arrays
|
|
# This script scans the scripts folder and generates array files for each subfolder
|
|
#
|
|
# Usage: ./generate_arrays.sh run
|
|
#
|
|
# SAFETY: This script only runs when executed directly with 'run' parameter
|
|
# It will NOT run when sourced (which happens during LibrePortal startup)
|
|
|
|
# Only run if executed directly (not sourced) AND run parameter is provided
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" && "$1" == "run" ]]; then
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ARRAYS_DIR="$SCRIPT_DIR/arrays"
|
|
SCRIPTS_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
|
|
|
# Standalone runner — duplicate the framework's tiny output helpers inline so
|
|
# the script keeps its zero-dependency property but still matches the look of
|
|
# the rest of the install pipeline.
|
|
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[0;33m'; NC='\033[0m'
|
|
isSuccessful() { echo -e "${GREEN}✓ Success${NC} $1"; }
|
|
isNotice() { echo -e "${YELLOW}! Notice${NC} $1"; }
|
|
isHeader() {
|
|
local title="$1"
|
|
local width=52
|
|
local inner=$((width - 2))
|
|
local total_pad=$((inner - ${#title}))
|
|
(( total_pad < 0 )) && total_pad=0
|
|
local left_pad=$((total_pad / 2))
|
|
local right_pad=$((total_pad - left_pad))
|
|
local hbar
|
|
hbar=$(printf '═%.0s' $(seq 1 "$inner"))
|
|
printf '\n╔%s╗\n' "$hbar"
|
|
printf '║%*s%s%*s║\n' "$left_pad" '' "$title" "$right_pad" ''
|
|
printf '╚%s╝\n\n' "$hbar"
|
|
}
|
|
|
|
hbar=$(printf '═%.0s' $(seq 1 50))
|
|
printf '\n╔%s╗\n' "$hbar"
|
|
printf '║%6s%s%8s║\n' '' '╦ ┬┌┐ ┬─┐┌─┐ ╭─╮ ╔═╗┌─┐┬─┐┌┬┐┌─┐┬' ''
|
|
printf '║%6s%s%8s║\n' '' '║ │├┴┐├┬┘├┤ │◉│ ╠═╝│ │├┬┘ │ ├─┤│' ''
|
|
printf '║%6s%s%6s║\n' '' '╩═╝┴└─┘┴└─└─┘ ╨─╨ ╩ └─┘┴└─ ┴ ┴ ┴┴─┘' ''
|
|
printf '╚%s╝\n\n' "$hbar"
|
|
|
|
isHeader "Regenerating Array Files"
|
|
isNotice "Scanning scripts/ for subfolder arrays..."
|
|
|
|
# Create arrays directory if it doesn't exist
|
|
mkdir -p "$ARRAYS_DIR"
|
|
|
|
# Prune arrays whose source folder no longer exists, so a removed area (e.g.
|
|
# scripts/ssh/) doesn't linger in the sourced set as a stale files_*.sh.
|
|
for existing in "$ARRAYS_DIR"/files_*.sh; do
|
|
[ -f "$existing" ] || continue
|
|
pruned_name=$(basename "$existing"); pruned_name=${pruned_name#files_}; pruned_name=${pruned_name%.sh}
|
|
if [ ! -d "$SCRIPTS_DIR/$pruned_name" ]; then
|
|
rm -f "$existing"
|
|
isNotice "Pruned stale files_${pruned_name}.sh (no scripts/$pruned_name/)"
|
|
fi
|
|
done
|
|
|
|
# Get all directories in scripts folder
|
|
for folder in "$SCRIPTS_DIR"/*; do
|
|
if [ -d "$folder" ]; then
|
|
folder_name=$(basename "$folder")
|
|
|
|
# Skip folders that aren't sourced function libraries: the dead-code
|
|
# graveyard, and system/ (standalone root-owned helpers installed to
|
|
# /usr/local/sbin and invoked via sudo — never sourced into the runtime).
|
|
if [ "$folder_name" = "unused" ] || [ "$folder_name" = "system" ]; then
|
|
isNotice "Skipping $folder_name/"
|
|
continue
|
|
fi
|
|
array_file="$ARRAYS_DIR/files_${folder_name}.sh"
|
|
|
|
# Start the array file
|
|
cat > "$array_file" << EOF
|
|
#!/bin/bash
|
|
|
|
# This file is auto-generated by generate_arrays.sh
|
|
# Do not edit manually - run './scripts/source/files/generate_arrays.sh run' to regenerate
|
|
|
|
${folder_name}_scripts=(
|
|
EOF
|
|
|
|
# Find all .sh files in the folder and subdirectories
|
|
find "$folder" -name "*.sh" -type f | sort | while read -r file; do
|
|
# Get relative path from scripts directory
|
|
rel_path=$(realpath --relative-to="$SCRIPTS_DIR" "$file")
|
|
|
|
# Skip specific files for source folder
|
|
if [ "$folder_name" = "source" ]; then
|
|
case "$rel_path" in
|
|
"source/files/app_files.sh"|"source/files/cli_files.sh"| \
|
|
"source/loading/check_files.sh"|"source/loading/initilize_files.sh"| \
|
|
"source/loading/scan_files.sh"|"source/load_sources.sh"| \
|
|
"source/paths.sh"| \
|
|
"source/files/generate_arrays.sh")
|
|
continue
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Skip specific files for webui folder
|
|
if [ "$folder_name" = "webui" ]; then
|
|
case "$rel_path" in
|
|
"webui/data/generators/webui_test_generate.sh")
|
|
continue
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Skip specific files for headscale folder
|
|
if [ "$folder_name" = "headscale" ]; then
|
|
case "$rel_path" in
|
|
"headscale/tailscale/tailscale.sh")
|
|
continue
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Escape quotes and add to array
|
|
echo " \"$rel_path\"" >> "$array_file"
|
|
done
|
|
|
|
# Close the array
|
|
cat >> "$array_file" << EOF
|
|
|
|
)
|
|
EOF
|
|
|
|
isSuccessful "Generated files_${folder_name}.sh"
|
|
fi
|
|
done
|
|
|
|
isHeader "Generation Complete"
|
|
isSuccessful "$(find "$ARRAYS_DIR" -name "files_*.sh" | wc -l) array files written to $ARRAYS_DIR"
|
|
echo ""
|
|
|
|
fi
|