mkdomain
changeset 0 51d248a512a1
child 7 9cad6f1c5505
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mkdomain	Fri Jun 18 15:36:13 2010 +0200
@@ -0,0 +1,96 @@
+#! /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
+
+secondary=hh.schlittermann.de
+this_host=ns1.eins.lan #${this_host=$(hostname -f)}
+this_ip=192.168.0.1 #${this_ip=$(hostname -i)}
+this_domain=eins.lan #${this_domain=$(hostname -d)}
+
+hostmaster=${hostmaster="hostmaster.$this_domain"}
+
+primary_dir=${primary_dir=/etc/bind/zones.d}
+master_dir=${master_dir=/etc/bind/master}
+
+test -d $primary_dir || mkdir $primary_dir
+test -d $master_dir || mkdir $master_dir
+
+secondary=${secondary?}
+secondary_ip=${secondary_ip=$(dig +short $secondary)}
+
+# debug option
+if test $opt_debug; then
+	cat <<xxx
+this host:		$this_host [$this_ip]
+this domain:		$this_domain
+secondary:		$secondary [$secondary_ip]
+hostmaster:		$hostmaster
+primary directory:	$primary_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=$primary_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		$this_host.
+		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
+
+