#!/bin/sh
#
#	$OpenBSD: bind9-disable,v 1.2 2001/10/08 23:01:51 jakob Exp $
#
#	this script disables BIND v9 by removing links created by
#	bind9-enable.

PREFIX=y0y0y0
BINDIR=/usr/sbin

if [ `id -u` -ne 0 ]; then
    echo "You must be root to run this script."
    exit
fi

echo "This script will remove BIND v9 links from $BINDIR"
echo ""
echo -n "Are you sure you want to to this (y/[n])? "

read answer
echo ""

if [ X$answer != Xy ]; then
    echo "exit"
    exit
fi

if [ ! -e /usr/sbin/lwresd ]; then
    echo "BIND v9 not enabled, script terminated."
    exit 
fi

######################################################################
echo "Removing BIND v9 links:"

for link in \
    dig host nslookup nsupdate \
    named rndc lwresd \
    dnssec-keygen dnssec-makekeyset dnssec-signkey dnssec-signzone \
    named-checkconf named-checkzone
do
    if [ -L $BINDIR/$link ]; then
        echo " $link"
        rm -f $BINDIR/$link
    fi
done

echo ""
echo done.

######################################################################
if [ ! -e /usr/sbin/named.dist ]; then
    echo "Couldn't find saved BIND v4 files, saved files not restored."
    exit 
else
    echo "Trying to restore BIND v4 files:"

    for file in \
	/usr/sbin/addr \
	/usr/sbin/dig \
	/usr/sbin/dnsquery \
	/usr/sbin/host \
	/usr/sbin/named \
	/usr/sbin/named.reload \
	/usr/sbin/named.restart \
	/usr/sbin/ndc \
	/usr/sbin/nslookup \
	/usr/share/man/cat1/dig.0 \
	/usr/share/man/cat1/dnsquery.0 \
	/usr/share/man/cat1/host.0 \
	/usr/share/man/cat8/named-xfer.0 \
	/usr/share/man/cat8/named.0 \
	/usr/share/man/cat8/named.reload.0 \
	/usr/share/man/cat8/named.restart.0 \
	/usr/share/man/cat8/ndc.0 \
	/usr/share/man/cat8/nslookup.0 \
	/usr/share/misc/nslookup.help \
	/var/named/named-xfer
    do
	if [ -e $file.dist ]; then
	    echo " $file"
	    mv $file.dist $file
	fi
    done

    echo ""
    echo done.
fi
