#!/bin/sh
#pragma	ident	"@(#)install_nf 1.6     95/06/09 NPI"
#
#	Copyright (c) 1990, 1994 by Sun Microsystems, Inc.
#
#
#
#	install_nf:  Shell Script to Configure the Kernel for 
#		     Sunlink FDDI/S support.
#
#	Arguments:
#
#	Exit Conditions:
#
#	In any case where an error in this procedure is detected, an immediate
#	exit with a negative code will be taken.
#
#
PATH="/usr/ucb:/bin:/usr/bin:/etc:/usr/etc"
export PATH
ARCH=`arch`
ARCH_K=`arch -k`
INS="install"
ulib="/usr/lib"
SYS="sys"
SYS_PATH="/usr/share/$SYS"
SYS_INS="sys_$INS"
SYSN="System Config File"

#NF_PATH="/usr/sunlink/nf"
MYDIR=`dirname $0`
NF_PATH="`( cd $MYDIR/../ ; pwd )`"
NFS_PATH="$NF_PATH/$SYS"
NFI_PATH="$NF_PATH/$INS"

CONF="conf"
CONF_PATH="/$SYS/$ARCH_K/$CONF"
FILE="files"
GEN_ADD="GENERIC.add"
OSVER=`uname -r`
SNM_LIB="/usr/snm/lib/libnetmgt.so.*"
DATE=`date '+%m%d%y'`
DATE=$$
DRVNAME="nf"
#USERTEST=/usr/diag/sundiag/.usertest

RC_LOCAL="/etc/rc.local"
RC_LOCAL_TMP="/usr/tmp/rc.local.$$"

tmpIF=/tmp/`basename $0`.$$ 

maxinterfaces=16
trap cleanup 2

cleanup()
{
	j=0
	while [ $j -lt $maxinterfaces ]; do
		if [ -f /etc/hostname."$DRVNAME""$j" ]; then
			rm -f /etc/hostname."$DRVNAME""$j"
		fi
		j=`expr $j + 1`
	done
	exit 1


}


valid_field()
{
	nonNum=`echo "$1" | sed "s/[1-9][0-9]*//g"`
	if [ ! -z "$nonNum" ] ; then
		return 1
	fi
	if [ $1 -gt 255 -o $1 -lt 0 ] ; then
		return 1
	fi
	return 0
}

validate_addr_wrong()
{

	if [ $1 -lt 127 -a  $1 -gt 0 ] ; then   	# Class A address
		for n in $2 $3 $4 ; do
			if valid_field $n ; then
				return 1
			fi
		done
	else
		if [ $1 -gt 127 -a $1 -lt 192 ]; then 	# Class B address
			for n in $3 $4 ; do
				if valid_field $n ; then
					return 1
				fi
			done
		else					# Class C address
			if [ $1 -ge 192 -a $1 -lt 224 ]; then
				if valid_field $4 ; then
					return 1
				fi
			fi
		fi
	fi

	return 0


}

install_sundiag()
{
	touch -f $USERTEST
	mv -f $USERTEST $USERTEST.$DATE
	tar cf - usr/diag | (cd /; tar xpBf -)
	grep -v nf $USERTEST.$DATE >> $USERTEST
}

install_etc() 
{
	tar cf -         usr/etc | (cd /; tar xfp -)
	cd /usr/etc
	if [ -r nf_snmd ]; then
		rm nf_snmd
	fi
#	if [ ! -r $SNM_LIB ]; then
		ln -s nf_snmd-static nf_snmd
#	else
#		ln -s nf_snmd-shared nf_snmd
#	fi
}

modify_rcboot()
{
	grep -s "hostname.official" /etc/rc.boot
	if [ $? -eq 1 ]; then
		# no match and no error
		cp /etc/rc.boot /etc/rc.boot.$DATE
		awk '
		{
			if ($1 == "hostname=\"`shcat") {
				printf("if [ -r /etc/hostname.official ]; then\n");
				printf("	hostname=`shcat /etc/hostname.official 2>/dev/null`\n");
				printf("else\n");
				printf("	for hostfile in /etc/hostname.??0; do\n");
				printf("		if [ -r $hostfile ]; then\n");
				printf("			hostname=`shcat $hostfile 2>/dev/null`\n");
				printf("			break\n");
				printf("		fi\n");
				printf("	done\n");
				printf("fi\n");
			}
			else if ( \
				$1 == "if" && \
				$2 == "[" && \
				$3 == "\"$1\"" && \
				$4 == "!=" && \
				$5 == "\"xx0\"" && \
				$6 == "];" && \
				$7 == "then" \
				) {
				printf("\t\t\tif [ \"$1\" != \"xx0\" -a \"$1\" != \"official\" ]; then\n");
			}
			else print $0

		}
		' /etc/rc.boot.$DATE > /etc/rc.boot
	fi
	sync
}

isno()
{
	case $1 in
	n | no | nO | N | No | NO)
		return 0
		;;
	*)
		return 1
		;;
	esac
}

yp_active()
{
	# Returns 0 if NIS is up, non-zero if NIS is down.

	ypwhich 2>&1 >/dev/null
}

arg_contains_blanks()
{
	# returns 0 if the first argument contains blanks, non-zero otherwise.
	set -- $1
	test $# -gt 1
}

find_yp_hosts_entry()
{
	# usage: find_yp_hosts_entry <hostname>
	# Returns status 0, and update ipaddr if all goes well, 
	#         status 1 on error
	# Writes "<ip-address> <hostname>" to the standard output.

	hn=$1
	if arg_contains_blanks "$hn"; then
		return 1
	fi
	if he=`ypmatch $hn hosts 2>/dev/null`; then
		set -- $he
		# echo $1 $hn
		ipaddr=$1
		return 0
	else
		return 1
	fi
}


find_etc_hosts_entry()
{
	# usage: find_etc_hosts_entry <hostname>
	# Returns status 0, and update ipaddr if all goes well, 
	#         status 1 on error
	# Writes "<ip-address> <hostname>" to the standard output.

	hn=$1
	hosts=`echo $hosts $hn`
	if arg_contains_blanks "$hn"; then
		return 1
	fi

	cp /etc/hosts /etc/hosts.$DATE
	awk '
	{
		aa=0;
		lstate=0;
		nn=split($0, larr, " ");
		for (ll=1; ll<=nn; ll++) {
			if ( larr[ll] == "#" ) {
				aa=ll;	
				break;
			}
		} 
		if ( aa != 0 ) {
			if ( larr[aa+1] == ss )
			{
				for (iindex=1; iindex<aa; iindex++) {
					if ( larr[iindex] == hh) {
						print $0;	
					}
				}
			}
			else {
				for (iindex=1; iindex<aa; iindex++) {
					if ( larr[iindex] == hh) 
						lstate=1;
				}
				if ( lstate == 0 )
					print $0;
				else {
					printf ("%s	",larr[1]);
					for (iindex=2; iindex<aa; iindex++) {
						printf("%s ",larr[iindex]);
					}
					printf("			# %s\n", ss);
				}
			}
		}
		else {
			for (iindex=1; iindex<=nn; iindex++) {
				if ( larr[iindex] == hh) 
					lstate=1;
			}
			if ( lstate == 0 )
				print $0;
			else {
				printf ("%s	",larr[1]);
				for (iindex=2; iindex<=nn; iindex++) {
					printf("%s ",larr[iindex]);
				}
				printf("			# %s\n", ss);
			}
		}
					
	}' hh=$hn ss=$sig  /etc/hosts.$DATE > /etc/hosts

	if he=`awk -F# '{ print $1}' /etc/hosts | grep -w $hn` ; then
		set -- $he
		for i in $*; do
			if [ $i = $hn ]; then
				ipaddr=$1
				return 0
			fi
		done
		return 1
	else
		return 1
	fi
}
get_ipaddr()
{
# ------- Check IP address : exactly the same used in SVR4 ----
		msg="Illegal ip address... Try again" 
                fdone=0
               while [ $fdone -eq 0 ]; do
			echo -n "What ip address do you want to use for nf$j: "
#			read ipaddr
#			case $ipaddr in
#                while [ $fdone -eq 0 ]; do
#                        ip_addr=`ckstr -Q -d "$ipaddr" \
#                                        -p "What ip address do you want to use for $hostname [$ipaddr]: " \
#                                        -h "4 octet network address in dotted decimal notation." `
			read ip_addr
			case $ip_addr in
                                127.1 | 127.0.1 | 127.0.0.1 | 127.01)
                                        echo "$msg" ;  
                                        ;;
                                *)
#                                       if [ "aa$ipaddr" = "aa" ]; then    # NULL Address 
                                        if [ "aa$ip_addr" = "aa" ]; then    # NULL Address 
                                                echo "$msg"
					else	# I need 4 fields separeted by dot 
#						nfields=`echo $ipaddr | awk -F. ' {printf("%d", NF)}'`
						nfields=`echo $ip_addr | awk -F. ' {printf("%d", NF)}'`
                                                if [ $nfields != "4" ]; then
                                                        echo "$msg"
                                                else   # they must be numeric and < 255 
#                                                       set - `echo "$ipaddr" | sed "s/\./ /g"`
                                                        set - `echo "$ip_addr" | sed "s/\./ /g"`
							wrongField=0			
							for n in $1 $2 $3 $4 ; do
								# echo "checking <$n>"
#								nonNum=`echo "$n" | sed "s/[1-9][0-9]*//g"`
#								if [ ! -z "$nonNum" ] ; then
#									echo "$msg" ; 
#									wrongField=1;  
#									break
#								fi
								if [ $n -gt 255 -o $n -lt 0 ] ; then
									echo "$msg" 
									wrongField=1 ; break
								fi
							done
							if validate_addr_wrong $1 $2 $3 $4 ; then
									echo "$msg" 
									wrongField=1 ;
							fi

							if [ $wrongField -eq 0 ] ; then 
								fdone=1
							fi
                                                fi
                                        fi
                                        ;;
                                esac
                done
echo "The good IP address is <$ip_addr> "
}
h_count=0
check_dup_ipaddr()
{
        shift $h_count
        if [ $ip_addr = $1 ]; then
                return 0
        else
                return 1
        fi


}

check_dup_hostip()
{
        h_count=0
        for ih in $l_hosts
        do
                if [ $hostname = $ih ]; then
                        if  check_dup_ipaddr $ipaddrs  ; then
                                return 0
                        fi
                fi
                h_count=`expr $h_count + 1`
        done
        return 1
}

check_dup_hostname()
{
        for il in $l_hosts
        do
                if [ $hostname = $il ]; then
                	return 0
                fi
        done
        return 1
}

check_dup_ipaddr()
{
        for jl in $ipaddrs
        do
                if [ $ip_addr = $jl ]; then
                	return 0
                fi
        done
        return 1
}

update_etc_hosts()
{
	if [ $fquick -eq 0 ]; then
		echo ""
		maxinterfaces=16  # DEFAULT max interfaces 
		# Count how many cards are installed 
		cardname1=`devinfo | grep -w nf | wc -l `
		cardname2=`devinfo | grep -w sbf | wc -l `
		interfaces=`expr $cardname1 + $cardname2 `
		if [ $interfaces -eq 0  ]; then
			echo "The hardware is not properly installed."
			echo "Please, check it and then reinstall it by running: $0"
			exit 3
		fi
		echo "$interfaces FDDI (nf) interface(s) installed " 
	else
		interfaces=1
	fi
	j=0
	primaryAlreadySelected=0
	while [ $j -lt $interfaces ]; do
		sig="FDDI/SX$j"
		echo ""
		echo  "What host name do you want to use for nf$j: "
		echo -n "Hit  <RETURN> if you dont want a hostname : "
		read hostname
		if [ "aa$hostname" = "aa" ] ; then
			get_ipaddr
			if check_dup_ipaddr ; then
			   echo ""
			   echo "This hostname and IP address is already used for other interface....."
			   echo ""
			   continue
                        fi

			l_hosts=`echo $l_hosts $ip_addr`
			hosts=`echo $hosts $ip_addr`
			ipaddrs=`echo $ipaddrs $ip_addr`
			j=`expr $j + 1`
			continue
		else
			if [ $hostname = "loghost" ]; then
			        echo ""
			        echo "loghost is not a valid hostname....."
				continue
			fi
	
			if check_dup_hostname ; then
			   echo ""
			   echo "This hostname is already used for other interface....."
			   echo ""
				continue
			fi
		fi
		if [ $primaryAlreadySelected -eq 0 ] ; then
			if [ $fquick -eq 0 ]; then
				echo -n "Do you want to use $hostname as the primary hostname? "
				echo -n "(y|n) [y]: "
				read answer
				isno $answer
				if [ $? -eq 1 ]; then
					modify_rcboot
					echo $hostname > /etc/hostname.official
					primaryAlreadySelected=1
				fi
			fi
		fi
		echo $hostname > /etc/hostname.nf$j
		if yp_active; then
			ipaddr=""
			if find_yp_hosts_entry $hostname; then
				if find_etc_hosts_entry $hostname; then
					l_hosts=`echo $l_hosts $hostname`
					ipaddrs=`echo $ipaddrs $ipaddr`
					j=`expr $j + 1`
				else
					echo -n "$ipaddr	$hostname" >> /etc/hosts
					echo "			# $sig" >> /etc/hosts
					l_hosts=`echo $l_hosts $hostname`
					ipaddrs=`echo $ipaddrs $ipaddr`
					j=`expr $j + 1`
				fi
			else
				echo "$hostname is not in the NIS data base."
			fi
		else	# no yp
			if find_etc_hosts_entry $hostname; then
				l_hosts=`echo $l_hosts $hostname`
				ipaddrs=`echo $ipaddrs $ipaddr`
				j=`expr $j + 1`
			else
				get_ipaddr
				if check_dup_hostip; then
			                echo ""
			   		echo "This hostname and IP address is already used for other interface....."
			                echo ""
					continue
				fi

				while check_dup_ipaddr
				do
			   		echo "This IP address is already used for other interface....."
					get_ipaddr
					continue
				done

				ipaddrs=`echo $ipaddrs $ip_addr`
				l_hosts=`echo $l_hosts $hostname`

				echo ""
				echo -n "Modifying /etc/hosts to add $hostname $ipaddr ..." 
#				echo -n "$ipaddr	$hostname" >> /etc/hosts
				echo -n "$ip_addr	$hostname" >> /etc/hosts
				echo "			# $sig" >> /etc/hosts
				echo " done."
				j=`expr $j + 1`
			fi
		fi
	done
	echo ""
	sync
}

verify_owner()
{
	me=`whoami`
	if [ $me -ne "root" ]; then
	   echo "This script must be run as root ... fatal error"
	   exit 1
	fi
	if [ ! -w $NF_PATH ]; then
	    echo "No root write access to $NF_PATH .. fatal error"
	    exit 1
	fi
}

modify_rclocal()
{
	# usage: modify_rclocal linkable|no-autoload|autoload

	echo -n "Modifying rc.local to load nf driver at boot time"

	cp $RC_LOCAL $RC_LOCAL_TMP
	echo "."
	case $1 in
	autoload)
		BF=`grep '^[	 ]*ifconfig[	 ]bf[0-9]' $RC_LOCAL`
		if [ ! -z "$BF" ]; then
			echo "Keeping the SunLink FDDI/S 2.0 declaration."
		fi
		grep -s "ifconfig "$DRVNAME"" $RC_LOCAL
		if [ $? -eq 1 ]; then
			# no match and no error
			awk ' 
			{ 
				#
				# Remove an existing /etc/loadable
				# The new one will be just after the line PATH=
				#
				if ($0 ~ /if[	 ]\[ -f[	 ]\/etc\/loadable \]/ ) {
					state = 1;
				}
				if (! (($0 == "# Load loadable modules.") ||  \
				       ($0 ~ /^[	 ]*ifconfig[	 ]bf[0-9]/ ) || \
				       (state == 1))) {
					#
					# Write existing lines
					#
					print $0;
				}
				if ($1 == "fi" && state == 1) {
					state = 0; 
				}

				#
				# Add the declaration of the driver and ifconfig
				# after the first occurence of PATH=
				#
				if ((substr($1, 0, length("PATH=")) == "PATH=") && done == 0 ) {
					printf("\n");
					printf("# Load loadable modules.\n");
					printf("if [ -f /etc/loadable ]; then\n");
					printf("	/etc/loadable\n");
					printf("fi\n");
					#
					# The FDDI 2.0 declaration should be before
					# the 3.0
					if (bfconfig) {
						printf("#\n# SunLink FDDI/S 2.0\n");
						printf("# Must be configured before SunLink FDDI/S 3.0\n#\n");
						printf("%s\n#\n", bfconfig);
					}
					n = split(hosts, arhosts, " "); 
					printf("if [ `modstat | grep nf | wc -l` -eq 0 ]; then\n");
					printf("	echo \"The fddi driver has not been properly loaded.\" \n");
					printf("else\n"); 
					for (i=0; i<n; i++) { 
						printf("	ifconfig nf%d %s netmask + -trailers up\n", i, arhosts[i+1]);
					} 
					printf("fi\n");
					printf("\n");
					done = 1;
				} 
			} 
			' hosts="$hosts" bfconfig="$BF" $RC_LOCAL_TMP | \
			sed -e "1,$$s/in.routed;/in.routed -q;/" \
				-e "1,$$s/\' routed\'/\' routed -q\'/" \
				> $RC_LOCAL
		else
			awk ' 
			{ 
				if ($1 == "ifconfig" && $2 ~ /nf[0-9]/ ) { 
					if (done == 0) { 
						n = split(hosts, arhosts, " "); 
						for (i=0; i<n; i++) { 
							printf("	ifconfig nf%d %s netmask + -trailers up\n", i, arhosts[i+1]); 
						} 
						done = 1; 
					} 
				} 
				else print $0 
			} 
			' hosts="$hosts" bf="$BF" $RC_LOCAL_TMP | \
			sed -e "1,$$s/in.routed;/in.routed -q;/" \
				-e "1,$$s/\' routed\'/\' routed -q\'/" \
				> $RC_LOCAL
		fi
		;;
	esac

	echo -n "Do you want to run the SunNet Manager daemon? "
	echo -n "(y|n) [y]: "
	read answer
	isno $answer
	if [ $? -eq 1 ]; then
		grep -s "/usr/etc/nf_snmd" /etc/rc.local
		if [ $? -eq 1 ]; then
			# no match and no error
			echo "" >> /etc/rc.local
			echo "#" >> /etc/rc.local
			echo "# start up the SMT deamon" >> /etc/rc.local
			echo "#" >> /etc/rc.local
			echo "if [ -f /usr/etc/nf_snmd ]; then" >> /etc/rc.local
			echo "	/usr/etc/nf_snmd" >> /etc/rc.local
			echo "fi" >> /etc/rc.local
		fi
	fi

	# save the ifconfig commands in a temp file - run later on
	rm -f $tmpIF;  touch $tmpIF 
	i=0
	for h in $hosts ; do
		echo "ifconfig nf$i $h netmask + -trailers up" >> $tmpIF
		i=`expr $i + 1`
	done

	# End 
	sync
}

loadable_driver()
{
	cd $NF_PATH/sys/$ARCH_K/OBJ
	echo -n "Compiling $NF_PATH/sys/sunif/nf_conf.c ... "
	sun4m_35="`nm /vmunix | grep hat_pagecache   2>/dev/null`"
	if [ -z "$sun4m_35" ]; then
		cc -O -I/sys -DKERNEL -sparc -c ../../sunif/nf_conf.c
	else
		cc -O -I/sys -DSUN4M_35 -DKERNEL -sparc -c ../../sunif/nf_conf.c
	fi
	echo "done." 

	echo -n "Linking nf_conf.o with the other FDDI kernel object files ... "
	mcast="`nm /vmunix | grep ether_addmulti   2>/dev/null`"
	if [ -z "$mcast" ]; then
		ld -r -o nf.o if_nf.o smt.o nf_smtcore.o nf_conf.o
	else
		echo " "
		echo "  Found IP_MULTICAST extentions in /vmunix."
		echo "  Linking FDDI driver with IP_MULTICAST extensions."
		ld -r -o nf.o if_nf.mcast.o smt.mcast.o nf_smtcore.mcast.o nf_conf.o
	fi
	echo "done."
	mv nf.o $NF_PATH/usr/etc

	cd $NF_PATH
	# install_sundiag
	install_etc
	/usr/etc/nf.INSTALL

	# Make an entry in /etc/loadable to invoke /dev/$DRVNAME.LOAD if 
	# /dev/$DRVNAME.AUTOLOAD exists. 
	# A maximum of one such entry will be appended. Because this 
	# script can be run multiple times and we do not want to edit
	# the /etc/loadable file, the automatic loading of $DRVNAME on reboot
	# is conditional on both /dev/$DRVNAME.LOAD and /dev/$DRVNAME.AUTOLOAD.

	# if it does not exist, create /etc/loadable for all to use.
	# Make it executable and flag it as a borne shell script to
	# allow calling by root as /etc/loadable.
	if [ ! -f /etc/loadable ]; then
		echo "#" > /etc/loadable
		chmod u+x /etc/loadable
	fi
	grep -s ""$DRVNAME".LOAD" /etc/loadable
	      
	if [ $? -eq 1 ]; then
		# no match and no error
		echo "Creating script /etc/loadable used to load nf driver at boot time"
		echo "#"				>> /etc/loadable
		echo "# Load the $DRVNAME driver if desired." >> /etc/loadable
		echo "#"				>> /etc/loadable
		echo "if [ -f /dev/"$DRVNAME".LOAD ]; then" >> /etc/loadable
		echo "	if [ -f /dev/"$DRVNAME".AUTOLOAD ]; then" >> /etc/loadable
		echo "		/dev/"$DRVNAME".LOAD" >> /etc/loadable
		echo "	fi"				>> /etc/loadable
		echo "fi"				>> /etc/loadable
		echo ""					>> /etc/loadable
	fi

	touch /dev/"$DRVNAME".AUTOLOAD
	modify_rclocal "autoload"

	j=0
	while [ $j -lt $interfaces ]; do
		if [ -f /etc/hostname."$DRVNAME""$j" ]; then
			rm -f /etc/hostname."$DRVNAME""$j"
		fi
		j=`expr $j + 1`
	done
	sync				# for safety after writing /dev

	echo "nf loadable driver is installed"
	# echo "To load the nf driver do: /dev/nf.LOAD"
	# echo "To unload the nf driver do: /dev/nf.UNLOAD"

	# load nf driver automatically
	/dev/nf.LOAD

	# Configure & Bring the interfaces up
	if [ -r $tmpIF ] ; then
		echo "Configuring IP interfaces ..."	
		sh $tmpIF 
	else	 # something wrong; the file should be there 
		echo "Execute ifconfig by hand to configure and bring up the interfaces "
	fi
	rm -f $tmpIF


}

update_files()
{
	cp files files.$DATE
	awk '
	BEGIN {
		fnf = 0;
	}
	{
		n = split($1, array, "/")
		if (array[1] == "sunif" && array[2] == "nf_conf.c")
				fnf = 1;
		if (array[1] == "sunwindow") {
			if (fnf == 0) {
				printf("#\n");
				printf("# Support for the Sunlink FDDI/S Controller\n");
				printf("#\n");
				printf("sunif/smt.c          optional smt device-driver\n");
				printf("sunif/nf_smtcore.c   optional smt device-driver\n");
				printf("sunif/if_nf.c        optional nf device-driver\n");
				printf("sunif/nf_conf.c      optional nf device-driver\n");
				fnf = 1;
			}
		}
		if (array[1] != "sunif" || array[2] != "nf_tst.c")
			print $0;
	}
	' files.$DATE > files
}

update_conf()
{
	awk '
	BEGIN {
		fipcmessage = 0;
		fsnit = 0;
		fclone = 0;
	}
	{
		if ($2 == "IPCMESSAGE") {
			fipcmessage = 1;
		}
		if ($1 == "config") {
			if (fipcmessage == 0) {
				printf("#\n");
				printf("# The following options are for various System V IPC facilities.\n");
				printf("# Most standard software does not need them, although they are\n");
				printf("# used by SunGKS and some third-party software.\n");
				printf("#\n");
				printf("options IPCMESSAGE      # System V IPC message facility\n");
				printf("options IPCSEMAPHORE    # System V IPC semaphore facility\n");
				printf("options IPCSHMEM        # System V IPC shared-memory facility\n");
				printf("\n");
			}
		}
		if ($2 == "snit") {
			fsnit = 1;
		}
		if ($1 == "device-driver" || $2 == "clone") {
			if ($2 == "clone") {
				fclone = 1;
			}
			if (fsnit == 0) {
				printf("#\n");
				printf("# The following are for streams NIT support.  NIT is used by\n");
				printf("# etherfind, traffic, rarpd, and ndbootd.  As a rule of thumb,\n");
				printf("# NIT is almost always needed on a server and almost never\n");
				printf("# needed on a diskless client.\n");
				printf("#\n");
				printf("pseudo-device   snit        # streams NIT\n");
				printf("pseudo-device   pf      	# packet filter\n");
				printf("pseudo-device   nbuf        # NIT buffering module\n");
				printf("\n");
				fsnit = 1;
			}
			if (fclone == 0) {
				printf("#\n");
				printf("# The following is for the \"clone\" device, used with streams devices.\n");
				printf("# This is required if you include streams NIT support, RFS, or an audio\n");
				printf("# device.\n");
				printf("#\n");
				printf("pseudo-device   clone       # clone device\n");
				printf("\n");
				fclone = 1;
			}
		}
		print $0;
	}
	END {	
		printf("\n");
		printf("#\n");
		printf("# Support for the Sunlink FDDI/S Controller\n");
		printf("#\n");
		printf("pseudo-device   smt2     # smt is a hook for station management");
		printf("\n");
		printf("device-driver   nf      # FDDI/S ");
		printf("\n");
		printf("device nf0");
		printf("\n");
		printf("device nf1");
		printf("\n");
	}
	' $1 > $2
}


usage()
{
	echo "install_nf"
	exit
}

case $# in
0)
	fquick=0;
	;;
1)
 	if [ $1 != "-v" ]; then
 		usage
	fi
	fquick=0;
	;;
*)
	usage
	;;
esac

cd /
verify_owner
update_etc_hosts
loadable_driver

cleanup
echo ""
echo "FDDI has been installed and configured successfully."
echo "Please reboot your machine to insure correct system operation."
