#!/bin/sh
# racon.sh
# init EBP for RAC opertions
#
PORT=8080
AUTH="--user fbloggs:fred"
EBPHOME=/var/lib/tomcat8/webapps/ebp*
EBP=http://localhost:$PORT/ebp
LDAP=ldap://localhost:389
DOMAIN=example
COM=com
MSGS=yes
HLQ=HCI00
LEVEL=D
set -x
: RAC configurations
curl -s -o curl1.xml $AUTH "$EBP/config?messages=$MSGS&errorlevel=$LEVEL&scheduler=no&parmlib.HLQ=$HLQ"
curl -s -o curl2.xml $AUTH "$EBP/config?rac.connectionurl=$LDAP"
curl -s -o curl3.xml $AUTH "$EBP/config?rac.resourcebase=cn=%7b0%7d,ou=%7b1%7d,dc=$DOMAIN,dc=$COM"
curl -s -o curl4.xml $AUTH "$EBP/config?rac.rolebase=ou=groups,dc=$DOMAIN,dc=$COM"
curl -s -o curl5.xml $AUTH "$EBP/config?rac.userpattern=uid=%7b0%7d,ou=people,dc=$DOMAIN,dc=$COM"
curl -s -o curl6.xml $AUTH "$EBP/config?rac.debug=true"

: Remove jobs, outputs, classes, restart and redefine 
curl -s -o curl7.xml $AUTH "$EBP/quiesce?reset=yes&wakeup=yes"
curl -s -o curl8.xml $AUTH "$EBP/define?class=A&type=JCL&maxcputime=10"
curl -s -o curl9.xml $AUTH "$EBP/start?class=A&n=1"

: Update default web.xml to turn on JAASRealm security
sed -i '1,$s/tomcat-users.xml - - >/tomcat-users.xml -->/g' $EBPHOME/WEB-INF/web.xml
sed -i '1,$s/< ! - - end of EBP/<!-- end of EBP/g' $EBPHOME/WEB-INF/web.xml

: Update the tomcat start-up sequence to include the following or
: start tomcat from the command line after this script '(use ". racon.sh")'
export JAVA_OPTS="$JAVA_OPTS -Djava.security.auth.login.config=$EBPHOME/META-INF/jaas.config"
