diff options
Diffstat (limited to 'core/utils/shflow-check.sh')
| -rwxr-xr-x | core/utils/shflow-check.sh | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/core/utils/shflow-check.sh b/core/utils/shflow-check.sh index d026875..6906868 100755 --- a/core/utils/shflow-check.sh +++ b/core/utils/shflow-check.sh @@ -2,7 +2,7 @@ # ShFlow Environment Checker # License: GPLv3 # Author: Luis GuLo -# Version: 1.5.0 +# Version: 1.5.1 set -e @@ -43,6 +43,10 @@ REQUIRED_PATHS=( "$PROJECT_ROOT/vault.sh" ) +# 📦 Variables Globales +declare -A shflow_vars +GLOBAL_VARS="$PROJECT_ROOT/core/inventory/vars/all.yaml" + # 🌐 Cargar traducciones lang="${shflow_vars[language]:-es}" trfile="$PROJECT_ROOT/core/utils/shflow-check.tr.${lang}" @@ -96,13 +100,74 @@ load_and_check_modules() { done } +# 📦 Carga las variables globales de all.yaml +load_global_vars() { + if [[ -f "$GLOBAL_VARS" ]]; then + echo "${tr[vars_loading]:-📦 Cargando variables globales de all.yaml...}" + + # Carga todas las claves del YAML + GLOBAL_KEYS=$("$YQ_BIN" eval 'keys[]' "$GLOBAL_VARS" -r 2>/dev/null || true) + + for key in $GLOBAL_KEYS; do + # Carga el valor en modo raw para Bash + raw_value=$("$YQ_BIN" eval ".\"$key\"" "$GLOBAL_VARS" -r 2>/dev/null || true) + + # Si el valor es una lista o multilínea, yq lo habrá cargado con saltos de línea, lo almacenamos tal cual. + # Si es un valor simple, lo almacenamos. + shflow_vars["$key"]="$raw_value" + done + + echo "$(render_msg "${tr[vars_loaded]:-✅ Variables cargadas: {count}}" "count=${#shflow_vars[@]}")" + + # Si la variable 'language' se ha cargado, actualizamos las traducciones del check. + local new_lang="${shflow_vars[language]:-es}" + if [[ "$new_lang" != "$lang" ]]; then + lang="$new_lang" + trfile="$PROJECT_ROOT/core/utils/shflow-check.tr.${lang}" + if [[ -f "$trfile" ]]; then + declare -A tr # Reset array + while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile" + fi + fi + else + echo "$(render_msg "${tr[vars_missing]:-⚠️ all.yaml no encontrado en {path}}" "path=$GLOBAL_VARS")" + fi +} + +# 🧠 Mostrar variables cargadas +show_global_vars() { + echo "" + echo "${tr[debug_vars_header]:-🌐 VARIABLES GLOBALES CARGADAS:}" + echo "=====================================" + local count=0 + for key in "${!shflow_vars[@]}"; do + local display_value="${shflow_vars[$key]}" + + # Formateo básico para listas para una mejor lectura en la consola + if [[ "$key" == "ntp_servers" || "$key" == "default_packages" ]]; then + # Reemplaza los saltos de línea por comas y espacio + display_value=$(echo "$display_value" | tr '\n' ' ' | xargs | sed 's/ /\//g') + fi + + echo "- $key: $display_value" + count=$((count + 1)) + done + echo "-------------------------------------" + echo "$(render_msg "${tr[debug_vars_count]:-Total de variables: {count}" "count=$count")" +} + + main() { echo "${tr[title]:-🧪 ShFlow Environment Check}" echo "${tr[separator]:-=============================}" + load_global_vars + check_global_tools check_structure load_and_check_modules + + show_global_vars echo "" echo "${tr[done]:-✅ Verificación completada.}" |
