#! /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/fwstart.csh,v 1.15.2.1 1996/04/11 09:59:17 yoav Exp $
#
if ( -f /kernel/genunix || -f /kernel/unix ) then
	set solaris2 = 1
else
	set solaris2 = 0
endif

if ( -f /hp-ux || -f /stand/vmunix ) then
	set hpux = 1
else
	set hpux = 0
endif

set dir = $0:h
set dir = $dir:h
if (-d $dir && -x $dir/bin/fwstart) then
	setenv FWDIR $dir
endif

if (! $?FWDIR) setenv FWDIR /etc/fw
set path = ( $FWDIR/bin /bin /usr/bin /etc /usr/etc )
set name = `uname -m`.`uname -r`
set name1 = `uname -r`

if ( $solaris2 != 1 && $hpux != 1) set fwload

$FWDIR/bin/fw putlic -k 0 0-0-0 0

set masters
if ( -f $FWDIR/conf/masters ) then
	set masters = ( `cat $FWDIR/conf/masters` )
endif

if ($?fwload) then
	set fwmod = $FWDIR/modules/fwmod.$name.o
	set fwmod1 = $FWDIR/modules/fwmod.$name1.o
	if (! -f $fwmod && ! -f $fwmod1) then
		echo "FW-1: No module for $name"
		echo "FW-1: failed"
		exit 1
	endif
	if (! -f $fwmod) set fwmod = $fwmod1
	modstat | grep -s fw
	if ($status == 0) then
		echo "FW-1: Module already installed, perform fwstop"
		echo "FW-1: failed"
		exit 1
	endif
	echo 'FW-1: Loading kernel module...'
	modload $fwmod -exec $FWDIR/modules/fw.mkdev
else
	if ($hpux) then
		fw putlic -k
		if ($status) then
			echo 'FW-1: failed to install license'
			exit 1
		endif
	endif
	fw ctl install
	if($status) then
		echo 'FW-1: failed to install'
		exit 1
	endif
endif

sync ; sync ; sync

echo 'FW-1: Starting fwd'
fwd $masters
if ($status) then
	echo 'FW-1: failed to start fwd'
	echo 'FW-1: failed'
	exit 1
endif
echo 'FW-1: Starting snmpd'
nohup snmpd
if ($status) then
	echo 'FW-1: failed to start snmpd'
endif

if (-f $FWDIR/bin/fwm) then
	echo 'FW-1:  Starting fwm (Remote Management Server)'
	fwm
	if ($status) then
		echo 'FW-1: failed to start fwm'
	endif
endif

echo ""

fw isonlycontrol >& /dev/null
if ($status) then
	echo "FW-1: This a Control Station. No Security Policy will be Loaded"
	echo "FW-1 started"
	exit 0
endif

set masters = ( $masters localhost )

echo "FW-1: Fetching Security Policy from $masters"
fw fetch $masters
set err = $status

echo 'FW-1 started'


exit $err

if ($err && -f $FWDIR/lib/default.pf) then
	echo 'FW-1: Loading default Security Policy...'
	fw load $FWDIR/lib/default.pf all.all
	if ($status) exit 1
	set err = 2
endif
if ($err && ! -f $FWDIR/lib/default.pf) then
	echo FW-1: $FWDIR/lib/default.pf not found
	echo FW-1: No Security Policy loaded
	exit 1
endif

echo 'FW-1 started'

exit $err
