#!/bin/sh
# 
# Copyright (c) 1994, Sun Microsystems, Inc.
#     All Rights Reserved
#
#
# request script - check to see if volmgt needs to be changed
#
#	@(#)request	1.5	19 Oct 1995


FILE_CHECK=/etc/.vold.wabi


NAWK=/usr/bin/nawk
GREP=/usr/bin/grep
CAT=/bin/cat
ECHO=/bin/echo
UNAME=/usr/bin/uname
PS=/usr/bin/ps
CKYORN=/usr/bin/ckyorn
SH=/usr/bin/sh

change_volmgt()
{
	#
	# change_volmgt() -
	#	check to see if /etc/vold.conf should change.
	#	return FALSE if there is no reason to change (e.g., no volmgt 
	#	    running)
	#	return TRUE if we should ask user to change
	#


	#
	# if this is already fixed, don't even continue
	#
		
	if [ -f $FILE_CHECK ]
	then
		$ECHO FALSE
		return
	fi	

	#
	# Define system BASEDIR
	#

	SYSBASEDIR=`echo ${BASEDIR} | awk -F// '{ print $2 }'`
	if [ "$SYSBASEDIR" = "a" ]
	then
	     SYSBASEDIR="/a"
	else
	     SYSBASEDIR=""
	fi


	#
	# only change 5.4 and 5.5 systems (should we do this?)
	#

	if [ "`$UNAME -r`" != "5.4" -a "`$UNAME -r`" != "5.5" -a "`$UNAME -r`" != "5.5.1" ]
	then
		$ECHO FALSE
		return
	fi

	#
	# only do this is they have a floppy
	#

	if [ ! -c /dev/rdiskette ]
	then
		$ECHO FALSE
		return
	fi

	# 
	# get the PID for vold
	#

	PID=`$PS -ef | $GREP /usr/sbin/vold | $GREP -v $GREP | $NAWK '{ print $2 }'`

	#
	# look to see if line exists in /etc/vold.conf
	#

	$CAT $SYSBASEDIR/etc/vold.conf | $NAWK '
	    BEGIN { FOUND = 0 } 
	    {
	    	if(($1 == "use") && ($2 == "floppy") && ($3 == "drive")) 
		    FOUND = 1
	    }
	    END { 
		exit (FOUND == 1)
	    } 
	'
	RET="$?"

	if [ "$RET" = "1" ]
	then
		$ECHO TRUE	# if we have found the line to change
	else
		$ECHO FALSE
	fi
}

# main

RET="`change_volmgt`"
if [ "$RET" = "TRUE" ]
then
	$ECHO
	$ECHO
	$ECHO "To use your diskette drive under Wabi, we recommend that you"
	$ECHO "disable Volume Manager's control of the diskette drive."
	$ECHO
	$ECHO "Would you like this done now?\c"
	ANS=`$CKYORN -d y -d "change /etc/vold.conf"`||exit 3
	case $ANS in 
	    q* | Q* )
		exit 3;;
	    y* | Y* )
		FIX_FLOPPY=TRUE;
		break;;
	    *)
		$ECHO
		$ECHO "If you need to use your diskette drive with Wabi, you can always"
		$ECHO "disable Volume Manager's control of the drive later. To do this,"
		$ECHO "enter the following command as superuser:"
		$ECHO "	$BASEDIR/SUNWwabi/lib/vold.switch -disable"
		$ECHO
		$ECHO "See the Wabi 2.1 Release Notes for more detailed information."
		$ECHO
		FIX_FLOPPY=FALSE;
		break;;
 	esac
	$ECHO
fi

cat >$1 <<!
FIX_FLOPPY='$FIX_FLOPPY'
!

exit 0
