#!/bin/sh

# development usage: KEEP THIS COMMENTED.
#PATH=$PATH:./

OPTIONS="-d"

# build the lockfile name
lfile=/tmp/jtrigger-`whoami`.lock

# if there is no lockfile, start the daemon
if !(test -f $lfile); then
	jtriggerd $OPTIONS > $lfile

# otherwise, query the server and see if it's alive
else 
	if (jtrigger-isalive `cut -b3- < $lfile`); then
		jtriggerd $OPTIONS > $lfile
	fi 	
fi

# now check to make sure we didn't 
# have an error when it started
if (test `cut -b1 < $lfile` = "X"); then
	echo "Daemon returned error:`cut -b3- < $lfile`"
	killall jtriggerd
	rm -rf $lfile
	exit 1
fi

# start the user interface, we're good to go
exec jtrigger-fltk `cut -b3- < $lfile`

