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

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
	# 
	# Edit /etc/system to turn off 64bit dma
	#
	cp /etc/system /etc/system.sv
	cp /etc/system /tmp/system.$$
	echo  "set fas:fas_enable_sbus64 = 0" >>  /tmp/system.$$
	mv /tmp/system.$$ /etc/system
	rm /etc/system.sv
	#
	# Forcing a reset of Presto data structures so that the system
	# won't hang on a presto -r
	#
	/tmp/pr_force_reset > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
		/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
else
	reboot_msg
fi

exit 0
