#!/bin/bash

set +e

{
date
whoami
env

# configure CONTEXT_ROOT

mkdir -p $CATALINA_BASE/conf/Catalina/localhost
echo "<Context docBase=\"$WEBAPP_DIR\"/>" > $CATALINA_BASE/conf/Catalina/localhost/$DISCOVERY_CONTEXT_ROOT.xml


# configure DB with ObsTAP
{
   echo "db_uri=$DB_URI"
   echo "db_schema=$DB_SCHEMA"
   echo "db_user_name=$DB_USERNAME"
   echo "db_password=$DB_PASSWORD"
} > $WEBAPP_DIR/WEB-INF/classes/search.properties


# configure response format
{
   echo "db_uri=$DB_URI"
   echo "db_schema=$DB_SCHEMA"
   echo "db_user_name=$DB_USERNAME"
   echo "db_password=$DB_PASSWORD"

   echo "cutout_url=$CUTOUT_SERVICE_URL"
} > $WEBAPP_DIR/WEB-INF/classes/formatresponsefilter.properties



###################################################################
date

} 1> /tmp/start-siav2.log 2>&1

$CATALINA_HOME/bin/catalina.sh run

