#!/bin/bash

OXFUNCTIONS=/opt/open-xchange/guard/sbin/oxfunctions.sh
OXCONFIG=/opt/open-xchange/guard/etc/ox-scriptconf.sh
CONSOLELOG=/var/log/open-xchange/guard/console.log

test -f $OXFUNCTIONS || {
    echo "missing common shell functions file"
    exit 1
}

. $OXFUNCTIONS

test -f $OXCONFIG && . $OXCONFIG

ox_set_JAVA_BIN

test -z "$LOGBACK_CONF" && LOGBACK_CONF=/opt/open-xchange/guard/etc/logback.xml
test -z "$JAVA_XTRAOPTS" && JAVA_XTRAOPTS="-Xmx1024M"

if [ -n "$UMASK" ]; then
    umask $UMASK
else
    umask 066
fi

if [ -z "$1" ]; then
    exec $JAVA_BIN $JAVA_XTRAOPTS $JVM_ARGS -classpath "/opt/open-xchange/guard/lib/*" -Dlogback.configurationFile=$LOGBACK_CONF com.openexchange.guard.server.Startup >> $CONSOLELOG 2>&1
else
    exec $JAVA_BIN $JAVA_XTRAOPTS -classpath "/opt/open-xchange/guard/lib/*" -Dlogback.configurationFile=$LOGBACK_CONF com.openexchange.guard.server.Startup $@
fi
