chiark / gitweb /
*.lisp: Arrange better authoritative nameservers.
[zones] / Makefile
index a0c2d66c0d9fe7a30117959e97e9b6844585436d..69d62e679a77cafb13b7acd1e6f080e78c6df022 100644 (file)
--- a/Makefile
+++ b/Makefile
-## Makefile for mdw's zones
+### -*-makefile-*-
+###
+### Makefile for the DNS zones I maintain.
+###
+### (c) 2011 Mark Wooding
 
-ZONE = zone
+###--------------------------------------------------------------------------
+### Silent-rules machinery.
 
-DISTORTED_ZONES = \
-       distorted.org.uk.zone \
-       198.29.172.in-addr.arpa.zone \
-       199.29.172.in-addr.arpa.zone
-HARLEQUIN_ZONES = \
-       harlequin.org.uk.zone
-ALL_ZONES = \
-       $(DISTORTED_ZONES) \
-       $(HARLEQUIN_ZONES)
+V                       = 0
+v_tag                   = $(call v_tag_$V,$1)
+v_tag_0                         = @printf "  %-6s %s\n" "$1" "$@";
 
-DOCS = distorted.tex
-DOC_OUTPUTS = $(foreach suffix,dvi ps,\
-               $(patsubst %.tex,%.$(suffix),$(DOCS)))
+V_AT                    = $(V_AT_$V)
+V_AT_0                  = @
 
-all: $(ALL_ZONES) $(DOC_OUTPUTS)
+###--------------------------------------------------------------------------
+### Programs and options.
 
-publish:; mkdir publish
+## Zone checking.
+CHECKZONE               = named-checkzone -i full \
+                               -k fail -M fail -n fail -S fail -W fail
 
-install: all publish
-       for i in $(ALL_ZONES); do \
-         cmp $$i publish/$$i >/dev/null 2>&1 && continue; \
-         cp $$i publish/$$i.new && mv publish/$$i.new publish/$$i; \
-         echo -n "$${i%.zone}: "; userv root named-reload $${i%.zone}; \
-       done
+## Zone installation.
+MASTER                  = localhost
+inside_MASTER           = precision
 
-$(DISTORTED_ZONES): distorted.lisp hosts.lisp
-       $(ZONE) $<
+ifeq ($(MASTER),localhost)
+ZONEINST                = userv zoneconf install
+else
+ZONEINST                = ssh zoneconf@$(MASTER)
+endif
 
-$(HARLEQUIN_ZONES): harlequin.lisp hosts.lisp
-       $(ZONE) $<
+###--------------------------------------------------------------------------
+### Utility functions.
 
-%.dvi: %.tex
-       latex $<
-       latex $<
+dir-nosl = $(patsubst %/,%,$(dir $1))
 
-%.ps: %.dvi
-       dvips -o $@ $<
+###--------------------------------------------------------------------------
+### Keeping all of the files straight.
 
-clean: 
-       rm -f $(ALL_ZONES) *.toc *.lof *.lot *.log *.dvi *.ps *.aux
+## Establish a default target.  We'll sort out what it does later.
+all:
+.PHONY: all
+
+## Things to clean.
+CLEANFILES              =
+CLEANDIRS               =
+REALCLEANFILES          = $(CLEANFILES)
+REALCLEANDIRS           = $(CLEANDIRS)
+
+## We work in terms of `zonesets'.  Each one corresponds to a Lisp source
+## file to be passed to `zone'.  A zoneset has a number of different nets
+## associated with it, in the variable zoneset_NETS, and we must run it
+## through `zone' once for each net.  The zoneset will make a number of
+## zones, listed in zoneset_ZONES.
+ZONESETS                =
+
+###--------------------------------------------------------------------------
+### The distorted.org.uk zones.
+
+ZONESETS               += distorted
+
+distorted_VIEWS                 = inside outside
+distorted_outside_NETS  = dmz jump
+distorted_inside_NETS   = any unsafe colo vpn upn
+
+distorted_all_ZONES    += distorted.org.uk
+
+distorted_all_ZONES    += 195.113.2.81.in-addr.arpa
+distorted_all_ZONES    += 128-143.238.187.81.in-addr.arpa
+distorted_all_ZONES    += 64-79.198.13.212.in-addr.arpa
+
+distorted_all_ZONES    += 199.29.172.in-addr.arpa
+
+distorted_all_ZONES    += 9.d.1.0.0.0.0.0.8.a.b.0.1.0.0.2.ip6.arpa
+distorted_all_ZONES    += 2.9.c.0.0.b.8.0.1.0.0.2.ip6.arpa
+distorted_all_ZONES    += 9.d.1.0.8.a.b.0.1.0.0.2.ip6.arpa
+
+distorted_outside_NSDIFF = -sradius.dmz.distorted.org.uk
+
+###--------------------------------------------------------------------------
+### Other zones.
+
+## binswood.org.uk
+ZONESETS               += binswood
+binswood_VIEWS          = outside
+binswood_all_ZONES     += binswood.org.uk
+binswood_all_ZONES     += 27.165.10.in-addr.arpa
+
+## escorted.org.uk
+ZONESETS               += escorted
+escorted_VIEWS          = outside
+escorted_all_ZONES     += escorted.org.uk
+
+## odin.gg
+ZONESETS               += odin
+odin_VIEWS              = outside
+odin_all_ZONES          = odin.gg
+
+## goodhstg.com
+ZONESETS               += goodhstg
+goodhstg_VIEWS          = outside
+goodhstg_all_ZONES      = goodhstg.com
+
+###--------------------------------------------------------------------------
+### Zone construction machinery.
+
+ZONE                    = zone
+V_ZONE                  = $(call v_tag,ZONE)$(ZONE)
+
+.SECONDEXPANSION: #sorry
+
+## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
+## remember that we've made the corresponding zones.
+ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
+       $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
+$(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
+       $(V_AT)mkdir -p $(dir $*)
+       $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
+               hack) $(addprefix -s, \
+               $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
+       $(V_AT)touch $@
+all: $(ALL_ZONESTAMPS)
+CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
+                      $(foreach v,$($s_VIEWS), \
+                        $v/*.zonestamp $v/*.zone)))
+REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
+                          $(foreach v,$($s_VIEWS), \
+                            $v/*.serial)))
+REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
+
+## Now explain that each generated zone file depends on the corresponding
+## zonestamp.  This is where things start getting a little hairy.
+$(foreach s,$(ZONESETS), \
+  $(foreach v,$($s_VIEWS), \
+    $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+      $(eval $v/$z.zone: $v/$s.zonestamp))))
+
+## Prepare a mapping from zone names back to their owning zonesets.
+$(foreach s,$(ZONESETS), \
+  $(foreach z,$(sort $(foreach v,$($s_VIEWS), \
+       $($s_all_ZONES) $($s_$v_ZONES))), \
+    $(eval $z_ZONESET = $s)))
+
+## Now we have to check the individual zone files.
+ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
+       $(foreach v,$($s_VIEWS), \
+         $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+           $v/$z.check)))
+$(ALL_ZONECHECKS) : %.check : %.zone
+       $(call v_tag,CHECK)\
+               { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
+               { grep -Ev 'loaded serial|OK' || :; }
+check: $(ALL_ZONECHECKS)
+.PHONY: check $(ALL_ZONECHECKS)
+
+## If nsdiff(1) is available then we can show what changes we will make if
+## we install the new zone files.
+ALL_ZONEDIFFS = $(foreach s,$(ZONESETS), \
+       $(foreach v,$($s_VIEWS), \
+         $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+           $v/$z.zonediff)))
+run-nsdiff = nsdiff -v "" $2 \
+       $($($(call notdir,$1)_ZONESET)_$(call dir-nosl,$1)_NSDIFF) \
+       $(call notdir,$1) $1.zone
+$(ALL_ZONEDIFFS) : %.zonediff : %.zone
+       $(call v_tag,NSDIFF)$(call run-nsdiff,$*,-q); \
+       rc=$$?; case $$rc in 1) $(call run-nsdiff,$*); rc=$$? ;; esac; \
+       case $$rc in 0 | 1) : ;; *) exit $$rc ;; esac
+diff: $(ALL_ZONEDIFFS)
+
+## Finally we have to install the zone files.
+ALL_INSTALLS = $(foreach s,$(ZONESETS), \
+       $(foreach v,$($s_VIEWS), \
+         $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
+           $v/$z.inst)))
+$(ALL_INSTALLS) : %.inst : %.check
+       $(call v_tag,INST)$(ZONEINST) \
+               $(call dir-nosl,$*) $(notdir $*) <$*.zone
+install: $(ALL_INSTALLS)
+.PHONY: install $(ALL_INSTALLS)
+
+## Files to clean.
+clean:
+       rm -f $(CLEANFILES)
+       [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
+realclean:
+       rm -f $(REALCLEANFILES)
+       [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
+.PHONY: clean realclean
+
+###----- That's all, folks --------------------------------------------------