2 dnl ### NSC 2.0 -- Zone File Generator
3 dnl ### (c) 1997 Martin Mares <mj@gts.cz>
5 dnl ### Usage: m4 nsc.m4 domain-source-files >zone-file
6 dnl ### Or: m4 nsc.m4 domain-source-files >rev-zone-file -DREVERSE=net-ip -DREVBASE=net-ip-to-SOA
9 # Default values of zone parameters:
11 define(refresh, hours(8))
12 define(retry, hours(2))
13 define(expire, days(7))
14 define(minttl, days(1))
15 define(nsname, translit(esyscmd(`hostname -f'),`
17 define(maintname, `root'.`corr_dot(nsname)')
21 define(whole_domain, `ifdef(`REVERSE', `define(esrever,revaddr(REVBASE))esrever.in-addr.arpa', `Xdomain')'))
22 define(dotdomain, `ifelse(Xdomain,,,.Xdomain)')
24 # Generate reverse addressing if needed
26 define(stop_if_rev, `ifdef(`REVERSE', `divert(-1)')')
27 define(mk_PTR, `divert
28 revaddr(substr($1,incr(len(REVERSE)))) PTR $2`'ifelse(index($2,`.'),-1,`dotdomain.',`')')
30 define(mk_ptr, `ifelse(REVERSE, substr($1, 0, len(REVERSE)),`mk_PTR($1,$2)')')
31 define(emit_ptr, `ifdef(`REVERSE', `mk_ptr($1,$2)divert(-1)')')
35 define(ver_file, ifdef(`VERS',`VERS',`.nsc_version'))
36 define(today_code, translit(esyscmd(`date +"%y%m%d"'),`
39 ifelse(today_code, last_today_code, `', `define(`subver_num',1)')
40 syscmd(echo >ver_file "`define'(`last_today_code',today_code) `define'(`subver_num', incr(subver_num))")
41 define(Subver_num, format(`%02d', subver_num))
42 define(version,`today_code`'Subver_num')
44 # Host / Subdomain name
46 define(emit_name, `ifdef(`keep_addr', `keep_addr`'undefine(`keep_addr')', `$1')')
50 define(DO_SOA, `divert; Primary file for the whole_domain domain generated on curdate
52 corr_dot(whole_domain) `SOA' corr_dot(nsname) maintname (
53 version refresh retry expire minttl )')
54 define(SOA, `ifdef(`Xdomain',`define(`Xdomain',$1)',`define(`Xdomain',$1)DO_SOA')')
58 define(exNS, `emit_name `NS' corr_dot($1)
60 define(NS, `iterate(`exNS', `$@')dnl')
64 define(exMX, `emit_name `MX' corr_dot($1)
66 define(MX, `stop_if_rev`'iterate(`exMX', `$@')dnl')
70 define(HI, ` HINFO "$1" "$2"')
74 define(exH, `emit_ptr($1, cname) A $1
76 define(H, `define(`cname', $1)stop_if_rev`'$1`'iterate(`exH', `shift($@)')dnl')
78 # Reverse-only host records
80 define(exRH, `emit_ptr($1, cname)')
81 define(RH, `define(`cname', $1)stop_if_rev`'iterate(`exRH', `shift($@)')dnl')
85 define(D, `stop_if_rev`'define(`keep_addr', $1)define(`cname', $1)dnl')
87 # Addressless entry (for example mail alias)
89 define(HH, `define(`keep_addr', $1)define(`cname', $1)dnl')
93 define(exALIAS, `$1 CNAME cname
95 define(ALIAS, `iterate(`exALIAS', `$@')dnl')
100 localhost A 127.0.0.1
101 divert`'ifdef(`REVERSE',`