#!/bin/sh
###########################################################################
# The contents of this file are subject to the license and copyright
# detailed in the LICENSE and NOTICE files at the root of the source
# tree and available online at
#
# http://www.dspace.org/license/
###########################################################################
# 'dspace' script
# This is a Unix shell script for running a command-line DSpace tool.
# It sets the CLASSPATH appropriately before invoking Java.

BINDIR=`dirname $0`
DSPACEDIR=`cd "$BINDIR/.." ; pwd`
# Add the directory with all oai classes (original and overlay) needed by the 'dspace oai' launcher.xml
OAICLASSES=$DSPACEDIR/webapps/oai/WEB-INF/classes/

# Get the JARs in $DSPACEDIR/jsp/WEB-INF/lib, separated by ':'
JARS=`echo $DSPACEDIR/lib/*.jar | sed 's/ /\:/g'`

# Class path for DSpace will be:
#   Any existing classpath
#   The JARs (WEB-INF/lib/*.jar)
#   The WEB-INF/classes directory
if [ "$CLASSPATH" = "" ]; then
    FULLPATH=$OAICLASSES:$JARS:$DSPACEDIR/config
else
    FULLPATH=$CLASSPATH:$OAICLASSES:$JARS:$DSPACEDIR/config
fi


# If the user only wants the CLASSPATH, just give it now.
if [ "$1" = "classpath" ]; then
  echo $FULLPATH
  exit 0
fi



#Allow user to specify java options through JAVA_OPTS variable
if [ "$JAVA_OPTS" = "" ]; then
  #Default Java to use 256MB of memory
  JAVA_OPTS="-Xmx256m -Dfile.encoding=UTF-8"
fi

# Now invoke Java
java $JAVA_OPTS -classpath $FULLPATH org.dspace.app.launcher.ScriptLauncher "$@"
