--- a/zone-mk Wed Jul 21 14:04:05 2010 +0200
+++ b/zone-mk Thu Jul 22 12:44:14 2010 +0200
@@ -1,100 +1,99 @@
-#! /bin/bash
-
-while getopts "d" opt; do
- case $opt in
- d) opt_debug=1;;
- ?) exit 1;;
- esac
-done
+#!/usr/bin/perl -w
-if test $# -lt 2; then
- echo "usage: $0 kundennummer domain..." >&2
- exit
-fi
+use strict;
-customer="$1"; shift
-start=$(date -I)
-
-# config
-source dnstools.conf
-
-primary=$PRIMARY
-primary_ip=${PRIMARY_IP:-$(dig +short $primary)}
-secondary=$SECONDARY
-secondary_ip=${SECONDARY_IP:-$(dig +short $secondary)}
-
-this_host=${THIS_HOST:-$(hostname -f)}
-this_ip=${THIS_IP:-$(hostname -i)}
-this_domain=${THIS_DOMAIN:-$(hostname -d)}
-primary=${PRIMARY:-$this_host}
-
-hostmaster=${HOSTMASTER:-"hostmaster.$this_domain"}
-
-zone_conf_dir=${ZONE_CONF_DIR:-/etc/bind/zones.d}
-master_dir=${MASTER_DIR:-/etc/bind/master}
-
-if [ ! -d $master_dir ]
-then
- echo $master_dir nicht gefunden
- exit 1
-fi
-
-if [ ! -d $zone_conf_dir ]
-then
- echo $zone_conf_dir nicht gefunden
- exit 1
-fi
+if (@ARGV < 2) {
+ print "usage: zone-mk kundennummer domain ... \n";
+ exit 1;
+}
-# debug option
-if test $opt_debug; then
- cat <<xxx
-this host: $this_host [$this_ip]
-this domain: $this_domain
-primary: $primary
-secondary: $secondary [$secondary_ip]
-hostmaster: $hostmaster
-zone config directory: $zone_conf_dir
-xxx
- exit
-fi
-
-for utf8domain in "$@"; do
- domain=$(idn --quiet "$utf8domain")
-
- test -d $master_dir/$domain || mkdir $master_dir/$domain
-
- zonefile=$master_dir/$domain/$domain
- config=$zone_conf_dir/$domain
-
- echo "$domain ($utf8domain)"
+my $primary = "pu.schlittermann.de";
+my $secondary= "hh.schlittermann.de";
+my $zone_conf_dir= "/etc/bind/zones.d";
+my $master_dir = "/etc/bind/master";
+my $customer = shift @ARGV;
+chomp (my $primary_ip = `dig +short $primary`);
+chomp (my $secondary_ip = `dig +short $secondary`);
+chomp (my $this_host= `hostname -f`);
+chomp (my $this_ip= `hostname -i`);
+chomp (my $this_domain = `hostname -d`);
+chomp (my $time = `date +%Y%m%d00`);
+chomp (my $start= `date -I`);
+my $hostmaster = "hostmaster.$this_domain";
- test -f $zonefile && { echo "$zonefile exists. Skipping $domain" >&2; continue; }
- test -f $config && { echo "$config exists. Skipping $domain" >&2; continue; }
-
- tpage \
- --define start="$start" \
- --define domain="$domain" \
- --define time="$(date +%Y%m%d00)" \
- --define primary="$primary" \
- --define secondary="$secondary" \
- --define hostmaster="$hostmaster" \
- --define customer="$customer" \
- --define utf8domain="$utf8domain" \
- templates/named.zone \
- >$zonefile
-
- tpage \
- --define domain="$domain" \
- --define start="$start" \
- --define customer="$customer" \
- --define utf8domain="$utf8domain" \
- --define file="$master_dir/$domain/$domain" \
- --define primary_ip="$primary_ip" \
- --define secondary_ip="$secondary_ip" \
- templates/named.config \
- >$config
-
-done
+if (! -e $master_dir) {
+ print "$master_dir nicht vorhanden \n";
+ exit 1;
+}
+if (! -e $zone_conf_dir) {
+ print "$zone_conf_dir nicht vorhanden \n";
+ exit 1;
+}
+# legt fuer jede domain in @ARGV ein verzeichnis in $master_dir an.
+# schreibt aus den angegeben templates die dateien $zonefile und $config
+# in die entsprechenden verzeichnisse.
+
+foreach (@ARGV) {
+
+ chomp (my $domain = `idn --quiet "$_"`);
+ my $zonefile = "$master_dir/$domain/$domain";
+ my $config = "$zone_conf_dir/$domain";
+ my $utf8domain = "$_";
+
+ if (! -e "$master_dir/$domain") {
+ `mkdir $master_dir/$domain`;
+ }
+
+ if (-e $zonefile) {
+ $zonefile =~ s#/.*/##;
+ print "$zonefile exists. Skipping $domain\n";
+ next;
+ }
+ if (-e $config) {
+ $config =~ s#/.*/##;
+ print "$config exists. Skipping $domain\n";
+ next;
+ }
+
+ print "$domain ($_) for $customer \n";
+
+ open (TEMPZONE, "templates/named.zone");
+ my @tempzone = <TEMPZONE>;
+ close (TEMPZONE);
+
+ foreach (@tempzone) {
+ s#<start>#$start#;
+ s#<domain>#$domain#;
+ s#<time>#$time#;
+ s#<primary>#$primary#;
+ s#<secondary>#$secondary#;
+ s#<hostmaster>#$hostmaster#;
+ s#<customer>#$customer#;
+ s#<utf8domain>#$utf8domain#;
+ }
+
+ open (ZONEOUT, ">$zonefile");
+ print ZONEOUT @tempzone;
+ close (ZONEOUT);
+
+ open (TEMPCONF, "templates/named.config");
+ my @tempconf = <TEMPCONF>;
+ close (TEMPCONF);
+
+ foreach (@tempconf) {
+ s#<domain>#$domain#;
+ s#<start>#$start#;
+ s#<customer>#$customer#;
+ s#<utf8domain>#$utf8domain#;
+ s#<file>#$master_dir/$domain/$domain#;
+ s#<primary_ip>#$primary_ip#;
+ s#<secondary_ip>#$secondary_ip#;
+ }
+
+ open (CONFOUT, ">$config" );
+ print CONFOUT @tempconf;
+ close (CONFOUT);
+}