diff -r 05132262d212 -r 8715e7b706db zone-mk --- 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 <&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 = ; + close (TEMPZONE); + + foreach (@tempzone) { + s##$start#; + s##$domain#; + s#