*.lisp: Deploy `eggle' as a nameserver.
[zones] / Makefile
... / ...
CommitLineData
1### -*-makefile-*-
2###
3### Makefile for the DNS zones I maintain.
4###
5### (c) 2011 Mark Wooding
6
7###--------------------------------------------------------------------------
8### Silent-rules machinery.
9
10V = 0
11v_tag = $(call v_tag_$V,$1)
12v_tag_0 = @printf " %-6s %s\n" "$1" "$@";
13
14V_AT = $(V_AT_$V)
15V_AT_0 = @
16
17###--------------------------------------------------------------------------
18### Programs and options.
19
20## Zone checking.
21CHECKZONE = named-checkzone -i full \
22 -k fail -M fail -n fail -S fail -W fail
23
24## Zone installation.
25MASTER = localhost
26inside_MASTER = precision
27
28ifeq ($(MASTER),localhost)
29ZONEINST = userv zoneconf install
30else
31ZONEINST = ssh zoneconf@$(MASTER)
32endif
33
34###--------------------------------------------------------------------------
35### Utility functions.
36
37dir-nosl = $(patsubst %/,%,$(dir $1))
38
39###--------------------------------------------------------------------------
40### Keeping all of the files straight.
41
42## Establish a default target. We'll sort out what it does later.
43all:
44.PHONY: all
45
46## Things to clean.
47CLEANFILES =
48CLEANDIRS =
49REALCLEANFILES = $(CLEANFILES)
50REALCLEANDIRS = $(CLEANDIRS)
51
52## We work in terms of `zonesets'. Each one corresponds to a Lisp source
53## file to be passed to `zone'. A zoneset has a number of different nets
54## associated with it, in the variable zoneset_NETS, and we must run it
55## through `zone' once for each net. The zoneset will make a number of
56## zones, listed in zoneset_ZONES.
57ZONESETS =
58
59###--------------------------------------------------------------------------
60### The distorted.org.uk zones.
61
62ZONESETS += distorted
63
64distorted_VIEWS = inside outside
65distorted_outside_NETS = dmz
66distorted_inside_NETS = any unsafe vpn upn
67
68distorted_all_ZONES += distorted.org.uk
69
70distorted_all_ZONES += 195.113.2.81.in-addr.arpa
71distorted_all_ZONES += 128-143.238.187.81.in-addr.arpa
72distorted_all_ZONES += 64-79.12.169.217.in-addr.arpa
73distorted_all_ZONES += 2.9.c.0.0.b.8.0.1.0.0.2.ip6.arpa
74distorted_all_ZONES += 9.d.1.0.8.a.b.0.1.0.0.2.ip6.arpa
75
76distorted_all_ZONES += 199.29.172.in-addr.arpa
77
78distorted_outside_NSDIFF = -sradius.dmz.distorted.org.uk
79
80###--------------------------------------------------------------------------
81### Other zones.
82
83## binswood.org.uk
84ZONESETS += binswood
85binswood_VIEWS = outside
86binswood_all_ZONES += binswood.org.uk
87binswood_all_ZONES += 27.165.10.in-addr.arpa
88
89## escorted.org.uk
90ZONESETS += escorted
91escorted_VIEWS = outside
92escorted_all_ZONES += escorted.org.uk
93
94## odin.gg
95ZONESETS += odin
96odin_VIEWS = outside
97odin_all_ZONES = odin.gg
98
99###--------------------------------------------------------------------------
100### Zone construction machinery.
101
102ZONE = zone
103V_ZONE = $(call v_tag,ZONE)$(ZONE)
104ZONEOPTS =
105
106.SECONDEXPANSION: #sorry
107
108## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
109## remember that we've made the corresponding zones.
110ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
111 $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
112$(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
113 $(V_AT)mkdir -p $(dir $*)
114 $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
115 hack) $(addprefix -s, \
116 $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $(ZONEOPTS) $<
117 $(V_AT)touch $@
118all: $(ALL_ZONESTAMPS)
119CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
120 $(foreach v,$($s_VIEWS), \
121 $v/*.zonestamp $v/*.zone)))
122REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
123 $(foreach v,$($s_VIEWS), \
124 $v/*.serial)))
125REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
126
127## Now explain that each generated zone file depends on the corresponding
128## zonestamp. This is where things start getting a little hairy.
129$(foreach s,$(ZONESETS), \
130 $(foreach v,$($s_VIEWS), \
131 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
132 $(eval $v/$z.zone: $v/$s.zonestamp))))
133
134## Prepare a mapping from zone names back to their owning zonesets.
135$(foreach s,$(ZONESETS), \
136 $(foreach z,$(sort $(foreach v,$($s_VIEWS), \
137 $($s_all_ZONES) $($s_$v_ZONES))), \
138 $(eval $z_ZONESET = $s)))
139
140## Now we have to check the individual zone files.
141ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
142 $(foreach v,$($s_VIEWS), \
143 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
144 $v/$z.check)))
145$(ALL_ZONECHECKS) : %.check : %.zone
146 $(call v_tag,CHECK)\
147 { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
148 { grep -Ev 'loaded serial|OK' || :; }
149check: $(ALL_ZONECHECKS)
150.PHONY: check $(ALL_ZONECHECKS)
151
152## If nsdiff(1) is available then we can show what changes we will make if
153## we install the new zone files.
154ALL_ZONEDIFFS = $(foreach s,$(ZONESETS), \
155 $(foreach v,$($s_VIEWS), \
156 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
157 $v/$z.zonediff)))
158run-nsdiff = nsdiff -v "" $2 \
159 $($($(call notdir,$1)_ZONESET)_$(call dir-nosl,$1)_NSDIFF) \
160 $(call notdir,$1) $1.zone
161$(ALL_ZONEDIFFS) : %.zonediff : %.zone
162 $(call v_tag,NSDIFF)$(call run-nsdiff,$*,-q); \
163 rc=$$?; case $$rc in 1) $(call run-nsdiff,$*); rc=$$? ;; esac; \
164 case $$rc in 0 | 1) : ;; *) exit $$rc ;; esac
165diff: $(ALL_ZONEDIFFS)
166
167## Finally we have to install the zone files.
168ALL_INSTALLS = $(foreach s,$(ZONESETS), \
169 $(foreach v,$($s_VIEWS), \
170 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
171 $v/$z.inst)))
172$(ALL_INSTALLS) : %.inst : %.check
173 $(call v_tag,INST)$(ZONEINST) \
174 $(call dir-nosl,$*) $(notdir $*) <$*.zone
175install: $(ALL_INSTALLS)
176.PHONY: install $(ALL_INSTALLS)
177
178## Files to clean.
179clean:
180 rm -f $(CLEANFILES)
181 [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
182realclean:
183 rm -f $(REALCLEANFILES)
184 [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
185.PHONY: clean realclean
186
187###----- That's all, folks --------------------------------------------------