#! /bin/csh -f
#
# Copyright (c) 1993-1996 CheckPoint Software Technologies Ltd.
# All Rights Reserved
#
# THIS IS AN UNPUBLISHED PROPRIETARY SOURCE CODE OF CHECKPOINT SOFTWARE
# TECHNOLOGIES LTD. The copyright notice above does not evidence any actual
# or intended publication of such source code.
#
# $Header: /fw/cvs/fw-1/fwutil/fwuninstall.csh,v 1.10.2.3 1996/06/19 12:03:31 yuval Exp $
#
alias get 'set \!^ = $<'

if ( -f /kernel/genunix || -f /kernel/unix ) then
	set solaris2 = 1
	set sunos4 = 0
	set hpux = 0
else if (-f /hp-ux) then
	set hpux = 9
	if (`uname -m | sed -e 's/^.*\///' -e 's/\(.\).*/\1/'` == 7) then
		set hpux700 = 1
		set hpux800 = 0
	else
		set hpux700 = 0
		set hpux800 = 1
	endif
	set solaris2 = 0
	set rcfile = /etc/rc
	set sunos4 = 0
else if (-f /stand/vmunix) then
	set hpux = 10
	set solaris2 = 0
	set sunos4 = 0
else
	set solaris2 = 0
	set sunos4 = 1
	set hpux = 0
	set rcfile = /etc/rc.local
endif

if (! $?FWDIR) then
	if ($?BASEDIR) setenv FWDIR $BASEDIR
endif

if (! $?FWDIR) setenv FWDIR = /etc/fw

$FWDIR/bin/fwstop

#
# Remove Authentication code from /etc/inetd.conf
#
ex - /etc/inetd.conf << EOEX >& /dev/null
%s/^#FW: //
w!
q
EOEX

if ( $sunos4 || $hpux == 9) then
	if ( $sunos4 ) then
		grep -s FW-1 $rcfile >& /dev/null
	else
		grep -q -s FW-1 $rcfile
	endif
	if ($status == 0) then
		ex - $rcfile << EOEX
/^# FW-1/,/^# FW-1 END/d
w!
q
EOEX
	endif
endif

if ( $solaris2 ) then
	/bin/rm -f /etc/rc3.d/S[0-9][0-9]firewall1 /etc/init.d/firewall1 >& /dev/null
	egrep -s fw /etc/name_to_major
	if ($status == 0) then
		/usr/sbin/rem_drv fw
	endif
endif

if ($hpux == 9) then

	echo ""
	echo -n "Enter kernel configuration directory [/etc/conf]: "
	get kdir
	if (x$kdir == x) set kdir = /etc/conf

	echo ""
	echo -n "Enter master device information table file [/etc/master]: "
	get master
	if (x$master == x) set master = /etc/master

	if ($hpux700) then
		echo ""
		echo -n "Enter system description file [$kdir/dfile]: "
		get dfile
		if (x$dfile == x) set dfile = $kdir/dfile
		set libfile = $kdir/libusrdrv.a
	else
		echo ""
		echo -n "Enter system description file [$kdir/gen/S800]: "
		get dfile
		if ("X$dfile" == X) set dfile = $kdir/gen/S800
		set libfile = $kdir/lib/libusrdrv.a
	endif

	echo ""
	ar dv $libfile fwmod.hpux9.o
	set size = `ls -l $libfile`
	if ($size[5] == 8) rm -f $libfile

	if ($hpux700) then
		if ( { grep -q fw $master } ) then
			ex - $master << EOF
/^fw/d
w!
q
EOF
		endif

		if ( { grep -q fw $dfile } ) then
			ex - $dfile << EOF
/^fw/d
w!
q
EOF
		endif

		( cd $kdir && /etc/config -m $master $dfile && make -f config.mk ROOT=$kdir )
		set hpkernelfile = $kdir/hp-ux
	else
		if ( { grep -q driver\ fw $master } ) then
			ex - $master << EOF > /dev/null
/driver\ fw
.,.+5d
w!
q
EOF
		endif

		if ( { grep -q fw $dfile } ) then
			ex - $dfile << EOF > /dev/null
/include fw/d
w!
q
EOF
		endif

		( cd $dfile:h && /etc/uxgen $dfile:t )
		set hpkernelfile = $kdir/$dfile:t/hp-ux
	endif
	rm -f /dev/fw0
	echo "To remove the firewall-1 driver from your kernel"
	echo "copy $hpkernelfile to /hp-ux and reboot"
endif

if ($hpux == 10) then
	echo ""
	echo -n "Enter kernel configuration directory [/etc/conf]: "
	get kdir
	if ("X$kdir" == X) set kdir = /etc/conf

	echo ""
	echo -n "Enter master device information tables directory [$kdir/master.d]: "
	get master
	if ("X$master" == X) set master = $kdir/master.d

	echo ""
	echo -n "Enter system description file [/stand/system]: "
	get dfile
	if ("X$dfile" == X) set dfile = /stand/system

	echo ""

	/bin/rm -f $kdir/lib/libfw.a $master/firewall1 /dev/fw0 >& /dev/null
	/bin/rm -f /sbin/rc[23].d/S[0-9][0-9][0-9]firewall1 /sbin/init.d/firewall1 >& /dev/null

	if ( { grep -q fw $dfile } ) then
		ex - $dfile << EOF
/^fw/d
w!
q
EOF
	endif

	mk_kernel -s $dfile -o /stand/build/vmunix_nofw
	echo ""
	echo "To remove FireWall-1 from the kernel, copy /stand/build/vmunix_nofw to"
	echo "/stand/vmunix and reboot"
endif

exit 0
