#!/bin/bash

set +e

{
date
whoami
env


## configure SODA

mkdir -p $CATALINA_BASE/conf/Catalina/localhost
cp $WEBAPP_DIR/META-INF/context.xml $CATALINA_BASE/conf/Catalina/localhost/$ACCESS_CONTEXT_ROOT.xml


## Security

case $SECURITY in
   iamtoken)
      cd $WEBAPP_DIR/WEB-INF/ && rm -f web.xml && cp web-cutout-$SECURITY.xml web.xml && cd -
      cp /etc/pki/tls/server-connector.xml $CATALINA_BASE/conf
      cp /etc/pki/tls/iamtoken.properties $WEBAPP_DIR/WEB-INF/classes/
      rm -f $WEBAPP_DIR/WEB-INF/lib/jjwt-*0.11*.jar
      ;;
   tsl)
      cp /etc/pki/tls/server-connector.xml $CATALINA_BASE/conf
      rm -f $WEBAPP_DIR/WEB-INF/lib/jjwt-*.jar
      ;;
   *)
      echo "Security not configured, runs open."
      ;;
esac

date
} 1> /tmp/start-soda.log 2>&1

$CATALINA_HOME/bin/catalina.sh run

