#!/bin/sh   
cd ${0%${0##*/}}.
. ./conf.sh
. ./setenv.sh

if [ -z "$JAVA_HOME" ]; then
  echo "The JAVA_HOME environment variable is not defined"
  echo "This environment variable is needed to run this program"
  exit 1
fi

WIFI_HOME=.

CLASSPATH=$WIFI_HOME
CLASSPATH="${CLASSPATH}":"$WIFI_HOME/lib/ext/bgcommon-boot.jar"

COMMON_PARAMS="-Djava.net.preferIPv4Stack=true"
PARAMS="-Dlog4j.configuration=log4j_wifi.xml  -Dlog.dir.path=log/"
MEMORY=-Xmx256m
SETUP_NAME=inet_wifi_agent


if [ "$1" = "start" ]; then
    nohup ${JAVA_HOME}/bin/java ${COMMON_PARAMS} ${PARAMS} ${MEMORY}  -cp ${CLASSPATH} ru.bitel.common.bootstrap.Boot ru.bitel.bgbilling.kernel.wifi.WiFiAgent  ${SETUP_NAME} $1  $2 $3 $4 $5 $6 > ./log/agent.out 2>&1 &
else

  if [ "$1" = "debug" ]; then
  	  #starting in debug mode
  	  nohup  ${JAVA_HOME}/bin/java ${COMMON_PARAMS} ${PARAMS} ${MEMORY} -cp ${CLASSPATH} -enableassertions -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=5589,server=y,suspend=n  ru.bitel.common.bootstrap.Boot ru.bitel.common.bootstrap.Boot ru.bitel.bgbilling.kernel.wifi.WiFiAgent  ${SETUP_NAME} start $2 $3 $4 $5 $6 > ./log/agent.out 2>&1 &
  else    
	${JAVA_HOME}/bin/java ${COMMON_PARAMS} ${MEMORY} -cp ${CLASSPATH} ru.bitel.common.bootstrap.Boot ru.bitel.common.bootstrap.Boot ru.bitel.bgbilling.kernel.wifi.WiFiAgent  ${SETUP_NAME} $1 $2 $3 $4 $5 $6
  fi
fi
