Skip to content

Instantly share code, notes, and snippets.

@mwoodiupui
Last active August 29, 2015 14:05
Show Gist options
  • Save mwoodiupui/86b89bc5b4d17066d095 to your computer and use it in GitHub Desktop.
Save mwoodiupui/86b89bc5b4d17066d095 to your computer and use it in GitHub Desktop.
Shell script to create customized Tomcat Context descriptors for a DSpace instance
#! /bin/sh
# Copyright 2014 Indiana University
# Mark H. Wood, IUPUI University Library
### Configure me!
DSHOME="${HOME}/dspaces"
DBMS='postgresql'
DB_HOST=localhost
DB_PORT=5432
DB_USER=${USER}
#################################################################
# Functions
#################################################################
function make_context {
cat > ${FILE} <<- EOF
<Context
docBase='/home/mwood/dspaces/${NAME}/webapps/${APP}'>
<Parameter
description='Path to the DSpace configuration file.'
override='false'
name='dspace-config'
value='${DSHOME}/${NAME}/config/dspace.cfg'
/>
<Resource name='jdbc/dspace'
auth='Container'
type='javax.sql.DataSource'
factory='org.apache.tomcat.jdbc.pool.DataSourceFactory'
driverClassName='${DB_DRIVER}'
url='${DB_URL}'
username='${DB_USER}'
password='${DB_PW}'
initialSize='2'
maxActive="5"
maxIdle="1"
minIdle='1'
maxWait="-1"
/>
<ResourceLink name="mail/Session"
global='mail/Session'
type="javax.mail.Session"
/>
</Context>
EOF
}
#################################################################
# Start here
#################################################################
### Options
while getopts '?h:o' option
do
case "${option}" in
'o') DBMS='oracle' ;;
'h') DB_HOST=${OPTARG} ;;
'?')
echo $0 '[-o] [-h host] name'
exit
;;
*)
echo Known but unimplemented option ${option}
exit 1
;;
esac
done
shift $(( OPTIND - 1 )) # drop option arguments
### Collect specifics
NAME=$1
if [ "x${NAME}" = "x" ]
then
echo "Please specify a name for the environment/context/database"
exit 1
fi
shift
if [ $# -gt 0 ]; then echo "Extra parameters ignored: $@"; fi
read -p "DB password: " -s
DB_PW="${REPLY}"
echo ""
case "${DBMS}" in
'oracle')
DB_DRIVER='oracle.jdbc.OracleDriver'
DB_PORT=1521
DB_URL="jdbc:oracle:thin:@${DB_HOST}:${DB_PORT}/XE"
DB_USER=${NAME}
echo "Don't forget: mvn -Ddb.name=oracle"
;;
'postgresql')
DB_NAME="${NAME}"
DB_DRIVER='org.postgresql.Driver'
DB_PORT=5432
DB_URL="jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}"
DB_USER=${USER}
;;
*)
echo "Unknown DBMS: ${DBMS}"
exit 1
;;
esac
### Generate the XMLUI Context
APP="xmlui"
FILE="${NAME}#${APP}.xml"
make_context
chmod u=rw,g=r,o= ${FILE}
chgrp tomcat ${FILE}
### Generate the JSPUI Context
APP="jspui"
FILE="${NAME}#${APP}.xml"
make_context
chmod u=rw,g=r,o= ${FILE}
chgrp tomcat ${FILE}
### Generate the Solr Context
APP="solr"
FILE="${NAME}#${APP}.xml"
cat > ${FILE} <<- EOF
<Context
docBase='/home/mwood/dspaces/${NAME}/webapps/${APP}'>
<Parameter
description='Path to the DSpace configuration file.'
override='false'
name='dspace-config'
value='/home/mwood/dspaces/${NAME}/config/dspace.cfg'
/>
<ResourceLink name="mail/Session"
global='mail/Session'
type="javax.mail.Session"
/>
</Context>
EOF
chmod u=rw,g=r,o= ${FILE}
chgrp tomcat ${FILE}
### Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment