#!/bin/bash

# Reconcile the general LibrePortal config files ($configs_dir) against the
# freshly-cloned templates ($install_configs_dir). See reconcileConfigFile.
checkLibrePortalConfigFilesMissingVariables()
{
    local live fn rel remote
    while IFS= read -r live; do
        [[ -f "$live" ]] || continue
        fn=$(basename "$live")
        # configs_dir carries a trailing slash (paths.sh) — strip it before
        # appending one, or the prefix never matches ("configs//"), rel stays
        # the absolute path, the template lookup misses, and every nested
        # config file silently skips reconciliation.
        rel="${live#"${configs_dir%/}"/}"
        remote="$install_configs_dir$fn"
        [[ -f "$remote" ]] || remote="$install_configs_dir$rel"
        reconcileConfigFile "$live" "$remote"
    done < <(find "$configs_dir" -type f ! -name ".category" ! -name "*.bak")

    isSuccessful "LibrePortal config reconciliation completed."
}
