:
#	@(#) dkinit.sh 25.4 93/02/24 
#
#	Copyright (C) 1986-1993 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
# DKINIT	- SCO UNIX System V hard disk initialization
#		  with non-standard disk support.
#

dkconf=/usr/lib/mkdev/perms/DKINIT

Getdfl() {
	read prm1 prm2 prm3 prm4 prm5 prm6 prm7 prm8 < /tmp/dkinit$$
}
Showdfl() {
	echo "
	Disk Parameters		Values
	---------------         ------
	1. Cylinders		$prm1
	2. Heads		$prm2
	3. Write Reduce		$prm3
	4. Write Precomp	$prm4
	5. Ecc			$prm5
	6. Control		$prm6
	7. Landing Zone		$prm7
	8. Sectors/track	$prm8"
}

usage() {
echo "USAGE:
dkinit [/dev/rhd00 |
	drive-number (0|1) controller-number (0-6) controller-type (W|E|I)]
	where controller-type W = ST506 / ESDI 
			      E = OMTI 
			      I = IDA"
	   exit 1
}

# Initialize variables
modified=
root=
controller=
drive=
type=

case $# in
	1) if [ "$1" = "/dev/rhd00" ] 
	   then
		root=yes
	   else
		usage
	   fi
	   ;;
	3) drive=$1
	   controller=$2
	   type=$3
	   ;;
	*) usage
	   ;;
esac

# determine the disk number from DKINIT
if [ -f $dkconf -a "$root" != "yes" -a "$controller.$drive" != "0.0" ]
then
	drive0=`grep "^$type $controller 0" $dkconf | awk '{print $4}' `
	dn=`grep "^$type $controller $drive" $dkconf | awk '{print $4}' `
	[ ! "$dn" ] && {
		echo "Drive $drive on Controller $type $controller is \
not configured"
		exit 1
	}
	[ "$controller" -eq 0 ] && {
		# /usr/lib/mkdev/perms/DKINIT does not exist during a root
		# install so the entry for the first disk on the primary 
		# controller is not listed. We have the second disk on that
		# controller, so assume that the 1st disk exists, and is the
		# root disk.
		drive0=0
	}
	[ ! "$drive0" ] && {
		echo "Controller $type $controller is not configured"
		exit 1
	}
else
	# /usr/lib/mkdev/perms/DKINIT does not exist at install time
	# if drive==0 and controller==0 assume root install
	if [ "$drive" -eq 0 -a "$controller" -eq 0 ]
	then
		dn=0
		drive0=0
		dparam -w
	else
		echo "dkinit: Cannot open $dkconf"
		exit 1
	fi
fi

dparam /dev/rdsk/${dn}s0 > /tmp/dkinit$$
Getdfl

while echo "\nHard Disk Drive $dn Configuration

	1. Display current disk parameters
	2. Modify current disk parameters
	3. Select default disk parameters

Enter your choice or q to quit: \c"
do
	read ans
	case "$ans" in
	1)	Showdfl
		;;
	2)
		Showdfl
		while echo "\nEnter a parameter to modify or q to return to the main menu: \c"
		do
			read y
			case "$y" in
			[1-8])	while echo "\nEnter the new value or <Return> to use the existing value: \c"
				do
					read z
					case "$z" in
					[0-9]*)
						eval prm$y=$z
						modified=1
						break
						;;
					"")	break
						;;
					*)	echo "Please enter a numeric value.\n"
						;;
					esac
				done
				;;
			[qQ])	break
				;;
			*)	echo "Please enter a choice, 1-8 or q.\n"
				;;
			esac
		done
		;;
	3)	[ $modified ] && {
			Getdfl
			Showdfl
			}
		;;
	[qQ])	
		[ $modified ] && {
			dparam -w /dev/rdsk/${drive0}s0
			dparam /dev/rdsk/${dn}s0 $prm1 $prm2 $prm3 $prm4 $prm5 $prm6 $prm7 $prm8
			}
		break
		;;
	*)	echo "\nPlease enter a choice, 1 2 3 or q.\n"
		;;
	esac
done
rm -f /tmp/dkinit*
