From 57edb0710ed9d269227550009e1522c883bacd9c Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Sat, 12 Jul 2025 11:10:09 +0100 Subject: use a catalog zone to generate the ${ZONES} list --- bin/get_catalog | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bin/get_catalog (limited to 'bin') diff --git a/bin/get_catalog b/bin/get_catalog new file mode 100755 index 0000000..d9e744b --- /dev/null +++ b/bin/get_catalog @@ -0,0 +1,41 @@ +#! /bin/sh +# +# Fetch the catalog zone '$1' from the server '$2' and print a list of zones. + +set -e + +catalog="$1" +server="$2" + +tempfile="$(mktemp -t catalog)" +trap 'rm $tempfile' 0 + +if ! dig "$catalog" axfr @"$server" +noall +answer >"$tempfile"; then + printf >&2 '%s: query failed\n' "$0" + exit 1 +fi + +# Make sure the result has an SOA, otherwise the query failed. +if ! awk <"$tempfile" " +BEGIN { + exitcode=1 +} + +\$1 == \"$catalog.\" && \$4 == \"SOA\" { + exitcode=0 +} + +END { + exit exitcode +} +"; then + printf >&2 '%s: no SOA found in zone; transfer failed?\n' "$0" + exit 1 +fi + +awk <"$tempfile" " +\$1 ~ /zones.$catalog/ && \$4 == \"PTR\" { + zone = \$5 + sub(/\\.$/, \"\", zone) + print zone +}" -- cgit v1.2.3