#!/bin/sh

#DISPLAY=localhost:0
#export DISPLAY

DIR=`echo "$0"|sed 's/^\(.*\/\).*$/\1/'`
CURDIR=`pwd`
cd ${DIR}
SS_DIR=`pwd`
cd ${CUR_DIR}
echo "SS dir = ${SS_DIR}"
cd ${SS_DIR}

if [ "$DISPLAY" = "" ] ; then
DISPLAY=`ps -axw|grep Xvfb |grep -v grep| gawk '{print $6 } '`
fi

if [ "$DISPLAY" = "" ] ; then
	echo cannot find Xfb started, please install and start it.
	exit 1 
fi

export DISPLAY
 
export CLASSPATH=./:./ss.jar:./freemarker.jar:./ecs-1.1.jar:./Acme.jar:./activation.jar:./com.fooware.net.jar:./xalan.jar:./log4j.jar:./log4j-core.jar:./mail.jar:./gnu.regexp.jar:./postgresql.jar:./mm.mysql.jar:./classes12_01.zip:./jai_codec.jar:./jai_core.jar:./glf.jar:./xml-apis.jar

export TOMCAT_HOME=./tomcat
#export JAVA_HOME=/usr/java/jdk1.3.1

if [ "$JAVA_HOME" = "" ] ; then
	echo JAVA_HOME not set, you need to set it to dir where SUN jdk 1.3 is installed
	exit 1
fi

if [ "$1" = "start" ] ; then
	
echo "Starting tomcat ..."
$TOMCAT_HOME/bin/tomcat.sh start 1>>$TOMCAT_HOME/logs/tomcat.log 2>&1 &
echo "Starting image maker."
./imaker.sh 1>$SS_DIR/logs/imaker.log 2>&1 &
exit 0

fi

if [ "$1" = "stop" ] ; then
	
echo "Stoping tomcat."
$TOMCAT_HOME/bin/tomcat.sh stop 1>>$TOMCAT_HOME/logs/tomcat.log 2>&1 &
echo "Stoping image maker."
killall imaker.sh
kill -9 `ps -axw|grep ImageMakerServer |grep -v grep| gawk '{print $1 } '`
exit 0	

fi

echo Usage:
echo "ss.sh (start|stop)"
echo "        start - start SS in the background"
echo "        stop  - stop SS"


