zone-mk
changeset 9 c45415af9a4b
parent 8 a1eefce2bd5e
child 10 d7977be97fa1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zone-mk	Wed Jun 30 16:48:26 2010 +0200
@@ -0,0 +1,106 @@
+#! /bin/bash
+
+while getopts "d" opt; do
+	case $opt in
+	d)	opt_debug=1;;
+	?)	exit 1;;
+	esac
+done
+
+if test $# -lt 2; then
+	echo "usage: $0 kundennummer domain..." >&2
+	exit
+fi
+
+customer="$1"; shift
+start=$(date -I)
+
+# config
+source dnstools.conf
+
+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
+
+# 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)"
+
+	test -f $zonefile && { echo "$zonefile exists. Skipping $domain" >&2; continue; }
+	test -f $config && { echo "$config exists. Skipping $domain" >&2; continue; }
+
+	cat <<xxx >$zonefile
+\$ORIGIN $domain.
+\$TTL 1d
+@		IN SOA $this_host. $hostmaster. (
+		$(date +%Y%m%d00)	; serial
+		1d		; refresh
+		2h		; retry
+		7d		; expire
+		1d		; default ttl
+)
+
+		IN TXT		"invoice: $customer"
+		IN TXT		"start: $start"
+		IN TXT		"utf8: $utf8domain"
+
+		IN NS		$primary.
+		IN NS		$secondary.
+
+xxx
+
+	cat <<xxx >$config
+zone "$domain" {
+// Start: $start
+// Invoice: $customer
+// UTF8: $utf8domain
+	type master;
+	file "$master_dir/$domain/$domain.signed";
+	allow-transfer { $secondary_ip; };
+	allow-query { any; };
+};
+
+xxx
+done
+
+