#!/bin/bash

if [ -f ~/.sql-dk/environment.sh ]; then # .sql-dk must match with DIR in Constants.java
    . ~/.sql-dk/environment.sh
fi

[ -f ~/.sql-dk/config.rnc ] || ln -s /usr/share/doc/sql-dk/config.rnc ~/.sql-dk/config.rnc
[ -f ~/.sql-dk/config.xsd ] || ln -s /usr/share/doc/sql-dk/config.xsd ~/.sql-dk/config.xsd

[ -n "$JAR" ] || JAR="/usr/share/sql-dk/sql-dk.jar";

MAIN_CLASS="info.globalcode.sql.dk.CLIStarter";
CLASSPATH="$JAR:/usr/share/java/postgresql-jdbc4.jar";

LOGGER="-Djava.util.logging.config.class=info.globalcode.sql.dk.logging.LoggerInitializer";
# LOG_LEVEL="FINE"; # SEVERE, WARNING, INFO, FINE, FINER, FINEST, ALL
[ -n "$LOG_LEVEL" ] && LOGGER_LEVEL="-Dinfo.globalcode.sql.dk.logging.LoggerInitializer.level=$LOG_LEVEL";

java $LOGGER $LOGGER_LEVEL -cp $CLASSPATH $MAIN_CLASS "$@"
