#! /bin/sh
# @(#)preremove.src	1.4  93/03/18

BASEDIR=/opt
TOP=SUNWprsto
CLUSTER=Prestoserve
PROD_NAME=SUNWprsto
RELEASE=2.4.1
PROD_PATH=$BASEDIR/$PROD_NAME/$CLUSTER/$RELEASE/dist

cp $PROD_PATH/pr /kernel/drv/pr

PRESTO_INIT_CMD=/etc/init.d/prestoserve

reboot_msg()
{
	echo " "
	echo "NOTICE: Couldn't unload the Prestoserve driver"
	echo "NOTICE: Reboot the computer to use the patched Prestoserve driver"
	echo " "
}

if [ -x $PRESTO_INIT_CMD ]
then
	#
	# Check if presto mod is loaded, try to bring presto down and unload it.
	# If it fails then either the presto cmd is not available, presto cmd
	# returned an error, or the presto module is not loaded.
	# For these cases, just let them know that they must reboot the machine
	# for the patched driver to be loaded.
	#
	echo "INFO: Bringing Prestoserve down"
	/usr/sbin/presto -d
	echo "INFO: Flushing cached Unix filesystem data"
	/usr/sbin/sync
	#
	# Delete the line that disabled 64 bit dma
	cat /etc/system | sed -e '/^set fas:fas_enable_sbus64 = 0/D' > /tmp/system.$$
	mv /tmp/system.$$ /etc/system

	/usr/sbin/presto -r

	TMP=`modinfo | grep -i presto`
	if [ -z "$TMP" ]
	then
		reboot_msg
	else
		set -- $TMP
		modid=$1
		modunload -i $modid
		if [ $? -eq 0 ]
		then
			#
			# Causes a load of the new driver
			#
			$PRESTO_INIT_CMD start
		else
			reboot_msg
		fi
	fi
else
	reboot_msg
fi

exit 0
