#!/bin/bash
# contributed by Marcel <user04113@softhome.net>, 2004.
# and later modified by shizuma@vif.net and Javier Fernandez-Sanguino
# to support oinkcodes
# 
# Note that this script is more error-prone than the oinkmaster
# scripts. It is recommended you install the 'oinkmaster' package
# if you want to update Snort rules
#
# Example cron-entry:
#
# 7 0 * * * test -r /usr/local/bin/snort-update && /usr/local/bin/snort-update
#

vers=snapshot-CURRENT
# vers=snapshot-2-7

# get your snort code at www.snort.org and enter it here
oinkcode=""

if [ -z "$oinkcode" ] ; then
    echo "You need an oinkcode to run this script!" >&2
    echo "Aborting" >&2
    exit 1
fi

/etc/init.d/snort stop
pushd /tmp
wget http://www.snort.org/pub-bin/oinkmaster.cgi/${oinkcode}/snortrules-${vers}.tar.gz && ( \
	tar zxf snortrules-${vers}.tar.gz; \
	test "$vers" == "snapshot-2_1" && rm rules/netbios.rules; \
	mv rules/*.rules /etc/snort/rules/; \
	rm rules/snort.conf; \
	mv rules/* /etc/snort/; \
	rmdir rules; \
	rm snortrules-${vers}.tar.gz; \
	chown -R root.root /etc/snort/*; \
)
popd
/etc/init.d/snort start
