#!/bin/sh

if [ -z "$1" ]
then
  echo "No testname specified, use list to --list all test names"
  exit 1
else
	TESTNAME=$1
fi

if [ "$TESTNAME" == "list" -o "$TESTNAME" == "--list" ]
then
  pushd /testing/pluto > /dev/null
  ls -d *
  popd > /dev/null
  exit 
fi

rm -f /tmp/swan.current
rm -rf /etc/ipsec*
# needed or ipsec setup stop complains about bad syntax due to missing file
touch /etc/ipsec.conf

if [ ! -f /testing/pluto/$TESTNAME/testparams.sh ]
then
	echo "Unknown or broken test case /testing/pluto/$TESTNAME"
	exit 1
else
	pidof pluto && ipsec setup stop
	echo $TESTNAME > /tmp/swan.current
	source /testing/pluto/$TESTNAME/testparams.sh
	echo "DEBUG: $TESTNAME"
fi
if [ -f /testing/pluto/$TESTNAME/`hostname`init.sh ]
then
	eval /testing/pluto/$TESTNAME/`hostname`init.sh
	echo "`hostname` initialised $TESTNAME"
else
	echo "broken test - missing /testing/pluto/$TESTNAME/`hostname`init.sh"
	exit 1
fi
