#!/bin/sh
# $Cambridge: hermes/conf/bind/bin/delzone,v 1.3 2011/05/24 15:46:23 fanf2 Exp $

set -e

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

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

zone="${1%.}"
shift

cd /spool/bind

if [ -f zd/"$zone" ]
then
	rndc freeze $zone
	rndc delzone $zone
	BAK=BAK/$(date +%Y-%m-%d.%H:%M:%S)
	mkdir -p $BAK
	mv zd/"$zone" $BAK
	mv keys/K"$zone"*.key $BAK
	mv keys/K"$zone"*.private $BAK
	exit 0

elif [ -f zs/"$zone" ]
then
	rndc delzone $zone
	rm zs/"$zone"
	rm zs/"$zone".jnl
	exit 0
else
	echo 'delzone: unknown zone "'"$zone"'"' 1>&2
	exit 1
fi
