#!/bin/sh
#
# Script to download a rulebase for CGPSNF.
#
# Copyright (C) 2009 by MicroNeil Corporation. All rights reserved.
## See www.armresearch.com for the copyright terms.
#

#
# Replace authenticationxx and licensid with your license info.
#

SNIFFER_PATH=/var/CommuniGate/CGPSNF
SNF2CHECK=$SNIFFER_PATH/SNF2Check
AUTHENTICATION=authenticationxx
LICENSE_ID=licenseid

#
# Do not modify anything below this line.
#

cd $SNIFFER_PATH

if [ -e UpdateReady.txt ] && [ ! -e UpdateReady.lck ]; then

#       Uncomment the following line if more than one process might 
#       launch this script. Leave it commented out if this script will
#       normally be run by the <update-script/> mechanism in CGPSNF
#	touch UpdateReady.lck

	curl http://www.sortmonster.net/Sniffer/Updates/$LICENSE_ID.snf --output $LICENSE_ID.new --compressed --user sniffer:ki11sp8m --remote-time --fail

        $SNF2CHECK $LICENSE_ID.new $AUTHENTICATION 
 	RETVAL=$?
        if [ $RETVAL -eq 0 ]; then 

                if [ -e $LICENSE_ID.old ]; then rm -f $LICENSE_ID.old; fi
                if [ -e $LICENSE_ID.snf ]; then mv $LICENSE_ID.snf $LICENSE_ID.old; fi
                mv $LICENSE_ID.new $LICENSE_ID.snf

		if [ -e UpdateReady.txt ]; then rm -f UpdateReady.txt; fi
		if [ -e UpdateReady.lck ]; then rm -f UpdateReady.lck; fi

	else

		if [ -e $LICENSE_ID.new ]; then rm -f $LICENSE_ID.new; fi
		if [ -e UpdateReady.lck ]; then rm -f UpdateReady.lck; fi

	fi
fi

