#!/bin/bash

. $(dirname $0)/env.sh

LABKEY=LabKey24.11.11-14-community

if [ $# -gt 0 ] ; 
then
	case $1 in
	24.11)        
    	LABKEY=LabKey24.11.11-14-community;;
	esac;

fi;

echo "Using $LABKEY";

#config/application.settings are generic/complex enough that is part of the git container 
#and is not overwritten from source
#one can find template in ${TGZ_PATH}, ${LABKEY}/config/application.settings (to copy it to temp, use)
#tar xvzf ${TGZ_PATH} -C ~/temp --strip=2 ${LABKEY}/config/application.settings

#set database
if [ ! -d ${POSTGRES_DIR} ] ; then
   mkdir ${POSTGRES_DIR};
fi;

#set labkey-home

if [ ! -d ${LABKEY_HOME} ] ; 
then
   mkdir ${LABKEY_HOME};
fi;

#link source jar
if [ -f ${LABKEY_HOME}/labkeyServer.jar ] ; 
then
   rm ${LABKEY_HOME}/labkeyServer.jar;
fi;

TGZ_PATH=$HOME/software/packages/$LABKEY.tar.gz
tar xvzf ${TGZ_PATH} -C ${LABKEY_HOME} --strip=1 ${LABKEY}/labkeyServer.jar

#create helper directories

if [ ! -d ${LABKEY_TMP} ] ; 
then
   mkdir ${LABKEY_TMP};
fi;

if [ ! -d ${LABKEY_LOGS} ] ; 
then
   mkdir ${LABKEY_LOGS};
fi;


exit 0;