|
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 customer="$1"; shift |
|
16 start=$(date -I) |
|
17 |
|
18 # config |
|
19 source dnstools.conf |
|
20 |
|
21 secondary=$SECONDARY |
|
22 secondary_ip=${SECONDARY_IP:-$(dig +short $secondary)} |
|
23 |
|
24 this_host=${THIS_HOST:-$(hostname -f)} |
|
25 this_ip=${THIS_IP:-$(hostname -i)} |
|
26 this_domain=${THIS_DOMAIN:-$(hostname -d)} |
|
27 primary=${PRIMARY:-$this_host} |
|
28 |
|
29 hostmaster=${HOSTMASTER:-"hostmaster.$this_domain"} |
|
30 |
|
31 zone_conf_dir=${ZONE_CONF_DIR:-/etc/bind/zones.d} |
|
32 master_dir=${MASTER_DIR:-/etc/bind/master} |
|
33 |
|
34 if [ ! -d $master_dir ] |
|
35 then |
|
36 echo $master_dir nicht gefunden |
|
37 exit 1 |
|
38 fi |
|
39 |
|
40 if [ ! -d $zone_conf_dir ] |
|
41 then |
|
42 echo $zone_conf_dir nicht gefunden |
|
43 exit 1 |
|
44 fi |
|
45 |
|
46 # debug option |
|
47 if test $opt_debug; then |
|
48 cat <<xxx |
|
49 this host: $this_host [$this_ip] |
|
50 this domain: $this_domain |
|
51 primary: $primary |
|
52 secondary: $secondary [$secondary_ip] |
|
53 hostmaster: $hostmaster |
|
54 zone config directory: $zone_conf_dir |
|
55 xxx |
|
56 exit |
|
57 fi |
|
58 |
|
59 for utf8domain in "$@"; do |
|
60 domain=$(idn --quiet "$utf8domain") |
|
61 |
|
62 test -d $master_dir/$domain || mkdir $master_dir/$domain |
|
63 |
|
64 zonefile=$master_dir/$domain/$domain |
|
65 config=$zone_conf_dir/$domain |
|
66 |
|
67 echo "$domain ($utf8domain)" |
|
68 |
|
69 test -f $zonefile && { echo "$zonefile exists. Skipping $domain" >&2; continue; } |
|
70 test -f $config && { echo "$config exists. Skipping $domain" >&2; continue; } |
|
71 |
|
72 cat <<xxx >$zonefile |
|
73 \$ORIGIN $domain. |
|
74 \$TTL 1d |
|
75 @ IN SOA $this_host. $hostmaster. ( |
|
76 $(date +%Y%m%d00) ; serial |
|
77 1d ; refresh |
|
78 2h ; retry |
|
79 7d ; expire |
|
80 1d ; default ttl |
|
81 ) |
|
82 |
|
83 IN TXT "invoice: $customer" |
|
84 IN TXT "start: $start" |
|
85 IN TXT "utf8: $utf8domain" |
|
86 |
|
87 IN NS $primary. |
|
88 IN NS $secondary. |
|
89 |
|
90 xxx |
|
91 |
|
92 cat <<xxx >$config |
|
93 zone "$domain" { |
|
94 // Start: $start |
|
95 // Invoice: $customer |
|
96 // UTF8: $utf8domain |
|
97 type master; |
|
98 file "$master_dir/$domain/$domain.signed"; |
|
99 allow-transfer { $secondary_ip; }; |
|
100 allow-query { any; }; |
|
101 }; |
|
102 |
|
103 xxx |
|
104 done |
|
105 |
|
106 |