#!/bin/sh

PRODUCT="Solstice FireWall-1"
if [ -d "$BASEDIR/bin" ]; then
	FWDIR=$BASEDIR
fi

#
# OS release, 4 or 5
#
OSREL=`/usr/bin/uname -r | sed 's/\./\ /' | awk '{print $1}'`

# stop fw-1, first of all
echo "Stopping $PRODUCT, if running..."
if [ $?FWDIR ]; then
	$FWDIR/bin/fwstop > /dev/null 2> /dev/null
fi

# remove link from /etc/fw to $FWDIR
if [ -h /etc/fw ]; then
	echo "Removing /etc/fw and /etc/fw.OLD symlinks..."
	rm -rf /etc/fw /etc/fw.OLD
fi

# recover system files
solaris2=1
export solaris2
$FWDIR/scripts/sysrestore


# remove kernel module
if [ $OSREL -eq 5 ]; then
 echo "Removing kernel module..."
 egrep -s fw /etc/name_to_major
 if [ $? -eq 0 ]; then
	/usr/sbin/rem_drv fw
	sync
 fi
 /bin/rm -f /usr/kernel/drv/fw /usr/kernel/drv/fw.conf /dev/fw0 2>&1 > /dev/null
fi

# restore telnet and ftp in /etc/inetd.conf
if [ -f $FWDIR/conf/fwauthd.conf ]; then
	echo "Restoring telnet, ftp, and/or httpd in /etc/inetd.conf..."
	ed - /etc/inetd.conf << EOEX 2>&1 > /dev/null
1,\$s/^#FW: //
w
q
EOEX
	/bin/rm -f $FWDIR/conf/fwauthd.conf
	if [ $OSREL -eq 5 ]; then
	 inetdpid=`/usr/bin/ps -e | fgrep -v fgrep | fgrep inetd | awk '{print $1}'`
	else
	 inetdpid=`/usr/bin/ps -gx | fgrep -v fgrep | fgrep inetd | awk '{print $1}'`
	fi
	if [ "$inetdpid" != "" ]; then
		kill -HUP $inetdpid
	else
		echo "*** Note:	you will need to restart inetd for original"
		echo "         	ftp and telnet servers to become active."
	fi

fi

exit 0
