This repository has been archived on 2026-11-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Ephaitek-provisioning/scripts/admin/steps/02-dns.sh
T

64 lines
2.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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}"