|
1 #! /bin/bash |
|
2 |
|
3 while getopts "d" opt; do |
|
4 case $opt in |
|
5 d) opt_debug=1;; |
|
6 ?) exit 1;; |
|
7 esac |
|
8 done |
|
9 |
|
10 if test $# -lt 2; then |
|
11 echo "usage: $0 kundennummer domain..." >&2 |
|
12 exit |
|
13 fi |
|
14 |
|
15 |
|
16 customer="$1"; shift |
|
17 start=$(date -I) |
|
18 |
|
19 # config |
|
20 |
|
21 secondary=hh.schlittermann.de |
|
22 this_host=ns1.eins.lan #${this_host=$(hostname -f)} |
|
23 this_ip=192.168.0.1 #${this_ip=$(hostname -i)} |
|
24 this_domain=eins.lan #${this_domain=$(hostname -d)} |
|
25 |
|
26 hostmaster=${hostmaster="hostmaster.$this_domain"} |
|
27 |
|
28 primary_dir=${primary_dir=/etc/bind/zones.d} |
|
29 master_dir=${master_dir=/etc/bind/master} |
|
30 |
|
31 test -d $primary_dir || mkdir $primary_dir |
|
32 test -d $master_dir || mkdir $master_dir |
|
33 |
|
34 secondary=${secondary?} |
|
35 secondary_ip=${secondary_ip=$(dig +short $secondary)} |
|
36 |
|
37 # debug option |
|
38 if test $opt_debug; then |
|
39 cat <<xxx |
|
40 this host: $this_host [$this_ip] |
|
41 this domain: $this_domain |
|
42 secondary: $secondary [$secondary_ip] |
|
43 hostmaster: $hostmaster |
|
44 primary directory: $primary_dir |
|
45 xxx |
|
46 exit |
|
47 fi |
|
48 |
|
49 for utf8domain in "$@"; do |
|
50 domain=$(idn --quiet "$utf8domain") |
|
51 |
|
52 test -d $master_dir/$domain || mkdir $master_dir/$domain |
|
53 |
|
54 zonefile=$master_dir/$domain/$domain |
|
55 config=$primary_dir/$domain |
|
56 |
|
57 echo "$domain ($utf8domain)" |
|
58 |
|
59 test -f $zonefile && { echo "$zonefile exists. Skipping $domain" >&2; continue; } |
|
60 test -f $config && { echo "$config exists. Skipping $domain" >&2; continue; } |
|
61 |
|
62 cat <<xxx >$zonefile |
|
63 \$ORIGIN $domain. |
|
64 \$TTL 1d |
|
65 @ IN SOA $this_host. $hostmaster. ( |
|
66 $(date +%Y%m%d00) ; serial |
|
67 1d ; refresh |
|
68 2h ; retry |
|
69 7d ; expire |
|
70 1d ; default ttl |
|
71 ) |
|
72 |
|
73 IN TXT "invoice: $customer" |
|
74 IN TXT "start: $start" |
|
75 IN TXT "utf8: $utf8domain" |
|
76 |
|
77 IN NS $this_host. |
|
78 IN NS $secondary. |
|
79 |
|
80 xxx |
|
81 |
|
82 cat <<xxx >$config |
|
83 zone "$domain" { |
|
84 // Start: $start |
|
85 // Invoice: $customer |
|
86 // UTF8: $utf8domain |
|
87 type master; |
|
88 file "$master_dir/$domain/$domain.signed"; |
|
89 allow-transfer { $secondary_ip; }; |
|
90 allow-query { any; }; |
|
91 }; |
|
92 |
|
93 xxx |
|
94 done |
|
95 |
|
96 |