:
#!/bin/ksh
# Bourne shell is broken on SVR4!!!!

#
#	faxconfig [-k] [-b] [-f] [-s] [-S] [-U]
#
#	Configure:
#		-k	FAX device drivers
#		-s	scanner device driver
#		-b	board configuration file
#		-f	fonts
#		-S	server parameters
#		-U	Rebuild UNIX kernel with current config
#		-u	Unbuild UNIX kernel without FAX or scanner driver
#		-i	Install UNIX kernel (if needed)
#		-e	Start Server
#		-d	Stop Server
#		-n	FAX notify Configuration
#		-p	FAX print Configuration
#
#	(c) Copyright 1990-1992 Digi Intl.  All Rights Reserved
#	(c) Copyright 1989,1990 PC Research, Inc.  All Rights Reserved
#
#	Hey, Moe, did you know that XENIX /bin/sh trashes the positional
#	parameters when you call a shell function?  Thus, there's
#	more than the usual grossness in this shell script.  The
#	grossness is identified by the (should be unnecessary) variables
#	prefixed by _funcname.
#	
#
#########################################################################
#									#
#	This section implements kernel configuration			#
#									#
#	For UNIX: adjust .../sdevice.d/DRVR and .../conf.d/mdevice	#
#	For XENIX: adjust .../$SYSxxx/DRVRconf.asm			#
#									#
#########################################################################

SCOMPANY="DigiBoard"
PRODUCT="DigiFAX"
HPRODUCT="DigiFAX FAX/1 or FAX/2"
SYSxxx="digiboard"
VER="2.8.0"
#
PRODVER="$PRODUCT $VER"
TMP=/tmp/faxconfig.dat
DEV=/dev
NA="(n/a)"
FDRIVERS="bfax dfax jfax"
SDRIVERS="hpsj sjii"
DRIVERS="$FDRIVERS $SDRIVERS"
#
#	When faxsrv has to spawn a command that needs an LUID, this
#	is the LUID that is used.
#
LUIDNAME=-Lroot
UMASK=-U0
#

DOKERNEL=y
if [ -f /xenix -o "$XENIX" != "" ]; then
	OPSYS=xenix
	SYS=/usr/sys
	CONF=$SYS/conf
	IO=$SYS/io
	SYSSUBDIR=$SYS/$SYSxxx
	MASTER=$CONF/master
elif [ -f /bin/hp-pa ]; then
	OPSYS=hpux
	CONF=/etc/conf
	MASTER=/etc/master
elif [ -d /kernel/drv ]; then
	OPSYS=sol
	DOKERNEL=n
else
	OPSYS=unix
	CONF=/etc/conf
	SDEVICE=$CONF/sdevice.d
	CF=$CONF/cf.d
	MDEVICE=$CF/mdevice
	MDEVICED=$CONF/mdevice.d
fi

#
#	In file $1, return the $3rd whitespace separated field
#       on the line matching pattern $2.  Field #'s 0-9.
#
getfield() {
	field=$3
	set `grep "$2" $1 || echo 0`
	eval echo "\$$field"
}
getfield10() {
	field=$3
	set `grep "$2" $1 || echo 0`
	shift 10
	eval echo "\$$field"
}

#
#	In file $1, change the line matching pattern $2
#	so that the $3'rd whitespace separated field has value $4
#
setfield() {
	ed - <<-EOF $1
	g/$2/s/[^ 	]\{1,\}/$4/$3
	w
	q
	EOF
}

#
#	Set shell variable $2 in file $1 to value $3
#
setshellvar () {
	ed - <<-EOF $1
	/^$2=/s/=[^#;]*/="$3"	/
	w
	q
	EOF
}

#
#	print value of shell variable $2 in file $1
#
getshellvar () {
	grep "^$2=" $1 | sed -e '2,$d' \
		-e "s/^$2=//" -e 's/[;#].*//' -e 's/"//'g -e 's/[ 	]*$//'
}

#
#	return capitalized version of $1
#
capname() {
	echo "$1" | tr '[a-z]' '[A-Z]'
}

#
#	safecp src dst
#
#	uninterruptible copy
#
safecp() {
	trap "" 1 2 3 15
	cp $*
	trap 1 2 3 15
}

#
#	pagehdr $*
#
pagehdr() {
	_pagehdr="$*"
	tput clear
	tput smso; tput el
	echo "	" $_pagehdr " "
	tput rmso
	unset _pagehdr
}

#
#	Define functions specific to O/S installation
#
#		get_info devname
#			name configure unit ipl type vector sioa eioa
#			scma ecma major dma
#		set_??? devname parms
#		build_kernel
#
case "$OPSYS" in
xenix)
	#
	#	SCO XENIX
	#
	link_error() {
		echo "Error: kernel link failed"
		echo "	Check $CONF/kmakelog for details"
		exit 1
	}
	conf_error() {
		echo "Error: configure failed to update system configuration"
		echo "	Check $CONF/conflog for details"
		exit 1
	}
	#
	#	create_nodes devname major
	#
	create_nodes() {
		grep "^;/etc/mknod" $SYSSUBDIR/${1}conf.asm | sed 's/^;//' > $TMP
		major=$2 /bin/sh $TMP
		rm $TMP
		chmod 600 $DEV/${1}*
	}

	#
	#	delete_nodes devname
	#
	delete_nodes() {
		rm -f $DEV/${1}* >/dev/null 2>&1
	}

	#
	#	delete_module	func
	#
	#	remove lines which reference "func" from link_xenix
	#
	delete_module() {
		(
			cd $CONF
			cp link_xenix link_xenix.tmp
			if grep -c "$1" link_xenix.tmp >/dev/null
			then
				ed - link_xenix.tmp <<-EOF
				g/$1/d
				w
				q
				EOF
			fi
			safecp link_xenix.tmp link_xenix
		)
	}

	#
	#	add_module	func
	#
	#	add lines which reference "func" to link_xenix
	#
	add_module() {
		(
			cd $CONF
			cp link_xenix link_xenix.tmp
			ed - link_xenix.tmp <<-EOF
			/libmdep/i
				$1 \\
			.
			w
			q
			EOF
			safecp link_xenix.tmp link_xenix
		)
	}

	#
	#	get_major devname
	#		return major number of devname or "" if not configured
	#
	get_major() {
		if major=`cd $CONF; ./configure -j $1`
		then
			echo $major
		fi
	}

	#
	#	delete_major major - delete driver from master file
	#
	delete_major() {
		(cd $CONF; ./configure -m $1 -c -d)
	}

	#
	#	new_major major - get next major number
	#
	new_major() {
		(cd $CONF; ./configure -j NEXTMAJOR)
	}

	#
	#	delete_driver name major - remove all traces of driver
	#
	delete_driver() {
		_dd1=$1
		_dd2=$2
		delete_major $_dd2		#fix master
		delete_module lib$_dd1.a	#fix link_xenix
		delete_module ${_dd1}conf.o	#fix link_xenix
		delete_nodes $_dd1		#fix /dev/...
		unset _dd1 _dd2
	}

	#
	#	add_driver name units		- configure in a new driver
	#
	add_driver() {
		_ad1=$1
		_ad2=$2
		_AD1=`capname $_ad1`
		major=`new_major`
		funcs=`getfield $SYSSUBDIR/${_ad1}conf.asm "^${_AD1}_FUNCTIONS" 3 \
						| sed 's/[<>,]/ /g'`
		# Watch it - add 16 to vector on XENIX
		case "$vector" in
		0)	vector=;;
		9)	vector="-v 25";;
		10)	vector="-v 26";;
		11)	vector="-v 27";;
		12)	vector="-v 28";;
		13)	vector="-v 29";;
		14)	vector="-v 30";;
		15)	vector="-v 31";;
		*)	vector="-v $vector";;
		esac
		if [ "Q$ipl" != Q0 ]
			then ipl="-l $ipl"; else ipl=; fi
		(
			cd $SYSSUBDIR
			/usr/lib/storel ${_ad1}conf.asm
		)
		(
			cd $CONF
			./configure -c -m $major $vector $ipl -a $funcs \
				> $CONF/conflog 2>&1
		) || conf_error
		add_module ../$SYSxxx/lib$_ad1.a	#fix link_xenix
		add_module ../$SYSxxx/${_ad1}conf.o	#fix link_xenix
		create_nodes $_ad1 $major
		unset _ad1 _AD1 _ad2
	}
	get_info() {	# devname
		name=$1
		if [ ! -r $SYSSUBDIR/${name}conf.asm ]; then
			return 1
		fi
		grep "^System" $SYSSUBDIR/${name}conf.asm >$TMP
		controllers=0
		units=0
		configured=N
		exec 3<&0 0<$TMP
		while read x x x \
			name$controllers x configure$controllers x \
			unit$controllers x ipl$controllers x \
			type$controllers x vector$controllers x \
			sioa$controllers x eioa$controllers x \
			scma$controllers x ecma$controllers x
		do
			eval configure=\$configure$controllers
			if [ "$configure" = Y ]
			then
				eval unit=\$unit$controllers
				units=`expr $units + $unit`
				configured=Y
			fi
			controllers=`expr $controllers + 1`
		done
		exec 0<&3 3<&-
		configure=$configure0
		unit=$unit0; ipl=$ipl0
		type=$type0; vector=$vector0
		sioa=$sioa0; eioa=$eioa0
		scma=$scma0; ecma=$ecma0
		grep "^Master" $SYSSUBDIR/${name}conf.asm >$TMP
		read x x x mname x function x chars x prefix x bmajor x \
			cmajor x min x max x dma x <$TMP
		rm $TMP
		return 0
	}

	set_units() {
		_su1=$1
		_su2=$2
		if [ "$3" = "" ]; then _su3=$_su1; else _su3=$3; fi
		if [ $_su2 = 0 ]; then _su4=N; else _su4=Y; fi
		setfield $SYSSUBDIR/${_su1}conf.asm $_su3 6 $_su4
		setfield $SYSSUBDIR/${_su1}conf.asm $_su3 8 $_su2
		unset _su1 _su2 _su3 _su4
	}
	set_vector() {
		setfield $SYSSUBDIR/${1}conf.asm "^System0" 14 $2
	}
	set_dma() {
		setfield $SYSSUBDIR/${1}conf.asm "^Master" 20 $2
	}
	set_ioa() {	# devname sioa eioa
		_su1=$1
		_su2=$2
		_su3=$3
		setfield $SYSSUBDIR/${_su1}conf.asm "^System0" 16 0${_su2}H
		setfield $SYSSUBDIR/${_su1}conf.asm "^System0" 18 0${_su3}H
		unset _su1 _su2 _su3
	}
	set_cma() {	# devname scma ecma
		_su1=$1
		_su2=$2
		_su3=$3
		setfield $SYSSUBDIR/${_su1}conf.asm "^System0" 20 0${_su2}H
		setfield $SYSSUBDIR/${_su1}conf.asm "^System0" 22 0${_su3}H
		unset _su1 _su2 _su3
	}
	build_kernel() {
		#
		# configure the drivers into master and link_xenix
		# the procedure we use is to first delete the driver
		# and its device nodes, then add it back in if needed
		#
		echo "Deleting previous FAX configuration..."
		for drv in $DRIVERS
		do
			major=`get_major $drv`
			if [ "$major" != "" ]
			then
				delete_driver $drv $major
			fi
			get_info $drv
			if [ "$?" = 0 -a "Q$configured" = QY ]
			then	# configure driver into kernel
				echo "Adding $drv driver..."
				add_driver $drv
			fi
		done
		echo "Linking new kernel..."
		( cd $CONF; ./link_xenix >kmakelog 2>&1 ) || link_error
	}
	unbuild_kernel() {
		for drv in $DRIVERS
		do
			major=`get_major $drv`
			if [ "$major" != "" ]
			then
				delete_driver $drv $major
			fi
		done
		( cd $CONF; ./link_xenix >kmakelog 2>&1 ) || link_error
	}
	install_kernel() {
		( cd $CONF; ./hdinstall )
	}
	;;
unix)
	#
	#	Genuine UNIX SVR3.2, SVR4.X (but not Solaris)
	#
	get_info() {	# devname
		controllers=0
		units=0
		configured=N
		if [ ! -r $SDEVICE/$1 ]; then
			return 1
		fi
		# "dma" field below for SVR4.1
		exec 3<&0 0<$SDEVICE/$1
		while read name$controllers configure$controllers \
			unit$controllers ipl$controllers type$controllers \
			vector$controllers sioa$controllers eioa$controllers \
			scma$controllers ecma$controllers dma$controllers
		do
			eval name=\$name$controllers
			if [ "Q$name" != "Q$1" ]; then
				continue;
			fi
			eval configure=\$configure$controllers
			if [ "$configure" = Y ]
			then
				eval unit=\$unit$controllers
				units=`expr $units + $unit`
				configured=Y
			fi
			controllers=`expr $controllers + 1`
		done
		exec 0<&3 3<&-
		name=$name0; configure=$configure0
		unit=$unit0; ipl=$ipl0
		type=$type0; vector=$vector0
		sioa=$sioa0; eioa=$eioa0
		scma=$scma0; ecma=$ecma0
		if [ -f "$MDEVICED/$1" ]; then
			grep $1 $MDEVICED/$1 >$TMP
			read mname function chars prefix bmajor cmajor \
				min max dma <$TMP
			dma=$dma0 # for SVR4.1, dma is in sdevice file
			min=0; max=8 # temp fix for SVR4.1
		else
			grep $1 $MDEVICE >$TMP
			read mname function chars prefix bmajor cmajor \
				min max dma <$TMP
		fi
		rm $TMP
		return 0
	}
	set_units() {	# devname NUNITS (0 = off) [pattern]
		_su1=$1
		_su2=$2
		if [ "$3" = "" ]; then _su3=$_su1; else _su3=$3; fi
		if [ $_su2 = 0 ]; then _su4=N; else _su4=Y; fi
		setfield $SDEVICE/$_su1 $_su3 2 $_su4
		setfield $SDEVICE/$_su1 $_su3 3 $_su2
		unset _su1 _su2 _su3 _su4
	}
	set_vector() {	# devname VECTOR
		setfield $SDEVICE/$1 $1 6 $2
	}
	set_dma() {	# devname DMACHAN
		if [ -f "$MDEVICED/$1" ]; then
			setfield $SDEVICE/$1 $1 11 $2
		else
			setfield $MDEVICE $1 9 $2
		fi
	}
	set_ioa() {	# devname START END
		_sio1=$1
		_sio2=$2
		_sio3=$3
		setfield $SDEVICE/$_sio1 $_sio1 7 $_sio2
		setfield $SDEVICE/$_sio1 $_sio1 8 $_sio3
		unset _sio1 _sio2 _sio3
	}
	set_cma() {
		_sio1=$1
		_sio2=$2
		_sio3=$3
		setfield $SDEVICE/$_sio1 $_sio1 9 $_sio2
		setfield $SDEVICE/$_sio1 $_sio1 10 $_sio3
		unset _sio1 _sio2 _sio3
	}
	build_kernel() {
		/etc/conf/bin/idbuild
		if [ $? != 0 ]
		then
			exit 1
		fi
	}
	unbuild_kernel() {
		for drv in $DRIVERS
		do
			set_units $drv 0
		done
		build_kernel
	}
	install_kernel() {
		# Not needed with UNIX - happens automatically at shutdown
		:
	}
	;;
hpux)
	add_dfile() {
		/system/TOOL/mod_dfile $1 add $2
	}
	bak_dfile() {
		if [ -f $1 ]; then
			cp $1 $1.bak
		fi
	}

	build_kernel() {
		(
			cd $CONF
			# We trust that the current dfile is correct...
			#bak_dfile dfile
			#/system/TOOL/get_kdfile /hp-ux > dfile
			/etc/config -m /etc/master dfile
			make -f config.mk
		)
	}
	unbuild_kernel() {
		(
			cd $CONF
			bak_dfile dfile
			/system/TOOL/get_kdfile /hp-ux > dfile
			/system/TOOL/mod_dfile dfile remove dfax
			/etc/config -m /etc/master dfile
			make -f config.mk
		)
	}
	install_kernel() {
		if [ -f $CONF/hp-ux ]; then
			cp /hp-ux /hp-ux.old
			mv $CONF/hp-ux /
			chmod 755 /hp-ux
		fi
	}
	;;
sol)	# Solaris 2.X
	# We don't ever need to build kernels for Solaris
	;;
*)
	echo "Unknown operating system $OPSYS"
	exit 1
	;;
esac

#
#	Ask yes/no question
#
yesno() {
	abortok=$1; shift
	for i in "$@"
	do
		echo "$i"
	done
	while :
	do
		echo
		if [ $abortok = 1 ]
		then
			echo "Type 'y' for yes, 'n' for no, 'a' to abort: \c"
		else
			echo "Type 'y' for yes, 'n' for no; then ENTER: \c"
		fi
		read yesans
		case "$yesans" in
		y|yes|Y|YES)	return 0;;
		n|no|N|NO)	return 1;;
		a|A)		if [ $abortok = 1 ]; then exit 1; fi;;
		esac
	done
}

#
#	Get hex value for description $1, variable $2
#
gethex() {
	hex="[0-9a-fA-F][0-9a-fA-f]*"
	while :
	do
		echo "Enter hexadecimal value for $1"
		echo "Or press 'q' to quit: \c"
		read ans
		x=
		case "$ans" in
		q)		return;;
		0x*|0X*)	x=`expr "$ans" : "0[xX]\($hex\)$"`;;
		*)		x=`expr "$ans" : "\($hex\)$"`;;
		esac
		if [ "$x" != "" ]; then eval $2=0x$x; return; fi
	done
}

#
#	Report info about device driver $1
#
#	devinfo "hdr"			- print header only
#	devinfo device "data"		- get data only
#	devinfo device 			- print data only
#	devinfo device "addr"		- print I/O addresses
#
devinfo() {
	if [ "$1" = "hdr" ]
	then
		echo "	DEVICE	TURNED	UNITS	INTR.	 DMA	LONG"
		echo "	 NAME	  ON?	AVAIL	VECTOR	CHAN.	DESCRIPTION"
		echo "	------	------	------	------	------	-----------"
		return
	fi
	_devinfo1=$1
	_devinfo2=$2
	case "$_devinfo1" in
	bfax)	desc="Brooktrout TR111/TR112"; type=1;;
	dfax)	desc="$HPRODUCT"; type=0;;
	jfax)	desc="JT FAX 9600"; type=0;;
	esac
	get_info $_devinfo1
	if [ "$?" != 0 ]; then
		echo "	$_devinfo1	DRIVER NOT INSTALLED ON SYSTEM	$desc"
		
		return 1
	fi
	if [ "$_devinfo2" = "data" ]; then return 0; fi
	if [ "$type" = "0" ]; then vector="$NA"; fi
	if [ "$dma" = "-1" ]; then dma="$NA"; fi
	echo "	$_devinfo1	$configured	$units	$vector	$dma	$desc"
	if [ "$_devinfo2" != addr ]; then return 0; fi
	if [ "$controllers" = 1 ]; then return 0; fi
	echo
	echo "	IO ADDRESS	ENABLED"
	echo "	START  END"
	echo "	----------	-------"
	i=0
	while [ $i -lt $controllers ]
	do
		eval sioa=\$sioa$i
		eval eioa=\$eioa$i
		eval configure=\$configure$i
		echo "	$sioa    $eioa	$configure"
		i=`expr $i + 1`
	done
	return 0
}

set_all_units() {
	ans=999
	while [ "$ans" -lt 0 -o "$ans" -gt $max ]
	do
		echo "Enter Number of units to include ($min-$max),"
		echo "0 to turn the device off, or q when done: \c"
		read ans
		case "$ans" in
		0)	set_units $_devcfg1 0
			return 0;;
		q)	return 0;;
		esac
	done
	set_units $_devcfg1 $ans
	return 1
}

set_io_units() { # set_io_units units_per_ctrl
	_siu1=$1
	hex="[0-9a-fA-F][0-9a-fA-f]*"
	while :
	do
		echo "Enter hexadecimal starting IO address to enable/disable,"
		echo "0 to turn all units off, or q when done: \c"
		read ioaddr
		x=
		case "$ioaddr" in
		q)		return 0;;
		0)		set_units $_devcfg1 0
				return 0;;
		0x*|0X*)	x=`expr "$ioaddr" : "0[xX]\($hex\)$"`;;
		*)		x=`expr "$ioaddr" : "\($hex\)$"`;;
		esac
		if [ "$x" != "" ]; then break; return; fi
	done
	yesno 0 "Do you want to enable the board at io address $x?"
	if [ $? = 0 ]
	then
		set_units $_devcfg1 $_siu1 $x
	else
		set_units $_devcfg1 0 $x
	fi
	return 1
}

#
#	Configure a single device driver named $1
#
devcfg() {
	done=0
	_devcfg1=$1
	while [ $done = 0 ]
	do
		pagehdr "$PRODVER \"$_devcfg1\" Device Driver Configuration"
		echo
		devinfo hdr
		devinfo $_devcfg1 addr
		if [ "$?" != 0 ]; then
			return
		fi

		echo
		if [ $controllers -eq 1 ]
		then
			if set_all_units; then return; fi
		else
			# Implies dfax - should generalize someday
			if set_io_units 2; then return; fi
		fi

		if [ "$vector" != "$NA" ]
		then
			echo
			ans=999
			while [ "$ans" -lt 2 -o "$ans" -gt 15 ]
			do
				echo "Enter Interrupt Vector for board (2-15),"
				echo "or q to QUIT: \c"
				read ans
				case "$ans" in
				q)	return;;
				esac
			done
			set_vector $_devcfg1 $ans
		fi

		if [ "$dma" != "$NA" ]
		then
			echo
			ans=
			while [ "$ans" != 1 -a "$ans" != 3 ]
			do
				echo "Enter DMA channel for board (1 or 3),"
				echo "or q to QUIT: \c"
				read ans
				case "$ans" in
				q)	return;;
				esac
			done
			set_dma $_devcfg1 $ans
		fi
	done
}

#
#	Configure Kernel Device Drivers Menu
#
kerncfg() {
	if [ "$OPSYS" = hpux ]; then
		pagehdr "$PRODVER Kernel Device Driver Configuration"
		echo

		HERE=`pwd`
		cd $CONF
		bak_dfile dfile

		echo "I can get the current configuration from the currently"
		echo "booted /hp-ux, or from the contents of your $CONF/dfile."
		echo
		echo "Do you want me to use the current $CONF/dfile [y/n]? \c"
		read ans
		if [ "Q$ans" != Qy ]; then
			/system/TOOL/get_kdfile /hp-ux > dfile
		fi
		grep -c dfax dfile >/dev/null \
			|| /system/TOOL/mod_dfile dfile add dfax
		cd $HERE

		echo
		echo "The dfax driver has been added to kernel configuration."
		echo "You must run eisa_config when the board is installed."
		echo
		echo "Press enter to continue: \c"
		read a
		return
	fi

	while :
	do
		pagehdr "$PRODVER Kernel Device Driver Configuration"
		echo
		devinfo hdr
		for ans in $FDRIVERS
		do
			devinfo $ans
		done
		echo
		echo "NOTE: at least one of the above device drivers should be turned"
		echo "      on in order to operate the FAX system with internal boards."
		echo
		echo "Enter a device name to modify, or q when done: \c"
		read ans
		case "$ans" in
		b*)	devcfg bfax;;
		d*)	devcfg dfax;;
		j*)	devcfg jfax;;
		q)	return;;
		esac
	done
}

#########################################################################
#									#
#	This section implements scanner configuration			#
#									#
#########################################################################
#
#	Report info about scanner driver $1
#
hpsjinfo() {
	if [ "$1" = "hdr" ]
	then
		echo "	DEVICE	TURNED	UNITS	  IO	 MEM	LONG"
		echo "	 NAME	  ON?	AVAIL	 ADDR	 ADDR	DESC."
		echo "	------	------	------	------	------	------"
		return
	fi
	_hpsjinfo1=$1
	case "$_hpsjinfo1" in
	hpsj)	desc="HP ScanJet, ScanJet Plus";;
	sjii)	desc="HP ScanJet IIp, IIc";;
	esac
	get_info $_hpsjinfo1
	if [ "$?" != 0 ]; then
		echo "	$_hpsjinfo1	DRIVER NOT INSTALLED ON SYSTEM	$desc"
		return 1
	fi
	case "$_hpsjinfo1" in
	sjii)	sioa="N/A";;
	esac
	echo "	$_hpsjinfo1	$configure	$unit	$sioa	$scma	$desc"
	unset _hpsjinfo1
}

hpsjswitches() {
	cat <<EOF
	C0000	Switches 4,3,2 are 000
	C4000	Switches 4,3,2 are 001
	C8000	Switches 4,3,2 are 010
	CC000	Switches 4,3,2 are 011
	D0000	Switches 4,3,2 are 100
	D4000	Switches 4,3,2 are 101
	D8000	Switches 4,3,2 are 110
	DC000	Switches 4,3,2 are 111
EOF
}

sjiiswitches() {
	cat <<EOF
	C8000	Switches 1,2,3,4 are 1110	(1 means "open")
	CC000	Switches 1,2,3,4 are 1010
	D0000	Switches 1,2,3,4 are 1100
	D4000	Switches 1,2,3,4 are 1000
	D8000	Switches 1,2,3,4 are 1111
	DC000	Switches 1,2,3,4 are 1011
	E0000	Switches 1,2,3,4 are 1101
	E4000	Switches 1,2,3,4 are 1001
EOF
}

#
#	Configure a scanner device driver named $1
#
hpsjcfg() {
	done=0
	_hpsjcfg1=$1
	while [ $done = 0 ]
	do
		pagehdr "$PRODVER \"$_hpsjcfg1\" Device Driver Configuration"
		echo
		hpsjinfo hdr
		hpsjinfo $_hpsjcfg1

		echo
		ans=999
		while [ "$ans" -ne 1 ]
		do
			echo "Enter 1 to turn device on,"
			echo "0 to turn the device off, or q when done: \c"
			read ans
			case "$ans" in
			0)	set_units $_hpsjcfg1 0
				return;;
			q)	return;;
			esac
		done
		set_units $_hpsjcfg1 $ans

		case $_hpsjcfg1 in
		hpsj)
			echo
			ans=999
			while [ "$ans" -ne 268 -a "$ans" -ne 278 ]
			do
				echo "Enter Starting IO Address for board:,"
				echo "	268	Switch 1 is 1, recommended"
				echo "	278	Switch 1 is 0, same as LPT2"
				echo "or q to QUIT: \c"
				read ans
				case "$ans" in
				268)	eans=26f;;
				278)	eans=27f;;
				q)	return;;
				esac
			done
			set_ioa $_hpsjcfg1 $ans $eans
			;;
		esac

		echo
		ans=0
		while [ "$ans" = 0 ]
		do
			echo "Enter Starting Memory Address for board:"

			case $_hpsjcfg1 in
			hpsj) hpsjswitches;;
			sjii) sjiiswitches;;
			esac

			echo "or q to QUIT: \c"
			read ans
			case "$ans" in
			c0000|C0000)	eans=C3FFF;;	#hpsj only
			c4000|C4000)	eans=C7FFF;;	#hpsj only
			c8000|C8000)	eans=CBFFF;;
			cc000|CC000)	eans=CFFFF;;
			d0000|D0000)	eans=D3FFF;;
			d4000|D4000)	eans=D7FFF;;
			d8000|D8000)	eans=DBFFF;;
			dc000|DC000)	eans=DFFFF;;
			e0000|E0000)	eans=E3FFF;;	#sjii only
			e4000|E4000)	eans=E7FFF;;	#sjii only
			q)	return;;
			*)	ans=0;;
			esac
		done
		set_cma $_hpsjcfg1 $ans $eans
	done
}

#
#	Configure Scanner Device Drivers Menu
#
scancfg() {
	if [ "$OPSYS" = hpux ]; then
		pagehdr "$PRODVER Scanner Device Driver Configuration"
		echo
		echo "Scanners not supported on HP-PA"
		echo
		echo "Press enter to continue: \c"
		read a
		return
	fi

	while :
	do
		pagehdr "$PRODVER Scanner Device Driver Configuration"
		echo
		hpsjinfo hdr
		for ans in $SDRIVERS
		do
			hpsjinfo $ans
		done
		echo
		echo
		echo "Enter a device name to modify, or q when done: \c"
		read ans
		case "$ans" in
		hpsj)	hpsjcfg hpsj;;
		sjii)	hpsjcfg sjii;;
		q)	return;;
		esac
	done
}

#########################################################################
#									#
#	This section implements kernel rebuilding			#
#									#
#########################################################################
buildkernel() {
	pagehdr "$PRODVER Build New Operating System"
	echo
	build_kernel
}

#########################################################################
#									#
#	This section implements kernel installation			#
#									#
#########################################################################
installkernel() {
	pagehdr "$PRODVER Install New Operating System"
	echo
	install_kernel
}

#########################################################################
#									#
#	This section implements kernel unbuilding			#
#									#
#########################################################################
unbuildkernel() {
	pagehdr "$PRODVER Build New Operating System without FAX"
	echo
	unbuild_kernel
}

#########################################################################
#									#
#	This section implements board configuration			#
#									#
#########################################################################

SPOOLDIR=/usr/spool/fax
FAXCONFIG=$SPOOLDIR/faxconfig
CLASS2OPTS=$SPOOLDIR/class2opts
#	variables which are set from - options
boardopts="type device addr chan hdr scan rcv xmit quiet debug lock phdr"
#	variables which are set from xxx=yyy lines
boardvars="dialtone didparm prefix callprog asciiok class2opts txecm rxecm"
boardvars="$boardvars maxtxspeed mintxspeed maxrxspeed minrxspeed"
boardvars="$boardvars initcmd dataspeed hangupdelay"

#########################################################################
#	Routines for reading /usr/spool/fax/faxconfig			#
#########################################################################
#
#	Set 'array' variables for a single board from values passed in as $*
#
setboardvars() {
	eval rcv$n=0;
	eval xmit$n=0;
	eval quiet$n=0;
	for i in $boardvars
	do
		eval FAX$i$n=\$"FAX$i"
	done
	for i in $*
	do
		case $i in
		-T) eval type$n="$2"; shift 2;;
		-T*) eval type$n=`expr "$1" : "..\(.*\)"`; shift;;
		-D) eval device$n="$2"; shift 2;;
		-D*) eval device$n=`expr "$1" : "..\(.*\)"`; shift;;
		-A) eval addr$n="$2"; shift 2;;
		-A*) eval addr$n=`expr "$1" : "..\(.*\)"`; shift;;
		-C) eval chan$n="$2"; shift 2;;
		-C*) eval chan$n=`expr "$1" : "..\(.*\)"`; shift;;
		-h) eval hdr$n='$2'; shift 2;;
		-h*) eval hdr$n=`expr "$1" : "..\(.*\)"`; shift;;
		-H) eval phdr$n='$2'; shift 2;;
		-H*) eval phdr$n=`expr "$1" : "..\(.*\)"`; shift;;
		-s) eval scan$n="$2"; shift 2;;
		-s*) eval scan$n=`expr "$1" : "..\(.*\)"`; shift;;
		-r) eval rcv$n=1; shift;;
		-t) eval xmit$n=1; shift;;
		-q) eval quiet$n=1; shift;;
		-d) eval debug$n="$2"; shift 2;;
		-d*) eval debug$n=`expr "$1" : "..\(.*\)"`; shift;;
		-L) eval lock$n="$2"; shift 2;;
		-L*) eval lock$n=`expr "$1" : "..\(.*\)"`; shift;;
		esac
	done
}

#
#	Read faxconfig file and store data into shell variables
#	set "n" to number of fax boards encountered
#
getboards () {
	if [ ! -f $FAXCONFIG ]
	then
		> $FAXCONFIG
	fi
	# Null out the default board variables
	for i in $boardvars
	do
		eval FAX$i=
	done
	exec 3<&0 0<$FAXCONFIG
	n=0
	while read a b
	do
		case "$a" in
		\#*)	continue;;
		"")	continue;;
		faxrun)
			n=`expr $n + 1`
			# eval setboardvars $b
			eval setboardvars "$b"
			;;
		[a-zA-Z_]*)
			id="[a-zA-Z0-9_]*"
			ws="[ 	]*"
			name=`expr "$a $b" : "\($id\)$ws=$ws.*"`
			if [ "$name" = "" ]
			then
				name="$a"; arg="$b"
			else
				if [ "Q$b" = Q ]; then
					arg=`expr "$a" : "$id$ws=$ws\(.*\)"`
				else
					arg=`expr "$a $b" : "$id$ws=$ws\(.*\)"`
				fi
			fi
			eval FAX$name='$arg'
			;;
		esac
	done
	exec 0<&3 3<&-
}

#########################################################################
#	Routines for writing /usr/spool/fax/faxconfig			#
#########################################################################
#
#	Write variable named $1 if value for board $2 is different
#	from the last time it was written
#
putvar() {
	eval bv=\$FAX$1$2
	eval lv=\$FAX$1
	if [ "$bv" != "$lv" ]
	then
		case "$1" in
		prefix) ;;
		class2opts) ;;
		initcmd) ;;
		*)	if [ "$bv" = "" ]; then bv=0; fi;;
		esac
		echo "$1	=	$bv"
		eval FAX$1='$bv'
	fi
}

#
#	Write info about board number $1
#
putboard() {
	_pb1=$1
	eval x=\$type$_pb1; if [ "$x" = "" ]; then return; fi
	echo
	for _pbi in $boardvars
	do
		putvar $_pbi $_pb1
	done
	eval echo "faxrun -T \$type$_pb1\\\c"
	eval x=\$device$_pb1; if [ "$x" != "" ]; then echo " -D $x\c"; fi
	eval x=\$addr$_pb1; if [ "$x" != "" ]; then echo " -A $x\c"; fi
	eval x=\$chan$_pb1; if [ "$x" != "" ]; then echo " -C $x\c"; fi
	eval x="\$hdr$_pb1"; if [ "$x" != "" ]; then echo " -h \"$x\"\c"; fi
	eval x="\$phdr$_pb1"; if [ "$x" != "" ]; then echo " -H \"$x\"\c"; fi
	eval x=\$rcv$_pb1; if [ "$x" = "1" ]; then echo " -r\c"; fi
	eval x=\$xmit$_pb1; if [ "$x" = "1" ]; then echo " -t\c"; fi
	eval x=\$quiet$_pb1; if [ "$x" = "1" ]; then echo " -q\c"; fi
	eval x=\$debug$_pb1; if [ "$x" != "" ]; then echo " -d $x\c"; fi
	eval x=\$lock$_pb1; if [ "$x" != "" ]; then echo " -L $x\c"; fi
	echo
	unset _pb1 _pbi
}

#
#	write board info
#
putboards() {
	echo
	if [ "$FAXmax_tries" != "" ]; then
		echo "max_tries	=	$FAXmax_tries"
	fi
	if [ "$FAXwait_times" != "" ]; then
		echo "wait_times	=	$FAXwait_times"
	fi
	if [ "$FAXdebug" != "" ]; then
		echo "debug	=	$FAXdebug"
	fi
	if [ "$FAXroundrobin" != "" ]; then
		echo "roundrobin	=	$FAXroundrobin"
	fi
	if [ "$FAXkeeppartial" != "" ]; then
		echo "keeppartial	=	$FAXkeeppartial"
	fi
	if [ "$FAXsendpartial" != "" ]; then
		echo "sendpartial	=	$FAXsendpartial"
	fi
	if [ "$FAXretrywarning" != "" ]; then
		echo "retrywarning	=	$FAXretrywarning"
	fi
	if [ "$FAXlognickname" != "" ]; then
		echo "lognickname	=	$FAXlognickname"
	fi
	if [ "$FAXlogattempts" != "" ]; then
		echo "logattempts	=	$FAXlogattempts"
	fi
	if [ "$FAXsamenumber" != "" ]; then
		echo "samenumber	=	$FAXsamenumber"
	fi

	for i in $boardvars
	do
		eval FAX$i=
	done
	i=1
	while [ $i -le $n ]
	do
		putboard $i
		i=`expr $i + 1`
	done
}

#
#	Update faxconfig file
#
putfaxconfig() {
	#
	#	Make copy of faxconfig file and clear out old data
	#
	cp $FAXCONFIG $FAXCONFIG.new
	ed - <<-EOF $FAXCONFIG.new
	g/^[^#]/d
	g/^$/d
	w
	q
	EOF

	#
	#	Write new config information to file and rename it
	#
	putboards >> $FAXCONFIG.new
	mv -f $FAXCONFIG $FAXCONFIG.old
	mv -f $FAXCONFIG.new $FAXCONFIG
}

#########################################################################
#	Routines for displaying /usr/spool/fax/faxconfig		#
#########################################################################
#
#	Display the stats for board number $1 [long]
#
dispboardvars() {
	t="	"
	d="-------"
	if [ $1 = "hdr" ]
	then
		echo "CHANNEL${t}TYPE${t}IO-ADDR${t}RECV\c"
		echo "${t}RX-SCAN${t}DIALTON${t}QUIET${t}DEVICE NAME"
		echo "${t}${t}DMACHAN${t}XMIT\c"
		echo "${t}DIDPARM${t}PREFIX${t}DEBUG${t}FAX-ID"
		echo "$d$t$d$t$d$t$d$t$d$t$d$t$d$t---------------------"
		return
	fi
	eval _type="\$type$1"; if [ "$_type" = "" ]; then return; fi
	eval _addr="\$addr$1"
	eval _rcv="\$rcv$1";
	if [ "$_rcv" = 1 ]; then _rcv=disabld; else _rcv=enabled; fi
	eval _scan="\$scan$1"
	if [ "$_scan" = "" ]; then _scan="default"; fi
	eval _dial="\$FAXdialtone$1"
	if [ "$_dial" = "0" ]; then _dial=Ignore; fi
	eval _quiet="\$quiet$1"
	if [ "$_quiet" = "1" ]; then _quiet="SpkrOff"; else _quiet="SpkrOn"; fi
	eval _device="\$device$1"
	if [ "$_device" = "" ]; then _device="(not set yet)"; fi
	eval _chan="\$chan$1"
	if [ "$_chan" = "" ]; then _chan="(unset)"; fi
	eval _xmit="\$xmit$1"
	if [ "$_xmit" = 1 ]; then _xmit=disabld; else _xmit=enabled; fi
	eval _did="\$FAXdidparm$1"
	eval _prefix="\$FAXprefix$1"
	if [ "$_prefix" = "" ]; then _prefix="(none)"; fi
	eval _debug="\$debug$1"
	if [ "$_debug" = "" ]; then _debug="(off)"; fi
	eval _hdr="\$hdr$1"
	if [ "$_hdr" = "" ]; then _hdr="(none)"; fi

	case "$_type" in
	efax)
		_addr="(n/a)";
		_chan="(n/a)";
		_did="(n/a)";
		_ltype="        SP 2388"
		;;
	jfax)
		_addr="(n/a)";
		_chan="(n/a)";
		_did="(n/a)";
		_ltype="    JT FAX 9600"
		;;
	wfax)
		_addr="(n/a)";
		_chan="(n/a)";
		_did="(n/a)";
		_ltype="      Worldport"
		;;
	dfax)
		_addr="(n/a)";
		_chan="(n/a)";
		_did="(n/a)";
		_quiet="(n/a)";
		_ltype="      $SCOMPANY"
		;;
	bfax)
		_quiet="(n/a)";
		_ltype="     Brooktrout"
		;;
	esac
	
	echo "$1$t$_type$t$_addr$t$_rcv$t$_scan$t$_dial$t$_quiet$t$_device"
	echo "$_ltype$t$_chan$t$_xmit$t$_did$t$_prefix$t$_debug$t$_hdr"

	if [ "$2" = "long" ]
	then
		eval _phdr="\$phdr$1"
		if [ "$_phdr" = "" ]; then _phdr="(none)"; fi
		eval _lock="\$lock$1"
		if [ "$_lock" = "" ]; then _lock="(none)"; fi
		echo
		echo "PageHdr:   '$_phdr'"

		case "$_type" in
		wfax)
			echo "UUCP Lock: '$_lock'"
			eval _initcmd="\$FAXinitcmd$1"
			if [ "$_initcmd" = "" ]; then _initcmd="(none)"; fi
			echo "Stty Command: '$_initcmd'"
			;;
		efax)
			eval _dataspeed="\$FAXdataspeed$1"
			if [ "$_dataspeed" = "" -o "$dataspeed" = 0 ]; then
				_dataspeed="(off)";
			fi
			echo "Data Speed: $_dataspeed, UUCP Lock: '$_lock'"
			eval _class2opts="\$FAXclass2opts$1"
			if [ "$_class2opts" = "" ]; then
				_class2opts="(default)";
			fi
			eval _initcmd="\$FAXinitcmd$1"
			if [ "$_initcmd" = "" ]; then _initcmd="(none)"; fi
			echo "Class 2 type: '$_class2opts', \c"
			echo "Flow Ctrl Command: '$_initcmd'"
			;;
		*)
			echo "UUCP Lock: '$_lock'"
			;;
		esac
	fi
}

#
#	display information about boards $1 thru $2 [long]
#
displayboards() {
	_displayboards1=$1
	_displayboards2=$2
	_displayboards3=$3
	dispboardvars hdr
	i=$_displayboards1
	while [ $i -le $_displayboards2 ]
	do
		dispboardvars $i $_displayboards3
		i=`expr $i + 1`
		echo
	done
	unset _displayboards1 _displayboards2 _displayboards3
}

#########################################################################
#	Routines for presenting a menu					#
#########################################################################
menu() {
	i=1
	while [ $# -gt 0 ]
	do
		if [ $# -ge 2 ]
		then
			i2=`expr $i + 1`
			echo "					   $i2)	$2\r\c"
			echo "   $i)	$1"
			shift 2; i=`expr $i + 2`
		else
			echo "   $i)	$1"
			shift; i=`expr $i + 1`
		fi
	done
	echo
	echo \
"Type number of selection and then press enter or press q when done: \c"
	read ans
	if [ "Q$ans" = Qq ]; then return 0; fi
	if [ "$ans" -gt 0 -a "$ans" -lt $i ]; then return $ans; fi
	return 99
}

#########################################################################
#	Routines for modifiying /usr/spool/fax/faxconfig		#
#########################################################################
#
#	Get board type for board $1
#
gettype() {
	while :
	do
		echo

		if [ $DOKERNEL = y ]; then
			echo "bfax	Brooktrout TR111MC, TR112 FAX Board"
			echo "dfax	$SCOMPANY $HPRODUCT FAX Board"
			echo "jfax	Hayes JT FAX 9600B FAX Board"
			ans="bfax, dfax, efax, jfax"
		else
			ans="efax"
		fi
		echo "efax	TR29.2 PN 2388 conforming (Class 2) Serial FAX Modem"
		echo
		echo "Channel $1 is what type ($ans)? \c"
		read ans
		case "$ans" in
		[bdejw]fax)	eval type$1=$ans; return;;
		q)		return;;
		*)		;;
		esac
	done
}

#
#	Get board device for board $1
#
getdevice() {
	while :
	do
		eval x=\$type$1;
		case "$type" in
		bfax)	RANGE="(0-23)"; NNN=0;;
		dfax)	RANGE="(00,01,10,11,20,21,...,60,61)"; NNN=00;;
		efax)	RANGE=; x=tty; NNN=1A;;
		jfax)	RANGE="(0-7)"; NNN=0;;
		wfax)	RANGE=; x=tty; NNN=1A;;
		esac
		echo "Type the minor device # for /dev/$x $RANGE"
		echo "Or full device name (e.g. /dev/$x$NNN)? \c"
		read ans
		case "$ans" in
		/*)	eval device$1=$ans; return;;
		q)	return;;
		*)	if [ "$type" = "efax"  -o "$type" = "wfax" ]
			then
				eval device$1="/dev/$x$ans";
				return;
			elif [ "$ans" -ge 0 -a "$ans" -le 31 ]
			then
				eval device$1="/dev/$x$ans";
				return;
			fi
			;;
		esac
	done
}


#
#	Get decimal value for description $1, variable $2
#
getdecimal() {
	dec="[0-9-][0-9]*"
	while :
	do
		echo "Enter decimal value for $1"
		echo "Or press 'q' to quit: \c"
		read ans
		x=
		case "$ans" in
		q)		return;;
		*)		x=`expr "$ans" : "\($dec\)$"`;;
		esac
		if [ "$x" != "" ]; then eval $2=$x; return; fi
	done
}

#
#	Get DMA channel value for description $1, variable $2
#
getchan() {
	dec="[0-9][0-9]*"
	while :
	do
		echo "Enter $1 (1, 3, or blank)"
		echo "Or press 'q' to quit: \c"
		read ans
		x=
		case "$ans" in
		q)		return;;
		'')		eval $2=; return;;
		1|3)		eval $2="$ans"; return;;
		esac
	done
}

#
#	Get boolean value for description $1, variable $2
#
getbool() {
	while :
	do
		echo "Enter 'y' or 'n' to $1"
		echo "Or press 'q' to quit: \c"
		read _boolans
		x=
		case "$_boolans" in
		q)	return;;
		y)	eval $2=1; return;;
		n)	eval $2=0; return;;
		esac
	done
}

#
#	Get string value for description $1, length $2 variable $3
#
getstr() {
	while :
	do
		echo "Enter string value for $1"
		echo "Or press 'q' to quit: \c"
		read _gs_ans
		if [ "Q$_gs_ans" = Qq ]; then return 1; fi
		eval $3='$_gs_ans'
		unset _gs_ans
		return 0
	done
}

#
#	Get string value for page header into variable $1
#
gethdrstr() {
    _ghs1="$1"
    TYPICAL="%m/%d/%y %H:%M  YOUR COMPANY HERE  P.%%02d/%%02d"
    while :
    do
	pagehdr "Modify FAX Page Header"
	echo "\n\nTypical value for Page Header is:"
	echo "$TYPICAL"
	eval _phdr="\$$_ghs1"
	echo "\nCurrent value for Page Header is:\n$_phdr"
	unset _phdr
	echo "\nParameter substitions (like date(1/C)):"
	echo "	%m month (01-12)     %d day (01-31)         %y year (00-99)"
	echo "	%b or %B month name  %a or %A weekday name  %e day (1-31)"
	echo "	%H hour (00-23)      %M minute (00-59)      %S seconds (00-59)"
	echo "	%I hour (00-12)      %p AM/PM               %Y year (4 digits)"
	echo "	%%02d/%%02d pages    %%%% percent sign      %Z time zone"
	echo
	echo "Enter new value for Page Header, 't' for typical, or 'q' to quit:"
	echo
	# Allow (leading) blanks in string
	SIFS="$IFS"; IFS="" read ans; IFS="$SIFS"
	case "$ans" in
	q|Q)	unset _ghs1; return;;
	t|T)	eval $_ghs1='$TYPICAL';;
	*)	eval $_ghs1='$ans';;
	esac
    done
}

#
#	Get Class 2 modem type
#
getclass2opt() {
	_gc2opt1="$1"
	while :
	do
		pagehdr "Select Class 2 modem type"
		# echo "       (Using a Class 2 modem is *not* supported!)"
		eval _modem="\$$_gc2opt1"
		echo "\nCurrent modem type is:	'$_modem'"
		if [ "Q$_modem" != Q ]; then
			if grep "^$_modem[ 	]" $CLASS2OPTS > /dev/null
			then
				:
			else
				echo "***WARNING: $_modem is not a valid type"
			fi
		fi
		echo "\nModem types listed in $CLASS2OPTS:"
		while read _modem _spec
		do
			case "$_modem" in
			"#"*)	;;
			*)	echo "   $_modem"
			esac
		done < $CLASS2OPTS | pr -w79 -3 -t
		echo
		echo "Enter one of the above types," \
			"'vi' to edit the types file, or 'q' to quit:"
		echo
		read ans
		case "$ans" in
		q)	return;;
		vi)	vi $CLASS2OPTS;;
		*)	eval $_gc2opt1='$ans';;
		esac
	done
}

#
#	Get Data Speed, UUCP Lock File, and ditty command
#
getdata() {
	_getdata1=$1
	while :
	do
		pagehdr "Select Data Call Parameters"
		cat <<EOF

Some V.32bis faxmodems allow data and FAX calls on the same telephone line.
DigiFAX supports this feature.  To allow data calls on the same line,
specify the speed of the serial interface as 19200 or 38400.  A speed of 0
implies that the line will only be used for FAX.  In addition, if you plan
on using "cu" or "uucp" for outgoing data calls on the line, you will need
to set the UUCP Lock file to the full pathname of the lock file to use.
Finally, you will also need to specify a ditty (stty) command to set
HW (CTS/RTS) flow control on the port and any AT commands needed to
tell your modem to use hardware flow control.

EOF
		eval _dataspeed="\$FAXdataspeed$_getdata1"
		if [ "$_dataspeed" = "" -o "$dataspeed" = 0 ]; then
			echo "Data calls allowed?	No"
			echo "Serial Speed for Data:	0"
		else
			echo "Data calls allowed?	Yes"
			echo "Serial Speed for Data:	$_dataspeed"
		fi

		eval _lock="\$lock$_getdata1"
		if [ "$_lock" = "" ]; then _lock="(none)"; fi
		echo "UUCP Lock File:		$_lock"

		eval _initcmd="\$FAXinitcmd$1"
		if [ "$_initcmd" = "" ]; then _initcmd="(none)"; fi
		echo "HW Flow Ctrl Command:	$_initcmd"
		echo

		menu \
			"Serial Speed" "UUCP Lock File" \
			"HW Flow Ctrl Command" \
			"Edit $SPOOLDIR/atcmds.$_getdata1"
		case $? in
		0)	return;;
		99)	;;
		1)
			cat <<EOF

Enter the speed you wish to use for the serial port for communicating
between your computer and the modem.  The speed must be 19200 or 38400.
Some $SCOMPANY serial products support higher data rates. If you are
using one of those products you can choose 57600, 76800, or 115200.

If you don't want to place or receive data calls on the faxmodem, then
specify a speed of 0.
EOF
			getdecimal "Serial Interface Speed" \
				FAXdataspeed$_getdata1
			;;
		2)
			cat <<EOF

Enter the full path name of the UUCP lock file used by your operating system.

For SCO, it is usually /usr/spool/uucp/LCK..<devname>, where <devname> is the
serial port device name, e.g. /usr/spool/uucp/LCK..ttyI11.

For other UNIX SVR3.2's, it is usually /usr/spool/locks/LCK..<devname>, where
<devname> is the serial port device name, e.g. '/usr/spool/locks/LCK..ttyI11'.

For UNIX SVR4 it is usually /usr/spool/locks/LK.000.<major>.<minor>, where
<major> and <minor> are the major and minor device numbers of the serial
port device padded with 0's to be exactly three digits long, e.g.
'/usr/spool/locks/LK.000.066.001'.  You can get the major and minor numbers
of the device by using the ls -l command on the device name.

Or, enter one of the keywords sco, svr3, or svr4 to have the lockname
determined automatically according to your system type and device name.

EOF
			getstr "UUCP Lock File Pathname" 64 \
					lock$_getdata1
			;;
		3)
			cat <<EOF

To use a serial FAX modem for data and FAX, hardware flow control must be
used.  You must set your modem for hardware flow control and save it
permanently in the modem.  Alternatively, you could put the 'AT' command to
do this in the file $SPOOLDIR/atcmds.$_getdata1 using menu item 4.

You must also specify a ditty or stty command which will tell the tty device
driver to use hardware flow control on the port.  For all $SCOMPANY products,
on any operating system, the command is 'ditty ctspace rtspace'.  For SCO Unix,
the command 'stty ctsflow rtsflow' should work for any brand of serial port.

EOF
			getstr "HW Flow Ctrl Command" 64 \
				FAXinitcmd$_getdata1
			;;
		4)
			if [ ! -f $SPOOLDIR/atcmds.$_getdata1 ]; then
cat <<EOF >$SPOOLDIR/atcmds.$_getdata1
#
#	User supplied AT initialization commands for channel $_getdata1
#
#	Generally, just whatever the modem uses turn on hardware (RTS/CTS) flow
#	control when data and FAX are used on the same port.  These are output
#	after all the DigiFAX modem initialization commands.  For FAX only
#	operation, you do not need to use hardware flow control, and no
#	commands are needed in this file.
#
#	For Telebit modems, use:		ATS58=2
#	For Rockwell based modems, use:		AT&K3
#	For ZyXEL modems, use:			AT&H3
#	Otherwise, consult your modem manual.
#
#	List the AT command here, with no pound sign:
EOF
			fi
			vi $SPOOLDIR/atcmds.$_getdata1
			if grep -c "^[aA]" \
				$SPOOLDIR/atcmds.$_getdata1 >/dev/null; then
				:
			else
				rm -f $SPOOLDIR/atcmds.$_getdata1
			fi
			;;
		esac
	done
}

#
#	Modify board number $1
#
modboard() {
	moddone=0
	_modboard1=$1
	while [ $moddone = 0 ]
	do
		pagehdr "Modify FAX Channel $1 Configuration"
		echo

		displayboards $_modboard1 $_modboard1 long
		eval type=\$type$_modboard1;
		case "$type" in
		jfax|dfax)
			menu	"Change Type" "" \
				"" "" \
				"Disable Receive" "Disable Transmit" \
				"Set Receive Scan Time" "" \
				"DialTone Wait Period" "Set Dialing Prefix" \
				"Turn on Quiet Mode" "Turn on Debugging" \
				"Change Device Name" "Set FAX ID string" \
				"Enable UUCP Lock File" "Change Page Header"
			;;
		efax)
			menu	"Change Type" "" \
				"" "" \
				"Disable Receive" "Disable Transmit" \
				"Set Receive Scan Time" "" \
				"DialTone Wait Period" "Set Dialing Prefix" \
				"Turn on Quiet Mode" "Turn on Debugging" \
				"Change Device Name" "Set FAX ID string" \
				"Data Parameters" "Change Page Header" \
				"" "Select Class 2 type"
			;;
		wfax)
			menu	"Change Type" "" \
				"" "" \
				"Disable Receive" "Disable Transmit" \
				"Set Receive Scan Time" "" \
				"DialTone Wait Period" "Set Dialing Prefix" \
				"Turn on Quiet Mode" "Turn on Debugging" \
				"Change Device Name" "Set FAX ID string" \
				"Enable UUCP Lock File" "Change Page Header" \
				"Set 'stty' Command"
			;;
		bfax)
			menu	"Change Type" "" \
				"Change IO Address" "Change DMA Channel" \
				"Disable Receive" "Disable Transmit" \
				"Set Receive Scan Time" "Set DID parameter" \
				"DialTone Wait Period" "Set Dialing Prefix" \
				"Turn on Quiet Mode" "Turn on Debugging" \
				"Change Device Name" "Set FAX ID string" \
				"Enable UUCP Lock File" "Change Page Header"
			;;
		"")
			menu	"Change Type"
			;;
		esac
		case $? in
		0)	moddone=1;;
		99)	;;
		1)
			otype="$type"
			gettype $_modboard1
			eval type=\$type$_modboard1;
			case "$type" in
			bfax)
				if [ "$otype" != bfax ]
				then
					eval addr$_modboard1=
					eval chan$_modboard1=
					eval device$_modboard1=
				fi
				;;
			dfax|jfax|efax)
				if [ "$otype" != "$type" ]
				then
					eval FAXdidparm$_modboard1=
					eval addr$_modboard1=
					eval chan$_modboard1=
					eval device$_modboard1=
					eval FAXdataspeed$_modboard1=
					eval FAXinitcmd$_modboard1=
				fi
				;;
			wfax)
				if [ "$otype" != "$type" ]
				then
					eval FAXdidparm$_modboard1=
					eval addr$_modboard1=
					eval chan$_modboard1=
					eval device$_modboard1=
					eval FAXinitcmd$_modboard1=\"ditty ctspace\"
				fi
				;;
			esac
			;;
		2)	;;
		3)	gethex "Board $_modboard1 IO address" addr$_modboard1;;
		4)	getchan "Board $_modboard1 DMA channel" chan$_modboard1;;
		5)	getbool "Disable Receive" rcv$_modboard1;;
		6)	getbool "Disable Transmit" xmit$_modboard1;;
		7)	getdecimal "Receive Scan Time" scan$_modboard1;;
		8)	getdecimal "DID Parameter" FAXdidparm$_modboard1;;
		9)	
cat <<EOF

Enter the number of seconds to wait for dialtone before dialing.  Use
positive numbers if dialtone *must* be present and detected before dialing.
Prefix a '-' (minus) to the number if dialing should proceed even if
dialtone is not detected within the specified time.

EOF
			getdecimal \
	"Seconds to wait for dialtone" FAXdialtone$_modboard1;;
		10)	getstr "Dialing Prefix String" 8 FAXprefix$_modboard1;;
		11)	getbool "Enable Quiet Mode" quiet$_modboard1;;
		12)	getdecimal "Debug Output Level (0-9)" debug$_modboard1;;
		13)	getdevice $_modboard1;;
		14)	getstr "FAX Identification String" 20 hdr$_modboard1;;
		15)
			case "$type" in
			efax)	getdata $_modboard1
				;;
			*)	getstr "UUCP Lock File Pathname" 64 \
					lock$_modboard1
				;;
			esac
			;;
		16)	gethdrstr phdr$_modboard1;;
		17)	getditty FAXinitcmd$_modboard1;;
		18)	getclass2opt FAXclass2opts$_modboard1;;
		esac
	done
	unset _modboard1
}

#
#	renumber $1 $2 to begin with $3
#
renumber() {
	i=$1; j=$3
	while [ $i -le $2 ]
	do
		for var in $boardopts
		do
			eval $var$j=\$"$var$i"
		done
		for var in $boardvars
		do
			eval FAX$var$j=\$"FAX$var$i"
		done
		i=`expr $i + 1`
		j=`expr $j + 1`
	done
}

#
#
#
clearboards() {
	i=$1;
	while [ $i -le $2 ]
	do
		for var in $boardopts
		do
			eval $var$i=
		done
		for var in $boardvars
		do
			eval FAX$var$i=
		done
		i=`expr $i + 1`
	done
}

#
#	Configure FAX Boards Menu
#
boardcfgmenu() {
	done=0
	bpp=4
	fb=1
	lb=`expr $fb + $bpp - 1`; if [ $lb -gt $n ]; then lb=$n; fi
	while [ $done = 0 ]
	do
		pagehdr "$PRODVER FAX Channel Configuration Menu"
		echo
		displayboards $fb $lb
		echo
		if [ "$n" -lt 2 ]; then range=1; else range="1-$n"; fi
		echo "Type channel number to modify ($range), 'a' to add a channel"
		echo "'c' to copy a channel, 'd' to delete a channel, "
		if [ $fb -ne 1 -o $lb -ne $n ]
		then
			echo "'m' for more channels, \c"
		fi
		echo "'vi' to directly edit $FAXCONFIG, or 'q' when finished: \c"
		read ans
		case "$ans" in
		m*)	
			if [ $fb -ne 1 -o $lb -ne $n ]
			then
				fb=`expr $fb + $bpp`
				if [ $fb -gt $n ]; then fb=1; fi
				lb=`expr $fb + $bpp - 1`;
				if [ $lb -gt $n ]; then lb=$n; fi
			fi
			;;
		q*)	done=1;;
		vi)
			vi $FAXCONFIG
			getboards
			fb=1
			lb=`expr $fb + $bpp - 1`;
			if [ $lb -gt $n ]; then lb=$n; fi
			;;
		a*)
			changed_boards=1
			n=`expr $n + 1`
			clearboards $n $n
			setboardvars
			modboard $n
			eval x=\$type$n;
			if [ "$x" != "" ]
			then
				lb=`expr $fb + $bpp - 1`;
				if [ $lb -gt $n ]; then lb=$n; fi
			else
				n=`expr $n - 1`
			fi
			;;
		c*)
			echo "Enter channel number to copy: \c"
			read dfb
			if [ "$dfb" -lt 1 -o "$dfb" -gt $n ]; then break; fi
			changed_boards=1
			n=`expr $n + 1`
			clearboards $n $n
			renumber $dfb $dfb $n
			eval device$n=
			eval addr$n=
			lb=`expr $fb + $bpp - 1`;
			if [ $lb -gt $n ]; then lb=$n; fi
			;;
		d*)
			changed_boards=1
			echo "Enter first channel number to delete: \c"
			read dfb
			if [ "$dfb" -lt 1 ]; then dfb=1; fi
			echo "Enter last channel number to delete: \c"
			read dlb
			if [ $dlb -gt $n ]; then dlb=$n; fi
			if [ $dlb -eq $n ]
			then
				clearboards $dfb $dlb
				n=`expr $n - 1`
				lb=$n
			else
				len=`expr $dlb - $dfb + 1`
				renumber `expr $dlb + 1` `expr $dlb + $len` $dfb
				n=`expr $n - $len`
				if [ $lb -gt $n ]; then lb=$n; fi
			fi
			;;
		*)
			if [ "$ans" -ge 1 -a "$ans" -le $n ]
			then
				changed_boards=1
				modboard $ans
			fi
			;;
		esac
	done
}

#
#	Read, modify, and store the faxconfig file
#
boardcfg() {
	#
	#	Read Information from faxconfig file
	#
	getboards

	#
	#	Configure the boards
	#
	changed_boards=0
	boardcfgmenu

	if [ "$changed_boards" = 1 ]
	then
		echo
		yesno 0 "Do you want to make these changes permanent?"
		if [ $? = 0 ]
		then
			putfaxconfig
		fi
	fi
}

#########################################################################
#	Routines for modifiying /usr/spool/fax/fonts			#
#########################################################################
FAXFONTS=$SPOOLDIR/fonts
getsymsets () {
	/bin/ls $FAXFONTS/symset.* | sed 's/.*symset\.//'
}
fontcfg() {
	fontdone=0
	useset=PC-8
	symsets=`getsymsets`
	while [ $fontdone = 0 ]
	do
		pagehdr "$PRODVER Text Font Configuration Menu"
		echo
		echo "Symbol set $useset is currently selected..."
		echo
		echo "Choose from these available symbol sets:"
		echo
		menu	$symsets
		rc="$?"
		case $rc in
		0)	fontdone=1;;
		99)	;;
		*)
			set -- $symsets
			eval useset=\$$rc
			;;
		esac
	done
	( cd $FAXFONTS; sh ./makefonts $useset )
}

#########################################################################
#	Routines for modifiying /usr/bin/faxnotify			#
#########################################################################
FAXNOTIFY=/usr/bin/faxnotify
notifycfg() {
	notifydone=0
	while [ $notifydone = 0 ]
	do
		autoprint="`getshellvar $FAXNOTIFY AUTOPRINT`"
		autodelete="`getshellvar $FAXNOTIFY AUTODELETE`"
		mailonsend="`getshellvar $FAXNOTIFY MAILONSEND`"
		mailonrecv="`getshellvar $FAXNOTIFY MAILONRECV`"
		savedead="`getshellvar $FAXNOTIFY SAVEDEAD`"
		pagehdr "$PRODVER Notification Configuration Menu"
		echo
		echo "	Auto Print   = $autoprint # Auto print received FAXes"
		echo "	Auto Delete  = $autodelete # Auto delete received FAXes"
		echo "	Mail On Send = $mailonsend # Mail FAX status to sender"
		echo "	Mail On Recv = $mailonrecv # Mail user(s) on FAX receive"
		echo "	Save Dead    = $savedead # Save dead faxes in \$HOME/fax/dead"
		echo
		menu	"Change Auto Print" "Change Auto Delete" \
			"Change Mail On Send" "Change Mail On Recv" \
			"Change Save Dead"
		rc="$?"
		ans=
		case $rc in
		0)	notifydone=1;;
		1)	getbool "Enable Autoprint" ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXNOTIFY AUTOPRINT "$ans"; fi
			;;
		2)	getbool "Enable Autodelete" ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXNOTIFY AUTODELETE "$ans"; fi
			;;
		3)	getdecimal \
			"MailOnSend (0=never, 1=always, 2=failures only)" ans;
			case "$ans" in
			[012])	setshellvar $FAXNOTIFY MAILONSEND "$ans";;
			esac
			;;
		4)	getbool "Enable MailOnRecv" ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXNOTIFY MAILONRECV "$ans"; fi
			;;
		5)	
			echo
		echo "Enabling SaveDead will allow the feature system-wide."
		echo "Each user must choose to enable it for themselves by"
		echo "doing a mkdir \$HOME/fax/dead to hold the dead faxes."
			echo
			getbool "Enable SaveDead" ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXNOTIFY SAVEDEAD "$ans"; fi
			;;
		99)	;;
		esac
	done
}

#########################################################################
#	Routines for modifiying /usr/bin/faxprint			#
#########################################################################
FAXPRINT=/usr/bin/faxprint
getprinter() {	# var
	while :
	do
		echo
		echo "	ibm-pro       	IBM Proprinter"
		echo "	epson-fx      	Epson CX,FX,JX,LX,MX"
		echo "	epson-lq      	Epson LQ-800/1000"
		echo "	bj10e          	Canon BJ-10e, BJ-200"
		echo "	lj4           	HP LaserJet Series IV"
		echo "	lj3           	HP LaserJet Series III"
		echo "	lj, lj2        	HP LaserJet Plus, Series II"
		echo "	lj2p          	HP LaserJet Series IIP"
		echo "	ps     		Postscript"
		echo
		echo "Select printer from above list of abbreviations: \c"
		read _gp
		case "$_gp" in
		q)	return;;
		*)	eval $1=$_gp; return;;
		esac
	done
}

getpaper() {	# var
	while :
	do
		echo
		echo "	letter		Letter paper 8.5 x 11"
		echo "	legal		Legal paper 8.5 x 14"
		echo "	a4		ISO A4 paper"
		echo "	letter_legal	Letter if possible, else legal"
		echo "	any		Whatever paper is in printer"
		echo
		echo "Select paper from above list of abbreviations: \c"
		read _gp
		case "$_gp" in
		q)	return;;
		any)	eval $1=""; return;;
		*)	eval $1=$_gp; return;;
		esac
	done
}

printcfg() {
	printdone=0
	while [ $printdone = 0 ]
	do
		printer="`getshellvar $FAXPRINT printer`"
		paper="`getshellvar $FAXPRINT paper`"
		options="`getshellvar $FAXPRINT options`"
		raw_lp_opt="`getshellvar $FAXPRINT raw_lp_opt`"
		spooler="`getshellvar $FAXPRINT spooler`"
		force_dest="`getshellvar $FAXPRINT force_dest`"
		wantfooter="`getshellvar $FAXPRINT wantfooter`"
		wantheader="`getshellvar $FAXPRINT wantheader`"
		prcmd=fax2pr
		case "$printer" in
		lj3)		printer="LaserJet Series III";;
		lj4)		printer="LaserJet Series IV";;
		lj2p)		printer="LaserJet Series IIP";;
		lj*)		printer="LaserJet Plus, Series II";;
		epson-fx)	printer="Epson CX,FX,JX,LX,MX";;
		epson-lq)	printer="Epson LQ-800/1000";;
		bj*)		printer="Canon BJ-10e, BJ-200";;
		ibm-pro)	printer="IBM Proprinter";;
		ps)		prcmd=fax2ps; printer="Postscript";;
		*)		printer="Unknown ($printer)";;
		esac
		res="`getshellvar $FAXPRINT res`"
		case "$res" in
		1)		res="low (75)";;
		2)		res="medium low (100)";;
		3)		res="medium high (150)";;
		4)		res="high (300)";;
		esac
		case "$paper" in
		legal)		paper=Legal;;
		letter)		paper=Letter;;
		letter_legal)	paper="Letter or Legal";;
		a4)		paper=A4;;
		"")		paper="Whatever is available";;
		*)		paper="Unknown ($paper)";;
		esac
		case "$force_dest" in
		"")	force_dest="LP System Default Destination";;
		*)	;;
		esac
		pagehdr "$PRODVER Printer Configuration Menu"
		echo
		echo "faxprint:"
		echo "	Printer Type               = $printer"
		echo "	Print Resolution           = $res"
		echo "	Paper                      = $paper"
		echo "	Want Footer                = $wantfooter"
		echo "	Want Header                = $wantheader"
		echo "	Additional $prcmd Options  = $options"
		echo "$spooler:"
		echo "	Spooler Command            = $spooler"
		echo "	Destination                = $force_dest"
		echo "	Raw Output Spooler Options = $raw_lp_opt"
		echo
		menu	"Change Printer Type" "Change Print Resolution" \
			"Change Paper Type" "Change Footer" \
			"Change Header" "Change $prcmd options" \
			"Change Spooler" "Change Destination Name" \
			"Change $spooler options" "Restore Defaults" \
			"Configure LP spooler for LaserJet printer"
		rc="$?"
		ans=
		case $rc in
		0)	printdone=1;;
		99)	;;
		1)	getprinter ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXPRINT printer "$ans"; fi;;
		2)	
			echo
			echo "Select printer resolution from the list below"
			menu	"Low" "Medium Low" "Medium High" "High"
			rc="$?"
			case $rc in
			0)	;;
			99)	;;
			1|2|3|4) setshellvar $FAXPRINT res "$rc";;
			esac
			;;
		3)	getpaper ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXPRINT paper "$ans";
			else
				setshellvar $FAXPRINT paper ""; fi;;
		4)	getbool "Enable Page Footer" ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXPRINT wantfooter "$ans"; fi;;
		5)	getbool "Enable Page Header" ans;
			if [ "$ans" != "" ]; then
				setshellvar $FAXPRINT wantheader "$ans"; fi;;
		6)	if getstr "Additional $prcmd Options" 32 ans;
			then setshellvar $FAXPRINT options "$ans"; fi;;
		7)	if getstr "Spooler Command" 32 ans;
			then setshellvar $FAXPRINT spooler "$ans"; fi;;
		8)	if getstr "Printer Destination Name" 32 ans;
			then setshellvar $FAXPRINT force_dest "$ans"
			else setshellvar $FAXPRINT force_dest ""; fi;;
		9)	if getstr "Raw Output Spooler Options" 32 ans;
			then setshellvar $FAXPRINT raw_lp_opt "$ans"; fi;;
		10)	setshellvar $FAXPRINT printer "lj"
			setshellvar $FAXPRINT res "2"
			setshellvar $FAXPRINT paper ""
			setshellvar $FAXPRINT options ""
			setshellvar $FAXPRINT raw_lp_opt "-oraw -og"
			setshellvar $FAXPRINT force_dest ""
			setshellvar $FAXPRINT wantfooter "1"
			setshellvar $FAXPRINT wantheader "1"
			setshellvar $FAXPRINT spooler "lp"
			;;
		11)	sh /usr/bin/jetconfig; ans=;;
		esac
	done
}

#########################################################################
#	Routines for modifiying the server
#########################################################################
servercfgmenu() {
	serverdone=0
	while [ $serverdone = 0 ]
	do
		pagehdr "$PRODVER Server Configuration Menu"
		echo
		echo "Maximum Retries:    $FAXmax_tries"
		echo
		echo "Retry Wait Periods: $FAXwait_times"
		echo "(List one or more delay periods (minutes) between successive retries)"
		echo
		echo "Send Warning Mail on Retry #:	$FAXretrywarning	(0=no, >0=retry number)"
		echo
		echo "Keep Partial Recieves:		$FAXkeeppartial	(0=no, 1=yes)"
		echo "Continue Partial Sends:		$FAXsendpartial	(0=no, 1=yes)"
		echo "Channel Scheduling Method:	$FAXroundrobin	(0=linear, 1=roundrobin)"
		echo "Log Nicknames in txlog:		$FAXlognickname	(0=log numbers, 1=log names)"
		echo "Log All Tx Attempts in txlog:	$FAXlogattempts	(0=log once, 1=log all retries)"
		echo
		menu	"Set Maximum Retries" "Set Retry Wait Periods" \
			"Send Warning Mail on Retry N" \
			"Keep Partial Recieves" "Continue Partial Sends" \
			"Scheduling Algorithm" "Log Nicknames" \
			"Log All Tx Attempts"
		rc="$?"
		case $rc in
		0)	serverdone=1;;
		99)	;;
		1)	getdecimal "Number of Retries (1-999)" FAXmax_tries
			;;
		2)
			oldwait="$FAXwait_times"
			getstr "Retry Wait Periods (mins) (e.g. 0,5,10)" \
				64 newwait
	FAXwait_times="`echo "$newwait" | sed 's/,*[ 	][ 	]*/,/g'`"
			case "$FAXwait_times" in
			[0-9]*) ;;
			*)	FAXwait_times="$oldwait" ;;
			esac
			;;
		3)	getdecimal \
"retry # to send warning mail (0=no, 1-$FAXmax_tries)?" FAXretrywarning
			;;
		4)	getbool "Keep Partially Received Transmissions?" \
				FAXkeeppartial
			;;
		5)	getbool "Continue Partial Sends From Last Good Page?" \
				FAXsendpartial
			;;
		6)	getbool "Schedule Channels in Round-robin fashion?" \
				FAXroundrobin
			;;
		7)	getbool "Log nicknames instead of phone numbers in txlog?" \
				FAXlognickname
			;;
		8)	getbool "Log All Attempts (instead of just the last) in txlog?" \
				FAXlogattempts
			;;
		esac
	done
}

servercfg() {
	#
	#	Read Information from faxconfig file
	#
	getboards

	#
	#	Configure the server
	#
	servercfgmenu
	echo
	yesno 0 "Do you want to make these changes permanent?"
	if [ $? = 0 ]
	then
		putfaxconfig
	fi
}

#########################################################################
#	Routines for starting the server
#########################################################################
serverstop() {
	pid=`/bin/su root -c "/bin/ps -e" | grep faxrun | sed -e 's/^  *//' -e 's/ .*//'`
	if [ "${pid}" != "" ]; then /bin/kill ${pid}; fi
	pid=`/bin/su root -c "/bin/ps -e" | grep faxsrv | sed -e 's/^  *//' -e 's/ .*//'`
	if [ "${pid}" != "" ]; then /bin/kill ${pid}; fi
}

serverstart() {
	serverstop
	sleep 4;
	(
		cd $SPOOLDIR
		rm -f $SPOOLDIR/FIFO*
		if [ -x /etc/faxsrv ]
		then
			if [ -x /usr/bin/sd ]
			then
				# On SCO, fire it off without an LUID
				sd faxsrv $LUIDNAME $UMASK 2> /dev/null
				if [ $? != 0 ]; then
					# sd fails from cron
					/etc/faxsrv $LUIDNAME $UMASK &
				fi
			else
				/etc/faxsrv $LUIDNAME $UMASK &
			fi
		fi
	)
}

#
#	Set background color (y|n)
#
color() {
	if [ -x /usr/bin/setcolor ]; then
		case "$TERM" in
		ansi|at386|AT386)
			if [ $1 = y ]; then
				setcolor blue lt_cyan
			else
				setcolor -n
			fi
			;;
		esac
	fi
}

#########################################################################
#									#
#	The real script begins here					#
#									#
#########################################################################

case "$1" in
-k)	kerncfg;;
-b)	boardcfg;;
-f)	fontcfg;;
-s)	scancfg;;
-S)	servercfg;;
-U)	buildkernel;;
-u)	unbuildkernel;;
-i)	installkernel;;
-e|start)	serverstart;;
-d|stop)	serverstop;;
-p)	printcfg;;
-n)	notifycfg;;
*)
	if [ "$1" = -I ]; then
		allow_restart=0;
		startmsg="[Not allowed yet] "
	else
		allow_restart=1;
		startmsg=
	fi
	need_restart=0
	ans=
	while [ "Q$ans" != Qq ]
	do
		pagehdr "$PRODVER Device Driver and Channel Configuration"
		echo
		echo "UNIX KERNEL CONFIGURATION"
		if [ $DOKERNEL = y ]; then
		echo "	 1 device	FAX Board Device Driver Configuration"
		echo "	 2 scanner	Scanner Device Driver Configuration"
		echo "	 3 build	Build Kernel with Current Configuration"
		echo "	 4 unbuild	Build Kernel Without FAX Drivers"
		echo "	 5 install	Install Most Recently Built Kernel"
		else
			echo "	1-5		Not Applicable"
		fi
		echo
		echo "SERVER CONFIGURATION"
		echo "	 6 channels	Modify FAX Channel(s) Configuration"
		echo "	 7 fonts	Modify FAX Text Font Configuration"
		echo "	 8 server	Modify Server Parameter Configuration"
		echo "	 9 start	${startmsg}Start FAX Server"
		echo "	10 stop		${startmsg}Stop FAX Server"
		echo
		echo "APPLICATIONS CONFIGURATION"
		echo "	11 notify	Job Notification (faxnotify)"
		echo "	12 print	Print Configuration (faxprint)"
		echo
		echo "Enter a number, a name, or q to QUIT: \c"
		read ans
		case "$ans" in
		1|d*)	kerncfg; ans=;;
		2|sc*)	scancfg; ans=;;
		3|bui*)	buildkernel; ans=;;
		4|unb*)	unbuildkernel; ans=;;
		5|ins*)	installkernel; ans=;;
		6|ch*)	boardcfg; need_restart=1; ans=;;
		7|f*)	fontcfg; need_restart=1; ans=;;
		8|se*)	servercfg; need_restart=1; ans=;;
		9|sta*)
			if [ "$allow_restart" = 1 ]; then
				serverstart;
				need_restart=0;
			fi
			ans=
			;;
		10|sto*)
			if [ "$allow_restart" = 1 ]; then
				serverstop;
				need_restart=1;
			fi
			ans=
			;;
		11|n*)	notifycfg; ans=;;
		12|p*)	printcfg; ans=;;
		esac
	done
	if [ "$allow_restart" = 1 -a "$need_restart" = 1 ]
	then
		echo
		echo "The server needs to be restarted because of these changes"
		yesno 0 "Do you want to restart it now?"
		if [ $? = 0 ]
		then
			serverstart
		fi
	fi
esac

rc="$?"
exit $rc
