aboutsummaryrefslogtreecommitdiffstats
path: root/bin/get_catalog
blob: d9e744bb514ed42a1a69f77f7d5dfe56488fe0e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
}"