#!/bin/bash

INSTALL_HOME=`dirname $0`

CONFIG_FILE_DIR=${INSTALL_HOME}/conf

mkdir -p ${CONFIG_FILE_DIR}

CONFIG_CLASSPATH=.:${CONFIG_FILE_DIR}

LIB_DIR=${INSTALL_HOME}/lib

#
#Set up our classpath with our library dependencies...
for jar in `find ${LIB_DIR}/*.jar`;
do
    CONFIG_CLASSPATH=${jar}:${CONFIG_CLASSPATH}
done

#Guess JAVA_HOME if it's not set
if [ -z $JAVA_HOME ]; then
    JAVA_HOME=/usr/local/java
fi
echo ${JAVA_HOME}

#Guess SHRINE_CONF if it's not set
if [ -z $SHRINE_CONF ]; then
    SHRINE_CONF=/opt/shrine/tomcat/lib/shrine.conf
fi
echo ${SHRINE_CONF}

JVM_ARGS="-Xmx1024m -Dshrine.conf.file="${SHRINE_CONF}
echo ${JVM_ARGS}
${JAVA_HOME}/bin/java ${JVM_ARGS} -cp ${CONFIG_CLASSPATH} net.shrine.hub.setup.ShrineNetworkLifecycle "$@"