#!/usr/bin/env bash # # install.sh — install this repo's workstation dnsmasq profiles and reload the live resolver. # # Needs root (writes /etc/NetworkManager/dnsmasq.d). Run it as: # sudo infra/workstation/dnsmasq/install.sh # # WHY A SCRIPT AND NOT A DOC LINE: these rules decide which CLUSTER this workstation talks to. Getting # them into the wrong directory is silent — the file exists, looks installed, and changes nothing — # so the destination and the reload are pinned here rather than retyped. Idempotent; safe to re-run. # set -euo pipefail src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # THE LIVE RESOLVER IS NETWORKMANAGER'S dnsmasq, not the standalone service. NetworkManager.conf sets # `dns=dnsmasq`, and the process it spawns runs with `--conf-file=/dev/null` plus # `--conf-dir=/etc/NetworkManager/dnsmasq.d` — so /etc/dnsmasq.d is read ONLY by the standalone # dnsmasq.service, which is inactive here. Installing to the wrong one is the failure this pins down. dest_dir=/etc/NetworkManager/dnsmasq.d [ "$(id -u)" = "0" ] || { echo "ERROR: must run as root — try: sudo $0" >&2; exit 1; } if ! pgrep -af 'dnsmasq.*NetworkManager' >/dev/null 2>&1; then echo "WARN: no NetworkManager-spawned dnsmasq is running." >&2 echo " Check 'dns=dnsmasq' in /etc/NetworkManager/NetworkManager.conf before trusting this." >&2 fi install -d -m 0755 "${dest_dir}" shopt -s nullglob count=0 for f in "${src_dir}"/*.conf; do install -m 0644 "$f" "${dest_dir}/$(basename "$f")" echo "installed: ${dest_dir}/$(basename "$f")" count=$((count+1)) done [ "${count}" -gt 0 ] || { echo "ERROR: no .conf files found in ${src_dir}" >&2; exit 1; } # dnsmasq does NOT re-read its config on SIGHUP (SIGHUP only reloads /etc/hosts and the caches), so a # reload of NetworkManager — which respawns dnsmasq — is what actually applies these files. echo "reloading NetworkManager (respawns dnsmasq with the new config)" systemctl reload NetworkManager || systemctl restart NetworkManager echo echo "verify (expect prod's own VIPs, NOT dev's 192.168.2.50):" echo " getent hosts gitea.prod.home.keithjackson.dev # -> 192.168.2.20" echo " getent hosts unifi.prod.home.keithjackson.dev # -> 192.168.2.21" echo " getent hosts gitea.home.keithjackson.dev # -> 192.168.2.50 (dev, unchanged)"