#!/bin/bash
#
#help
#Syntax:   runsk [-r] filename [-dv| -d -v]
#Function  Tests spamkiller against the selected file
#          with -r=MG_ and using nc as a simple 
#          client-server pair to provide pacing.
#Options:  -r = regression test mode
#          -d = run with -d option
#          -v = run with -v option
#end 
if [ "$1" == '-?' ]
then
	script_help $0
	exit
fi

opts=""
reg=N
file=""
for x in $@ 
do
	case $x in 
	-r)	reg=Y;;
	-*)	opts="$opts $x";;
	*)	file=$x;;
	esac
done

if [ -z "$file" ]
then
	echo "File name not provided"
	exit 1
fi
if [ ! -r "$file" ]
then
	echo "Can't find $file"
	exit 1
fi

if [ $reg == 'Y' ]
then
	rname=$(basename $file)
	nc -l 16020 | diff - results/$rname &
else
	nc -l 16020 &
fi

echo "Running a test on $file, opts=$opts"
echo "-----------------------------------"
spamkiller $opts -r -c="nc localhost 16020" <$file
