#ident	"@(#)pkg.inet:i386/pkg/inet/preremove	1.5.9.10"
#ident	"$Header: $"

PKGMSG=${PKGINST}.pkg
LOCALE=${LC_ALL:-${LC_MESSAGES:-${LANG:-"C"}}}

if [ ! -f /usr/lib/locale/${LOCALE}/LC_MESSAGES/${PKGMSG} ]
then
   if [ -f ${REQDIR}/inst/locale/${LOCALE}/${PKGMSG} -a \
	-d /usr/lib/locale/${LOCALE}/LC_MESSAGES ]
   then
	cp ${REQDIR}/inst/locale/${LOCALE}/${PKGMSG} \
	   /usr/lib/locale/${LOCALE}/LC_MESSAGES
   fi
fi
#	
#	STREAMware TCP
#	Copyright 1987, 1993 Lachman Technology, Inc.
#	All Rights Reserved.
#	
#
# Issue a warning message if inet is running.
#
TMP=/tmp/tcp.err
ERROR1=`pfmt -s nostd -g ${PKGMSG}:101 "An error was encountered removing the %s package. The file %s contains errors reported by the system." ${NAME} ${TMP} 2>&1`
ERROR2=`pfmt -s nostd -g ${PKGMSG}:102 "The kernel rebuild failed.  However all software dealing with the %s package has been removed." ${NAME} 2>&1`

if [ ! -z "`ps -ef | grep slink | grep -v grep`" ]
then
	pfmt -s warn -g ${PKGMSG}:103 " inet (slink) is still running.\n" 2>&1

fi

#
# remove the "/dev/inet	MF" entry from /etc/ttysrch.
#
grep -v "/dev/inet	MF" /etc/ttysrch >/tmp/$$.a1
cp /tmp/$$.a1 /etc/ttysrch
rm -f /tmp/$$.a1

# unconfigure inet protocols for multiple boards.
/etc/confnet.d/configure -r -pinet

#
# Deinstall INET
#
for MODULE in app arp asyh icmp inet ip llcloop ppp rawip route slip tcp udp 
do
	/etc/conf/bin/idcheck -p ${MODULE} 2> /dev/null
	RES="$?"
	if [ "${RES}" -ne "100" -a "${RES}" -ne "0" ]
	then
		/etc/conf/bin/idinstall -P ${PKGINST} -d ${MODULE} 2>> $TMP
		if [ $? != 0 ]
		then
			message $ERROR1
			exit 1
		fi
		REBUILD=1
	fi
done


#remove entries added to the device database
for DEVICE in arp icmp ip llcloop rawip tcp udp tcp_subdev ppp
do
	# Error may only indicate we are not running an ES system
	# or entry does not exist.
	MSG="`putdev -d ${DEVICE} 2>&1`"
	RETURN=$?
	if	[ "$RETURN" = 1 -o "$RETURN" = 2 -o "$RETURN" = 5 ]
		# there's a fatal error that will affect the other devices, too.
		# so print error and abort the loop
	then	pfmt -s nostd -g ${PKGMSG}:104 "Device Database Error %s when deleting %s\n" $RETURN $DEVICE 2>&1
		echo $MSG
		break
	elif	[ "$RETURN" != 0 -a "$RETURN" != 3 ]
		# return 0: everything worked.
		# return 3: entry was not there to delete
		#when none of the above, error gets printed and we loop
	then	pfmt -s nostd -g ${PKGMSG}:104 "Device Database Error %s when deleting %s\n" $RETURN $DEVICE 2>&1
		echo $MSG
	fi
done

rm -f /dev/arp /dev/icmp /dev/ip /dev/loop /dev/rawip /dev/tcp /dev/udp \
	/dev/inet/arp /dev/inet/icmp /dev/inet/ip /dev/inet/loop \
	/dev/inet/rawip /dev/inet/udp  || exit 1
rm -f /dev/ppp /dev/inet/ppp || exit 1
rm -f /dev/inet/tcp*  || exit 1

#
# Remove the entries from /etc/netconfig
#

grep -v '[ 	]inet[ 	][ 	]*tcp[ 	][ 	]*/dev/tcp[ 	]' /etc/netconfig 2>/dev/null >/tmp/$$.1
grep -v '[ 	]inet[ 	][ 	]*udp[ 	][ 	]*/dev/udp[ 	]' /tmp/$$.1 2>/dev/null >/tmp/$$.2
grep -v '[ 	]inet[ 	][ 	]*icmp[ 	][ 	]*/dev/icmp[ 	]' /tmp/$$.2 2>/dev/null >/tmp/$$.3
grep -v '[ 	]inet[ 	][ 	]*-[ 	][ 	]*/dev/rawip[ 	]' /tmp/$$.3 2>/dev/null >/etc/netconfig

rm -f /tmp/$$.1 /tmp/$$.2 /tmp/$$.3

#
# Remove *.tcp entries from /etc/uucp/Sysfiles
# Remove inet.classdb entry from dtadmin
#

if [ -s /etc/uucp/Sysfiles ]
then
	grep -v "\.tcp" /etc/uucp/Sysfiles 2>/dev/null >/tmp/Sys.$$
	cp /tmp/Sys.$$ /etc/uucp/Sysfiles
fi
if [ -s /usr/X/lib/classdb/dtadmin ]
then
	grep -v "INCLUDE[ 	]inet.classdb;" /usr/X/lib/classdb/dtadmin 2>/dev/null >/tmp/dtadmin.$$
	cp /tmp/dtadmin.$$ /usr/X/lib/classdb/dtadmin
fi

#
#	Remove ourself from the OAM Scripts...
#

#grep -v 'inet^Internet Protocols (TCP and UDP)^inet/Menu.inet' /usr/sadm/sysadm/menu/netservices/name_to_addr/map.menu 2>/dev/null >/tmp/$$.1
#cp /tmp/$$.1 /usr/sadm/sysadm/menu/netservices/name_to_addr/map.menu

#
# Remove the port monitor entry
#

sacadm -r -p inetd >/dev/null 2>&1
sacadm -r -p tcp >/dev/null 2>&1
adminuser -r inetd root >/dev/null 2>&1
#/usr/bin/adminrole -r \
#   nslookup,rdate,ifconfig,in.routed,route,nslookup,slink,arp,ruptime,rwho,in.rwhod,in.named \
#   NET >/dev/null 2>&1

if	[ "${REBUILD}" = "1" ]
then
	/etc/conf/bin/idbuild 2>> $TMP
	if [ $? != 0 ]
	then
		message $ERROR2
		exit 1
	fi
	exit 10
fi

exit 0
