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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# This source code is released into the public domain.
DIFF?=
ZONEDIR= ${.CURDIR}/zones
NSUPDATE?= nsupdate
NSUPDATE_FLAGS?=-g
NSDIFF?= nsdiff
NSDIFFFLAGS?= -Sserial -s ${MASTER}
# Template variables for primary zones.
ZONE_PROCESS_FLAGS= \
-Dttl=${TTL} \
-Dnameservers="${NAMESERVERS}" \
-Dsoa_mname=${SOA_MNAME} \
-Dsoa_rname=${SOA_RNAME} \
-Dsoa_serial=${SOA_SERIAL} \
-Dsoa_refresh=${SOA_REFRESH} \
-Dsoa_retry=${SOA_RETRY} \
-Dsoa_expire=${SOA_EXPIRE} \
-Dsoa_minimum=${SOA_MINIMUM}
.SUFFIXES: .zone.erb .czone
update-zones:
.PHONY: update-zones
.for zone in ${ZONES}
# Update this zone when running update-zones.
update-zones: ${zone}
# How to build a processed zone from an ERB zonefile.
${zone:S,/,_,g}.czone: Makefile ${zone:S,/,_,g}.zone.erb
${PROCESS} \
-Dzone=${zone} \
${ZONE_PROCESS_FLAGS} \
${ZONEDIR}/${zone:S,/,_,g}.zone.erb $@
# Take the built .czone file and send it to nsdiff.
# If DIFF is set, just print the diff instead of sending it to nsupdate.
${zone}: ${zone:S,/,_,g}.czone
.if ${DIFF} != ""
@if ! ${NSDIFF} ${NSDIFFFLAGS} ${zone} ${.ALLSRC} >/dev/null 2>&1; then \
tmpfile="$$(mktemp dns.XXXXXX)"; \
${NSDIFF} ${NSDIFFFLAGS} ${zone} ${.ALLSRC} || true; \
rm "$$tmpfile"; \
fi
.else
${NSDIFF} ${NSDIFFFLAGS} ${zone} $> | ${NSUPDATE} ${NSUPDATE_FLAGS}
.endif
.PHONY: ${zone}
# Delete the czone for this zone when cleaning.
clean-zone-${zone}:
rm -f ${zone:S,/,_,g}.czone
.PHONY: Clean-zone-${zone}
clean: clean-zone-${zone}
.endfor
# For easy of use, 'make diff' runs update-zone with DIFF set.
diff:
@${MAKE} -C ${.CURDIR} DIFF=yes update-zones
.PHONY: diff
|