
# SCCS_ID - "@(#)setup_named (TWG)       3.7     88/11/11 "
#
#   @(#) Copyright 1986. The Wollongong Group, Inc.  All Rights Reserved.
#
PATH=$PATH:.;export PATH

# Prompt for yes or no answer - returns non-zero for no
#	askyn "\tIs this OK?" && {
#		# answered yes
#		isitok=ok
#	}
askyn() {
	while	echo "$* (y/n) \c">&2
	do	read yn rest
		case $yn in
		     [yY]) return 0 		                  ;;
	             [nN]) return 1		                  ;;
		        *) echo "\nPlease answer y, n, or q" >&2  ;;
		esac
	done
}

# input - String to display
# output - value in "$ansvalue"
askipvalue() {
	isitok=
	while [ "$isitok" = ""  ]
	do
		echo "Please enter $2 > \c"
		read ansvalue
		if [ "$ansvalue" = "" ]
		then
			if [ "$1" = "must" ]
			then
			    echo "\tYou must give an answer to the question"
			else
			    isitok="ok"
			fi
		else
			ansvalue=`inet_addr $ansvalue`
			code=$?
			if [ $code != 0 ]
			then
			    echo "\tThat is not a valid IP address, \c"
			    echo "please try again"
			else
			    echo "\t$2 = $ansvalue"
			    askyn "\tIs this OK?" && {
				# answered yes
				isitok="ok"
			    }
			fi
		fi
	done
}

#
# SETUP NAMESERVER 
#
UNAME="$1"
domain="$2"
RCFILE=/etc/rc2.d/S86wintcp

#
# install as a nameserver host
#
echo "removing /etc/resolv.conf"
rm /etc/resolv.conf > /dev/null 2>&1

#namesave="n"
#if [ -r /etc/named.boot.SAV ]
#then
#	askyn "do you wish to use the previously saved nameserver files?" && {
#		namesave=y
#	}
#	if [ "$namesave" = "y" ]
#	then
#		echo "restoring /etc/named.boot and directory /usr/local/domain "
#		cp /etc/named.boot.SAV /etc/named.boot > /dev/null 2>&1
#		if [ -r /etc/named.files ]
#		then
#			rm /usr/local/domain/*
#			cd /usr/local/domain; cpio -ic </etc/named.files 2> /dev/null
#		fi
#	fi
#
#fi

askipvalue must "the IP address for this server"
netnum=`./inet_net $ansvalue`

# following not needed for ARIX
## add domain name to hostname in $RCFILE
#ed -s $RCFILE <<DONE > /dev/null 2>&1
#/uname/d
#i
#/usr/bin/hostname \`uname -n\`.$domain > /dev/null 2>&1
#.
#w
#q
#DONE

# remove NONAMESERVER from $RCFILE
# enable named in $RCFILE
ed -s $RCFILE <<DONE > /dev/null 2>&1
/NONAMESERVER/s/^/#/
/\$ETC\/named/s/#//
w
q
DONE

ed -s /usr/local/domain/named.local <<DONE > /dev/null 2>&1
1,\$s/XDOMNAME/$domain/g
1,\$s/XHOSTNAME/$UNAME/g
w
q
DONE

ed -s /etc/named.boot <<! > /dev/null 2>&1
/XDOMNAME/s//$domain/
/XNETNUM/s//$netnum/
w
q
!

#
# remove NONAMESERVER from /etc/profile
#
found=`grep NONAMESERVER /etc/profile`
if [ "${found}" != "" ]
then
ed -s /etc/profile <<DONE > /dev/null 2>&1
/NONAMESERVER/d
w
q
DONE
fi

echo "Consult your Administrator's Guide for Domain setup"
echo "for the database files named.rev and named.hosts"
echo "Edit the nameserver files named.rev and named.hosts"
echo "before the system is rebooted. \n"
