#!/bin/bash

# install this to /etc/init.d/snort

ROOT_UID=0   # Root has $UID 0.

if [ "$UID" -eq "0" ]  # Will the real "root" please stand up?
then
  echo "You are root. Running."
else
  echo "Please run this as root."
  exit
fi

# restart capability, added 2/4/11 by tgiles

if [ "$1" = "r" ]
then
  echo "restarting snort. hang on"

  # stopping part

  SNORT_PIDS=`cat /var/run/*snort*pid`
  echo "killing snort PID's:" $SNORT_PIDS
  kill -9 $SNORT_PIDS
  rm -rf /var/run/*snort*pid
  echo "snort is stopped"
  sleep 4

rm -rf /var/log/snort/*

  # starting part

  for i in `/sbin/ifconfig | grep eth | /usr/bin/awk ' { print $1 } '`
  do
  /opt/snort/bin/snort -i $i -c /opt/snort/etc/snort.conf -D -F /opt/snort/excludes.conf --perfmon-file /opt/snort/snort.perfmon.$i.csv &
  echo "starting snort for $i with PID $!"
  done

else

# end of snort restart capability

        if [ -a /var/run/snort_eth0.pid ]; then

echo "snort running. Killing it off now"

SNORT_PIDS=`cat /var/run/*snort*pid`
echo "killing snort PID's:" $SNORT_PIDS
kill -9 $SNORT_PIDS
rm -rf /var/run/*snort*pid

else

echo "snort is not running. starting snort"

for i in `/sbin/ifconfig | grep eth | /usr/bin/awk ' { print $1 } '`
do
/opt/snort/bin/snort -i $i -c /opt/snort/etc/snort.conf -D -F /opt/snort/excludes.conf --perfmon-file /opt/snort/snort.perfmon.$i.csv &
echo "starting snort for $i with PID $!"
done

fi

fi
