#! /bin/csh -f

#
# should FW be started automaticly on boot time ?
#
source scripts/aliases

dorc:

	fwrand

	if ($solaris2) then
		/bin/rm -f /etc/rc[23].d/S[0-9][0-9]firewall1 >& /dev/null
		/bin/rm -f /etc/init.d/firewall1 >& /dev/null

		if (!($?bootmodifications)) then
			set autodef=no
			goto donerc
		endif

		set autodef=yes

		set rcfile = /etc/init.d/firewall1

		set ln_rcfile = /etc/rc3.d/S95firewall1
		cat > $rcfile << EOCAT
#!/bin/sh
# FW-1 Start
$shell_if [ -f $FWDIR/bin/fwstart ]; then
	FWDIR=$FWDIR
	export FWDIR
	$FWDIR/bin/fwstart
fi
# FW-1 END
EOCAT
		ln -f $rcfile $ln_rcfile
		chown root $rcfile $ln_rcfile
		chgrp sys $rcfile $ln_rcfile
		chmod 744 $rcfile $ln_rcfile
		E ""
		E "$product startup code installed in /etc/rc3.d"
		goto donerc
	endif

	if ($hpux == 10) then
		/bin/rm -f /sbin/rc[23].d/S[0-9][0-9][0-9]firewall1 >& /dev/null
		/bin/rm -f /sbin/init.d/firewall1 >& /dev/null

		if (!($?bootmodifications)) goto donerc

		set rcfile = /sbin/init.d/firewall1
		set ln_rcfile = /sbin/rc2.d/S485firewall1
		cat > $rcfile << EOCAT
#!/sbin/sh
case \$1 in
	start_msg)
		print "Start $product Internet Security Software"
		exit 0
		;;

	stop_msg)
		print "Stop $product Internet Security Software"
		exit 0
		;;

	stop)
		$shell_if [ -f $FWDIR/bin/fwstop ]; then
			FWDIR=$FWDIR
			export FWDIR
			$FWDIR/bin/fwstop
			exit \$?
		fi
		exit 1
		;;

	start)
		$shell_if [ -f $FWDIR/bin/fwstart ]; then
			FWDIR=$FWDIR
			export FWDIR
			$FWDIR/bin/fwstart
			exit \$?
		fi
		exit 1
		;;

	*)
		print "USAGE: \$O {start_msg | stop_msg | start | stop}" >&2
		exit 1

esac
EOCAT
		ln -s $rcfile $ln_rcfile
		chown root $rcfile $ln_rcfile
		chgrp sys $rcfile $ln_rcfile
		chmod 555 $rcfile $ln_rcfile
		E ""
		E "$product startup code installed in /sbin/rc2.d"
		goto donerc
	endif

# 	sunos4 ,hpux, or aix
	egrep FW-1 $rcfile >& /dev/null
	if ($status == 0) then
		E ""
		E "Deleting old FW-1 startup code from $rcfile"
		ex - $rcfile << EOF >& /dev/null
/^# FW-1/,/^# FW-1 END/d
w!
q
EOF
	endif
	if (!($?bootmodifications)) goto donerc
	if ($hpux) then
		ex - $rcfile << EOF >& /dev/null
?localrc()?+a
# FW-1 Start
$shell_if [ -f $FWDIR/bin/fwstart ]; then
	FWDIR=$FWDIR
	export FWDIR
	$FWDIR/bin/fwstart
fi
# FW-1 END
.
w!
q
EOF
	else
		cat >> $rcfile << EOF
# FW-1 Start
$shell_if [ -f $FWDIR/bin/fwstart ]; then
	FWDIR=$FWDIR
	export FWDIR
	$FWDIR/bin/fwstart -o
fi
# FW-1 END
EOF
	endif
	E ""
	E "$product startup code installed in $rcfile"

donerc:
	exit 0
