:
#      @(#)sco_tcp	5.6.1.4 Lachman System V STREAMS TCP  source
#      SCCS IDENTIFICATION
#
#	System V STREAMS TCP - Release 4.0
#
#	Copyright 1987, 1988, 1989 Lachman Associates, Incorporated (LAI)
#
#	All Rights Reserved.
#
#	The copyright above and this notice must be preserved in all
#	copies of this source code.  The copyright above does not
#	evidence any actual or intended publication of this source
#	code.
#
#	This is unpublished proprietary trade secret source code of
#	Lachman Associates.  This source code may not be copied,
#	disclosed, distributed, demonstrated or licensed except as
#	expressly authorized by Lachman Associates.
#
#	System V STREAMS TCP was jointly developed by Lachman
#	Associates and Convergent Technologies.
#
#
: ${OK=0} ${FAIL=1} ${RELINK=2}
PATH=/bin:/usr/bin:/etc:/etc/conf/bin

LOWER_PRD=$1
LOWER_IF=$2
UPPER_PRD=$3
UPPER_IF=$4
CONFIGURE=$5

# Shell Variables from lli Driver
#------------------------------------------------------------------------
# NODE - Required to remove device from osi configuration file. 
#------------------------------------------------------------------------

#
# Miscellaneous variable declarations
#
tmp=/tmp/sco_tcp$$

#
# Parameters used by the functions in tcp_nfs.comm
#
PRODUCT="TCP/IP"
PERMSLIST=/etc/perms/tcprt
LKPERM=/etc/perms/inst
DRIVERDIR=/usr/lib/tcprt/ID
DRIVERS="arp cp ip rip socket arpproc icmp llcloop tcp udp"
KPARAMS="NINODE -150 \
	 NS5INODE -150 \
	 NFILE -150 \
	 NQUEUE -768 \
	 NSTREAM -128 \
	 NBLK4096 -12 \
	 NBLK2048 -32 \
	 NBLK1024 -32 \
	 NBLK512 -64 \
	 NBLK256 -128 \
	 NBLK128 -256 \
	 NBLK64 -256 \
	 NBLK16 -256 \
	 NBLK4 -256"
_upgrade=
_no_prompt=
_reconfig=

#
# If the common functions file doesn't exist, we won't get very far
#
COMMONFILE=/usr/lib/netconfig/bin/tcp_nfs.comm

if [ ! -r $COMMONFILE ]
then
	echo "\nError: Missing or unreadable $COMMONFILE." >&2
	exit ${FAIL}
fi

. $COMMONFILE

##############################################################################
# main()
#
trap "cleanup $FAIL" 1 2 3 15

[ "$CONFIGURE" != "N" ] && message "Removing $PRODUCT from the system ... \n"

# Clean up /etc/ppphosts for a ppp line removal
[ "$LOWER_PRD" = "ppp0" -o "$LOWER_PRD" = "ppp1" -o "$LOWER_PRD" = "ppp2" -o "$LOWER_PRD" = "ppp3" ] && {
	old_config=`grep "$LOWER_PRD" /etc/tcp | fgrep "ifconfig"`
	if [ -n "$old_config" ] ; then
		PPP_REM_IP=`echo $old_config | awk '{ print $4 }'`
		PPP_LOC_IP=`echo $old_config | awk '{ print $3 }'`
		if [ -n "$PPP_REM_IP" ] ; then
			grep -v "$PPP_REM_IP[ 	]" /etc/ppphosts >$tmp
			mv $tmp /etc/ppphosts
			grep -v "$PPP_REM_IP[ 	]" /etc/hosts >$tmp
			mv $tmp /etc/hosts
		fi
		if [ -n "$PPP_LOC_IP" ] ; then
			grep -v "$PPP_LOC_IP[ 	]" /etc/hosts >$tmp
			mv $tmp /etc/hosts
		fi
	fi
}

# This takes care of cleaning up /etc/tcp and /etc/strcf. It needs to be done
# whether the CONFIGURE variable is "Y" or "N". $1 is the driver prefix.
[ "$LOWER_PRD" != "lo0" ] && {
	grep -v "ifconfig $1" /etc/tcp >/tmp/sco_tcp$$
	cp /tmp/sco_tcp$$ /etc/tcp
	chmod u+rwx,go-rw+x /etc/tcp
}

grep -v "net[cb]\{0,1\}[ ]ip.*$1" /etc/strcf >/tmp/sco_tcp$$
cp /tmp/sco_tcp$$ /etc/strcf
chmod u+rw-x,go+r-wx /etc/strcf

cd /
[ "$CONFIGURE" = "N" ] && cleanup $OK

_no_prompt=TRUE chklinkkit		# Inform user of link-kit status

#
# check if snmp is configured.  if so exit with warning
#
if [ -f /etc/rc2.d/S89snmp ] ; 
  then
	echo "\nSnmp is still configured. Please run mkdev snmp to deconfigure snmp"
	echo "from the system before removing sco_tcp."
	cleanup $FAIL
fi

#
# check if remote line printing is configured.  if so exit with warning
#
if [ -f /etc/rc2.d/S86lpd ] ; then
	echo "\nRemote Line Printing is still configured. Please run mkdev rlp to "
	echo "deconfigure rlp from the system before removing sco_tcp."
	cleanup $FAIL
fi

echo "Stopping TCP/IP ... \c"
/etc/tcp stop 2>/dev/null 1>&2
echo "done."

#
# remove the SENDMAIL stuff
#
savedir=/usr/lib/custom/save
if [ -f $savedir/.sndmailpaths ]
then
	echo "Shutting down sendmail and removing the configuration file
s..."
	ps -e | awk "/sendmail/ { print \"kill \" \$1 }" | sh
	sleep 3
	(
	cd /
	rm -f /usr/lib/sendmail.cf /usr/lib/sendmail.fc

	#
	# Move the saved files back where they came from
	#
	while read x
	do
		set `echo $x`
		mv $savedir/$1 $2 || { cp $savedir/$1 $2; rm $savedir/$1 ; }
	done <  $savedir/.sndmailpaths
	)
fi

/bin/rm -f /usr/bin/mailq /usr/bin/newaliases
/bin/rm -f /usr/lib/mail/aliases.dir /usr/lib/mail/aliases.pag

remove_drivers			# Remove drivers
set_kernel_params		# Reset kernel parameters

#
# Remove special files so that immediate re-install will work.
#
rm -rf /dev/inet
rm -f /dev/llcloop /dev/socksys* /dev/slip /dev/asyh /dev/pp*
rm -f /dev/nb /dev/nb-dg /dev/nbclts /dev/nbcots

#
# Remove other random things
#
rm -f /etc/rc2.d/S85tcp /etc/rc0.d/K85tcp
rm -f /etc/rc2.d/S86lpd /etc/rc0.d/K79lpd
rm -f /etc/rc2.d/S89snmp /etc/rc0.d/K79snmp
rm -f /etc/rc2.d/S86netbios /etc/rc0.d/K72netbios

rm -f /usr/spool/rwho/* /etc/netstat_data /usr/spool/locks/*
rm -f /etc/arp_data /etc/trpt_data

message "\nRemoval of $PRODUCT complete.\n"

cleanup $RELINK
