#!/bin/sh

cdaserverdistdir=/usr/share/java      # Or /usr/share/cdaserver/dist
cdaserverlibdir=/usr/share/java   # Or /etc/xos/config/cdaserver/lib



port=$1   # This version only takes an argument specifying the port number to bind to

# NB Please note this list of JAR files. Please pass only this list of files to the java command for the CDA server
#
# Please do not wildcard these JAR files from a directory such as  /usr/share/java
#
# If /usr/share/java/*.jar is used, the CDA server cannot parse the Hibernate
# configuration in hibernate.cfg.xml, and hence cannot access the XVOMS database

jars=\
${cdaserverlibdir}/antlr.jar:\
${cdaserverlibdir}/asm/asm-attrs.jar:\
${cdaserverlibdir}/asm/asm.jar:\
${cdaserverlibdir}/bcprov.jar:\
${cdaserverlibdir}/c3p0.jar:\
${cdaserverlibdir}/cglibjar:\
${cdaserverlibdir}/commons-collections.jar:\
${cdaserverlibdir}/commons-logging.jar:\
${cdaserverlibdir}/dom4j.jar:\
${cdaserverlibdir}/hibernate3.jar:\
${cdaserverlibdir}/javassist.jar:\
${cdaserverlibdir}/jta.jar:\
${cdaserverlibdir}/junit.jar:\
${cdaserverlibdir}/junit4.jar:\
${cdaserverlibdir}/log4j.jar:\
${cdaserverlibdir}/mail.jar:\
${cdaserverlibdir}/mysql-connector-java.jar:\
${cdaserverlibdir}/scannotation.jar:\
${cdaserverlibdir}/xvoms.jar

confdir=/etc/xos/config/cdaserver   # Put log4j.properties in a directory on the CLASSPATH
xvomsdir=/etc/xos/config/xvoms # Put hibernate.cfg.xml in a directory on the CLASSPATH

days="-Dcdaserver.validityDays=30"
hours="-Dcdaserver.validityHours=-9"  # Negative values should be ignored
minutes="-Dcdaserver.validityMinutes" # unset values should be ignored

serverjar=${cdaserverdistdir}/cdaserver.jar
libjars=${jars}

# At STFC, at least, we need to force binding to an IPv4 address because our firewall
# doesn't allow IPv6 through

jvmopts="-ea -server -Djava.net.preferIPv4Stack=true"

# Can put log4j.properties in the current directory '.' or somewhere else
# Make sure to put the directory containing log4j.properties in the 
# classpath below - here, first component of the '-cp' value
rootDir="-DXtreemOS.rootCertificate=/etc/pki/tls/rootcerts/XtreemOS.pem"

java ${jvmopts} ${days} ${hours} ${minutes} ${rootDir} -cp ${xvomsdir}:${confdir}:${serverjar}:${libjars} org.xtreemos.wp35.cda.CdaServer ${port}
