Ajouter scripts/admin/steps/02-dns.sh

This commit is contained in:
youness-adm committed 2026-04-27 02:48:39 +02:00
1 parent 9f5d990d5f
commit ba96ff0535
1 file changed
+63
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# ==============================================================================
# 02-dns.sh — Enregistrements A dans svc.ephaitek.com et adm.ephaitek.com
# ==============================================================================
# dns1maj.sh utilise read -r -p dans des subshells $() — impossible à piper.
# On utilise expect pour simuler un terminal interactif.
# ==============================================================================
set -euo pipefail
SCRIPT_DNS="${ADMIN_TOOLS}/majdns/dns1maj.sh"
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; BLUE='\033[0;34m'; NC='\033[0m'
info() { echo -e " ${BLUE}›${NC} $*"; }
ok() { echo -e " ${GREEN}✔${NC} $*"; }
warn() { echo -e " ${YELLOW}⚠${NC} $*"; }
die() { echo -e " ${RED}✖${NC} $*" >&2; exit 1; }
[[ ! -x "${SCRIPT_DNS}" ]] && die "Script DNS non exécutable: ${SCRIPT_DNS}"
# Vérifier que expect est disponible
if ! command -v expect &>/dev/null; then
die "expect non installé — corriger: dnf install -y expect"
fi
info "NS1 cible : ns1.adm:2260"
info "Hostname : ${NAME}"
info "IP SVC : ${VM_IP} → ${NAME}.svc.ephaitek.com"
info "IP ADM : ${VM_ADMIN_IP} → ${NAME}.adm.ephaitek.com"
if [[ "${DRY_RUN}" == true ]]; then
echo -e " ${YELLOW}[DRY-RUN]${NC} expect << ... | ${SCRIPT_DNS}"
echo -e " ${YELLOW}[DRY-RUN]${NC} Entrées: ${NAME} / ${VM_IP} / ${VM_ADMIN_IP} / y"
exit 0
fi
expect << EXPECT
set timeout 30
spawn ${SCRIPT_DNS}
expect "Hostname court*:" { send "${NAME}\r" }
expect "Adresse IP SVC*:" { send "${VM_IP}\r" }
expect "Adresse IP ADM*:" { send "${VM_ADMIN_IP}\r" }
expect "Appliquer*\[Y/n\]*:" { send "y\r" }
expect eof
EXPECT
# ─── Validation ───────────────────────────────────────────────────────────────
info "Validation résolution DNS (attente 5s)..."
sleep 5
if dig +short "${NAME}.svc.ephaitek.com" 2>/dev/null | grep -q "${VM_IP}"; then
ok "svc: ${NAME}.svc.ephaitek.com → ${VM_IP}"
else
warn "svc: résolution non confirmée — propagation en cours"
fi
if dig +short "${NAME}.adm.ephaitek.com" @10.100.0.60 2>/dev/null | grep -q "${VM_ADMIN_IP}"; then
ok "adm: ${NAME}.adm.ephaitek.com → ${VM_ADMIN_IP}"
else
warn "adm: résolution non confirmée — propagation en cours"
fi
ok "Enregistrements DNS créés pour ${NAME}"