#***********************************************************************
 #  This code is part of pyCMPL 
 #
 #  Copyright (C) 2013
 #  Mike Steglich - Technical University of Applied Sciences
 #  Wildau, Germany 
 #
 #  pyCMPL is a project of the Technical University of 
 #  Applied Sciences Wildau and the Institute for Operations Research 
 #  and Business Management at the Martin Luther University 
 #  Halle-Wittenberg.
 #  Please visit the project homepage <www.coliop.org>
 # 
 #  pyCMPL is free software; you can redistribute it and/or modify it 
 #  under the terms of the GNU Lesser General Public License as published by 
 #  the Free Software Foundation; either version 3 of the License, or 
 #  (at your option) any later version.
 # 
 #  pyCMPL is distributed in the hope that it will be useful, but WITHOUT
 #  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 #  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 #  License for more details.
 #  
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 #**********************************************************************
 
#!/bin/bash


export PYTHONPATH=$PYTHONPATH:$PWD/../lib:$PWD/../../cmplServer

if  [[ $OSTYPE == *msys* ]] ; then
	export CMPLBINARY=$PWD/../../Cmpl/bin/cmpl.exe
else
	export CMPLBINARY=$PWD/../../Cmpl/bin/cmpl
fi



if [ $# == 2 ] ; then
	cmplPort=$2
else
	cmplPort="8008"
fi

if [ ! -d ~/CmplServer ]; then
  mkdir ~/CmplServer
fi


if [ $1 == "-start" ]; then
	echo "Starting CmplServer ..."
	rm ~/cmplServer.out 2>/dev/null
	nohup $PythonBin $PWD/../../cmplServer/cmplServer/cmplServerHandler.py -start $cmplPort &>~/CmplServer/cmplServer.out &
	sleep 0.5
	more ~/CmplServer/cmplServer.out
elif [ $1 == "-stop" ]; then
	nohup $PythonBin $PWD/../../cmplServer/cmplServer/cmplServerHandler.py  -stop $cmplPort &>~/CmplServer/cmplServer.out 
fi

exit 0
