#!/bin/sh
# $Cambridge: hermes/conf/bind/bin/addzone-master,v 1.5 2011/05/26 18:08:31 fanf2 Exp $

set -e

PATH="/opt/bind/bin:$PATH"
cd /spool/bind

case "$1" in
''|-*)
	echo 'usage: addzone-master <zone>' 1>&2
	exit 1
esac

zone="${1%.}"

if [ -f zd/"$zone" ]
then
	echo "$zone" already exists
	exit 1
else
	echo Adding "$zone"
fi

named-compilezone -F raw -o zd/"$zone" "$zone" /dev/stdin <<EOF
@ 1h SOA localhost. root.localhost.  1 1h 1000 1w 1h
  1h NS  localhost.
EOF

cd keys
dnssec-keygen -f KSK "$zone"
dnssec-keygen "$zone"
chmod g+r   K"$zone"*
chgrp named K"$zone"*

rndc addzone '"'"$zone"'" {
	type master;
	file "/zd/'"$zone"'";
	masterfile-format raw;
	auto-dnssec maintain;
	update-policy local;
};'

exit 0
