massive update. Master conf split, now modular with a load sceriprt to drive all configs to scripts. with unraid scpecific safeguard tests , and improved standardized ux. including dynamic host detect, who am i who else it there. EVERY SINGLE SCRIPT UPDATED. DEBATING THAT THIS IS ACUALLY V2
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
# ==============================================================================================
|
||||
# ================================= CONFIGURATION LOADER =======================================
|
||||
# ==============================================================================================
|
||||
# Single entry point for all configuration sourcing across the ecosystem.
|
||||
# Every script sources this file instead of sourcing master.conf files directly.
|
||||
#
|
||||
# ── HOW IT WORKS ──────────────────────────────────────────────────────────────────────────────
|
||||
# 1. Sources master.conf (shared config — thresholds, toggles, profiles, job lists)
|
||||
# 2. Auto-discovers and sources all master_host*.conf files in the same directory
|
||||
# Each host conf extends the shared profile arrays and adds host-specific identity
|
||||
# 3. Sources common.sh (shared functions — detect_hosts, logging, notifications etc.)
|
||||
#
|
||||
# ── WHY THIS EXISTS ───────────────────────────────────────────────────────────────────────────
|
||||
# Without this loader every script had to explicitly source each conf file:
|
||||
# source master.conf
|
||||
# source master_host1.conf
|
||||
# source master_host2.conf
|
||||
# source common.sh
|
||||
#
|
||||
# Adding a new server meant updating every script.
|
||||
# With this loader — add master_host3.conf to the git repo and every server
|
||||
# auto-discovers it on next git pull. Zero script changes required. Ever.
|
||||
#
|
||||
# ── ADDING A NEW SERVER ───────────────────────────────────────────────────────────────────────
|
||||
# 1. Create master_host3.conf following the same structure as HOST1/HOST2
|
||||
# 2. Commit and push to git repo
|
||||
# 3. All servers pull it automatically — no other changes needed
|
||||
#
|
||||
# ── USAGE IN SCRIPTS ──────────────────────────────────────────────────────────────────────────
|
||||
# Replace the three source lines at the top of every script with:
|
||||
#
|
||||
# SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# source "$SCRIPT_DIR/../load_config.sh"
|
||||
#
|
||||
# Scripts in subdirectories (Rsync/, Docker_Essentials/ etc.) use ../ to reach root.
|
||||
# Scripts in root directory use ./ instead:
|
||||
#
|
||||
# SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# source "$SCRIPT_DIR/load_config.sh"
|
||||
#
|
||||
# ── SPARSE CHECKOUT NOTE ──────────────────────────────────────────────────────────────────────
|
||||
# Sparse checkout controls which master_host*.conf files each server receives.
|
||||
# HOST1 only pulls master_host1.conf — never HOST2's credentials.
|
||||
# HOST2 only pulls master_host2.conf — never HOST1's credentials.
|
||||
# This loader sources whatever conf files ARE present — sparse checkout handles the rest.
|
||||
# Both servers pull all non-credential conf files (master.conf, common.sh, load_config.sh).
|
||||
#
|
||||
# ==============================================================================================
|
||||
|
||||
# ━━━ Locate config root ━━━
|
||||
# load_config.sh always lives in the repo root.
|
||||
# Scripts call it from subdirectories using ../ — resolve to the actual root.
|
||||
LOAD_CONFIG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# ━━━ Source shared config ━━━
|
||||
# master.conf must be sourced first — it declares the shared PROFILE_* arrays
|
||||
# that Host confs extend. Sourcing host confs before master.conf would fail.
|
||||
if [[ ! -f "$LOAD_CONFIG_DIR/master.conf" ]]; then
|
||||
echo "[FATAL] master.conf not found at $LOAD_CONFIG_DIR/master.conf" >&2
|
||||
echo "[FATAL] Check TARGET_DIR and git pull status" >&2
|
||||
exit 1
|
||||
fi
|
||||
source "$LOAD_CONFIG_DIR/master.conf"
|
||||
|
||||
# ━━━ Auto-discover and source all master_host*.conf files ━━━
|
||||
# Sorted for consistent load order — HOST1 before HOST2 before HOST3 etc.
|
||||
# Each host conf extends the shared PROFILE_* arrays and adds host-specific vars.
|
||||
# Missing files are silently skipped — sparse checkout intentionally withholds some.
|
||||
# At least one host conf must be present or the ecosystem has no identity to work with.
|
||||
_host_confs_loaded=0
|
||||
|
||||
for _conf in $(ls "$LOAD_CONFIG_DIR"/master_host*.conf 2>/dev/null | sort); do
|
||||
if [[ -f "$_conf" ]]; then
|
||||
source "$_conf"
|
||||
(( _host_confs_loaded++ ))
|
||||
[[ "${ENABLE_LOGGING:-false}" == "true" ]] && \
|
||||
echo "[LOG] Loaded host config: $(basename "$_conf")" >&2
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$_host_confs_loaded" -eq 0 ]]; then
|
||||
echo "[FATAL] No master_host*.conf files found in $LOAD_CONFIG_DIR" >&2
|
||||
echo "[FATAL] At least one host conf required — check git pull and sparse checkout" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ━━━ Source shared functions ━━━
|
||||
# common.sh sourced last — it calls detect_hosts() which needs HOST* vars to be set.
|
||||
if [[ ! -f "$LOAD_CONFIG_DIR/common.sh" ]]; then
|
||||
echo "[FATAL] common.sh not found at $LOAD_CONFIG_DIR/common.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
source "$LOAD_CONFIG_DIR/common.sh"
|
||||
|
||||
# ━━━ Cleanup ━━━
|
||||
unset _conf _host_confs_loaded LOAD_CONFIG_DIR
|
||||
Reference in New Issue
Block a user