#/bin/sh
#set -x

# Check JAVA. We require a installed version.
# Required is min. Version 11

if test "$FITDIR" != "" 
	then echo "FITDIR found"
	CP=${PWD}/install/ant-launcher.jar
	
	if test "$JAVA_HOME" != ""
		then 
			echo "JAVA found"
		else
			echo "No JAVA_HOME found, please install JRE 11 or newer!"
			exit 1
	fi

	${JAVA_HOME}/bin/java -cp "${CP}" -Dj.home="${JAVA_HOME}" -DINST_OS=unix -DINST_SYS=fit -DINST_DIR=${PWD} -DDST_DIR=${FITDIR}/run/bin/FIT-MI_Server -DBASE_DIR=${FITDIR} -Dant.home=${PWD}/install org.apache.tools.ant.launch.Launcher -buildfile install/ant_install.xml doinstall

elif test "$TCFITDIR" != ""
	then echo "TCFITDIR found"
	CP=${PWD}/install/ant-launcher.jar
	
	if test "$JAVA_HOME" != ""
		then 
			echo "JAVA found"
		else
			echo "No JAVA_HOME found, please install JRE 11 or newer!"
			exit 1
	fi
	${JAVA_HOME}/bin/java -cp "${CP}" -Dj.home="${JAVA_HOME}" -DTCFITDIR=${TCFITDIR} -DINST_SYS=fit4tc -DINST_OS=unix -DINST_DIR=${PWD} -DDST_DIR=${TCFITDIR}/FIT-MI_Server -DBASE_DIR=${TCFITDIR} -Dant.home=${PWD}/install org.apache.tools.ant.launch.Launcher -buildfile install/ant_install.xml doinstall
	
else
	echo "Starting Standalone installation..."
	echo " (Because Environment variables FITDIR or TCFITDIR not found)"
	
	CP=${PWD}/install/ant-launcher.jar
	
	if test "$JAVA_HOME" != ""
		then 
			echo "JAVA found: ${JAVA_HOME}"
		else
			echo "No JAVA_HOME found, please install JRE 11 or newer!"
			exit 1
	fi
	${JAVA_HOME}/bin/java -cp "${CP}" "$@" -DSERVICENAME=SFCMTCService -Dj.home="${JAVA_HOME}" -DINST_SYS=fit4tc -DINST_OS=unix -DINST_DIR=${PWD} -Dant.home=${PWD}/install org.apache.tools.ant.launch.Launcher -buildfile install/ant_install.xml doinstallStandAlone
fi
