#!/bin/bash

prefix=/usr/local
ETC=${prefix}/etc

set -m

gui=`grep "gui=" $ETC/kismet.conf | cut -d= -f2 | tr -d [:space:]`

if [ "$gui" = "" ]; then
	echo "No gui specified in $ETC/kismet.conf.  Please specify one!"
	exit
fi

mode="server"
while [ "$1" != "" ]; do
	if [ "$1" = "-h" ]; then
		echo "$0 [server options] -- [client options]"
		echo "ex: $0 -c prism2 -p 5000 -- -q -p 5000"
		echo "to start the server with a prism/2 capture source on port 5000 and start the"
		echo "client in quiet mode on the same port."
		exit
	elif [ "$1" = "--" ]; then
		mode="client";
	elif [ "$mode" = "server" ]; then
		server="$server $1"
	elif [ "$mode" = "client" ]; then
		client="$client $1"
	fi

	shift
done

if [ "$server" = "" ]; then
	echo "Server options:  none"
else
	echo "Server options:  $server"
fi

if [ "$client" = "" ]; then
	echo "Client options:  none"
else
	echo "Server options:  $client"
fi

echo "Starting server..."
kismet_server --silent $server &

servpid=$!

sleep 3

echo "Starting UI..."
kismet_curses $client

kill $servpid

wait %-

echo "Terminating..."

