#! /sbin/sh
####################################################################
#	$Id: preremove,v 1.6 2004/03/29 04:28:20 scottk Exp $
# 	Copyright (c) Digi, Digi International Inc.
#
#	Pre-removal script for Digi RealPort Driver.
#	Copyright (c) 1988-98 Digi International Inc.
#
#	For HP-UX 10.X & 11.X
#
#	NOTE: It is expected that the swinstall program will call
#             this script just before removing the files.
#				
####################################################################

PATH=$SW_PATH
export PATH


majorrev=`uname -r | cut -d '.' -f 2`
minorrev=`uname -r | cut -d '.' -f 3`



case ${majorrev}${minorrev} in
	1123)

		UTILS="/usr/lbin/sw/control_utils"
		if [[ ! -f $UTILS ]]
		then
			msg ERROR "Cannot find $UTILS"
			exit 1
		fi
		. $UTILS
		exitval=$SUCCESS


		mod_systemfile ${SW_SYSTEM_FILE_PATH} -d drp
		retval=$?
		if [[ $retval -ne $SUCCESS ]]
		then
			[[ $retval -ne $SUCCESS && $exitval -ne $FAILURE ]] &&
			exitval=$retval
		fi

		rm -f /usr/conf/mod/drp

	;;


	*)


		#
		# Remove "drp" from the system file.
		#
		if [[ ! -f $SW_SYSTEM_FILE_PATH ]]
		then
			echo "ERROR:   Couldn't find the system file."
			exit 1
		fi

		cat $SW_SYSTEM_FILE_PATH | \
			awk '( $0 != "drp" ) { print $0 }' > \
			${SW_SYSTEM_FILE_PATH}.new.tmp.digi

		if [[ ! -f ${SW_SYSTEM_FILE_PATH}.new.tmp.digi ]]
		then
			echo "ERROR:   Couldn't create new system file."
			exit 1
		fi

		cp ${SW_SYSTEM_FILE_PATH}.new.tmp.digi ${SW_SYSTEM_FILE_PATH}
		if [[ $? -ne 0 ]]
		then
			echo "ERROR:   Couldn't replace system file."
			exit 1
		fi

		rm -f ${SW_SYSTEM_FILE_PATH}.new.tmp.digi

		rm -f /usr/conf/lib/drp.a
		rm -f /usr/conf/master.d/drp

	;;

esac


#
# Remove the OS version specific binaries
#
rm -f /usr/bin/ditty
rm -f /usr/local/bin/dinc
rm -f /usr/bin/dinc
rm -f /sbin/drpd
rm -f /sbin/dgipserv
rm -f /sbin/dgelreset

exit 0
