From d6d0129a95725249983f409a8765da5ce609cdcd Mon Sep 17 00:00:00 2001 From: luisgulo Date: Thu, 6 Nov 2025 18:28:12 +0100 Subject: YQ_BIN in shflow-trust shflow-ssh-init --- core/utils/shflow-trust.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'core/utils/shflow-trust.sh') diff --git a/core/utils/shflow-trust.sh b/core/utils/shflow-trust.sh index bc27d94..ca24762 100755 --- a/core/utils/shflow-trust.sh +++ b/core/utils/shflow-trust.sh @@ -2,7 +2,7 @@ # Utility: shflow-trust # Description: Evalúa acceso SSH y privilegios sudo para cada host del inventario # Author: Luis GuLo -# Version: 0.4.0 +# Version: 0.4.1 set -euo pipefail @@ -13,6 +13,16 @@ REPORT="$PROJECT_ROOT/core/inventory/trust_report.yaml" TIMEOUT=5 USER="${USER:-$(whoami)}" +# 🔧 yq segun arquitectura +ARCH=$(uname -m) +case "$ARCH" in + x86_64) YQ_BIN="$PROJECT_ROOT/core/utils/yq_linux_amd64" ;; + i686|i386) YQ_BIN="$PROJECT_ROOT/core/utils/yq_linux_386" ;; + aarch64) YQ_BIN="$PROJECT_ROOT/core/utils/yq_linux_arm64" ;; + armv7l|armv6l) YQ_BIN="$PROJECT_ROOT/core/utils/yq_linux_arm" ;; + *) echo "❌ Arquitectura no soportada: $ARCH"; exit 1 ;; +esac + # 🧩 Cargar render_msg si no está disponible COMMON_LIB="$PROJECT_ROOT/core/lib/translate_msg.sh" if ! declare -f render_msg &>/dev/null; then @@ -33,8 +43,8 @@ echo "$(render_msg "${tr[report]}" "path=$REPORT")" echo "" # 🧪 Validar dependencia yq -if ! command -v yq &>/dev/null; then - echo "$(render_msg "${tr[missing_dep]}" "cmd=yq")" +if ! command -v $YQ_BIN &>/dev/null; then + echo "$(render_msg "${tr[missing_dep]}" "cmd=$YQ_BIN")" exit 1 fi @@ -47,7 +57,7 @@ fi # 🔁 Extraer hosts HOSTS=() -HOSTS_RAW=$(yq ".all.hosts | keys | .[]" "$INVENTORY") +HOSTS_RAW=$($YQ_BIN eval -o=json ".all.hosts | keys | .[]" "$INVENTORY") [ -z "$HOSTS_RAW" ] && echo "${tr[no_hosts]:-❌ No se encontraron hosts en el inventario.}" && exit 1 while IFS= read -r line; do @@ -56,7 +66,7 @@ done <<< "$HOSTS_RAW" # 🔍 Evaluar cada host for host in "${HOSTS[@]}"; do - IP=$(yq -r ".all.hosts.\"$host\".ansible_host" "$INVENTORY") + IP=$($YQ_BIN eval -o=json ".all.hosts.\"$host\".ansible_host" "$INVENTORY") [[ "$IP" == "null" || -z "$IP" ]] && echo "$(render_msg "${tr[missing_ip]}" "host=$host")" && continue echo "$(render_msg "${tr[checking]}" "host=$host" "ip=$IP")" -- cgit v1.2.3