#! /bin/csh -f
#
# Copyright (c) 1993-1996 CheckPoint Software Technologies Ltd.
# All Rights Reserved
#
# THIS IS 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/cisco/Attic/fwcisco.csh,v 1.6.2.2 1996/10/23 09:36:42 gh Exp $
#

if (! $?FWDIR) then 
	setenv FWDIR /etc/fw
endif

set path = ( $FWDIR/bin $FWDIR/cisco $path )
set echo_timeout = 300

if (! $?FWCONFDIR) then
	setenv FWCONFDIR $FWDIR/conf
endif

if ($#argv != 5) then
	echo "Usage: $0 [put|get] router passwd enable-passwd $FWCONFDIR/file"
	exit(1)
endif

cd $FWDIR/cisco

switch ($1)
	case "put":

		echo -n "Putting $5 on $2... "

		echo "set timeout $echo_timeout" > $FWCONFDIR/$5.exp
		awk 'NF > 0 && ! /^\!/ { \
			printf("\n"); \
			printf("send \"%s\\r\"\n", $0); \
			printf("expect {%s} {} \\\n", $0); \
			printf("\ttimeout {send_error \"Write failed.\\n\"; exit 1}\n")}' < $FWCONFDIR/$5 >> $FWCONFDIR/$5.exp

		(expect $FWDIR/cisco/fwciscoput $2 $3 $4 $FWCONFDIR/$5.exp > /dev/null) |& uniq

		set rc = $status
		if ($rc == 0) then
			echo "Done"
			exit(0)
		else
			exit(1)
		endif
		breaksw
	case "get":
		echo "******** get $5 from $2 ********"
		expect $FWDIR/cisco/fwciscoget $2 $3 $4 $5 $FWCONFDIR
		set rc = $status
		if ($rc == 0) then
			echo "******** $1 Done ********"
			exit(0)
		else
			echo "******** $1 Failed ********"
			exit(1)
		endif
		breaksw
	default:
			echo "$0 : Unknown command $1"
			set rc = 1
endsw
exit(1)
