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

60 lines
2.9 KiB
Bash
Raw Permalink 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
# ==============================================================================
# 04-splitdns.sh — Déploiement dnsmasq + resolv.conf via deploy-dns-keyv3.sh
# ==============================================================================
# Fix TTY : deploy-dns-keyv3.sh fait un `read -s` qui requiert un TTY.
# Solution : copie temporaire patchée du script qui lit DEFAULT_PASSWORD
# depuis l'environnement au lieu du read -s interactif.
# ==============================================================================
set -euo pipefail
SCRIPT_SPLITDNS="${ADMIN_TOOLS}/deploy_splitdns_adminkey/deploy-dns-keyv3.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_SPLITDNS}" ]] && die "Script split DNS non exécutable: ${SCRIPT_SPLITDNS}"
# ─── CSV temporaire ───────────────────────────────────────────────────────────
TMP_CSV=$(mktemp /tmp/post-provision-XXXXXX.csv)
TMP_SCRIPT=$(mktemp /tmp/splitdns-patched-XXXXXX.sh)
trap 'rm -f "${TMP_CSV}" "${TMP_SCRIPT}"' EXIT
printf 'name,host,ssh_port\n%s,%s,%s\n' \
"${NAME}" "${VM_ADMIN_IP}" "${SSH_PORT}" \
> "${TMP_CSV}"
info "VM cible : ${NAME} (${VM_ADMIN_IP}:${SSH_PORT})"
info "CSV : ${NAME},${VM_ADMIN_IP},${SSH_PORT}"
if [[ "${DRY_RUN}" == true ]]; then
echo -e " ${YELLOW}[DRY-RUN]${NC} ${SCRIPT_SPLITDNS} ${TMP_CSV}"
exit 0
fi
# ─── Mot de passe root VM ─────────────────────────────────────────────────────
if [[ -z "${VM_ROOT_PASSWORD:-}" ]]; then
echo -e " ${YELLOW}ℹ${NC} Astuce: export VM_ROOT_PASSWORD=xxx avant de lancer run-all.sh"
read -r -s -p " Mot de passe root des VM (Cloud-Init): " VM_ROOT_PASSWORD
echo
fi
# ─── Patch TTY ────────────────────────────────────────────────────────────────
# La ligne dans deploy-dns-keyv3.sh :
# read -s -p "Mot de passe root générique des VM : " DEFAULT_PASSWORD
# On la remplace par une lecture depuis l'environnement :
# DEFAULT_PASSWORD="${DEFAULT_PASSWORD:-}"
sed 's/read -s -p "Mot de passe root.*" DEFAULT_PASSWORD/DEFAULT_PASSWORD="${DEFAULT_PASSWORD:-}"/' \
"${SCRIPT_SPLITDNS}" > "${TMP_SCRIPT}"
chmod +x "${TMP_SCRIPT}"
info "Exécution split DNS..."
DEFAULT_PASSWORD="${VM_ROOT_PASSWORD}" \
bash "${TMP_SCRIPT}" "${TMP_CSV}" \
|| die "Échec déploiement split DNS sur ${NAME}"
ok "Split DNS (dnsmasq) déployé sur ${NAME}"