#!/bin/sh
source ./setenv.sh
export CURRENTPATH=`pwd`
echo ${CURRENTPATH}
echo ${TOMCAT_PATH}
echo "installation start ..."
echo "Stop tomcat..."
sudo systemctl stop tomcat
echo "Copy initial file ..."
if sudo test  -f "${TOMCAT_PATH}/conf/tomcat.conf"; then
	sudo cp -af ${TOMCAT_PATH}/conf/tomcat.conf .
	echo "JAVA_OPTS=\"${JAVA_OPTS}\"" | sudo tee -a tomcat.conf
	sudo cp -af ${CURRENTPATH}/tomcat.conf ${TOMCAT_PATH}/conf
else
	sudo cp -af ./setenv.sh ${TOMCAT_PATH}/bin
fi
echo "Initial DB ..."
cd AuthFiConfig/bin
./AuthFiConfig
echo "Initial DB OK, remove previous build..."
sudo rm -rf ${TOMCAT_PATH}/webapps/ROOT
echo "Copy new build..."
sudo cp -af ${CURRENTPATH}/ROOT.war ${TOMCAT_PATH}/webapps
sudo chown tomcat.tomcat ${TOMCAT_PATH}/webapps/ROOT.war
if sudo test  -f "${TOMCAT_PATH}/conf/tomcat.conf"; then
	sudo chcon -t tomcat_var_lib_t ${TOMCAT_PATH}/webapps/ROOT.war
fi
echo "Start tomcat..."
sudo systemctl start tomcat
