# if this file is executed, /bin/sh is used, as we don't start with #! # this should work under ash, bash, zsh, ksh, sh style shells. #the purpose of this file is to check/set up the environment for greenstone3 #sorts out: # - gsdl3home # - java # java_min_version gets passed to search4j as the minimum java version java_min_version=1.5.0_00 function testSource(){ if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced. # One exception is zsh has an option to set it temporarily to the script name if test -z "$ZSH_NAME" ; then # we aren't using zsh gsdl_not_sourced=true fi fi if test -n "$gsdl_not_sourced" ; then echo " Error: Make sure you source this script, not execute it. Eg:" echo " $ source gs3-setup.sh" echo " or" echo " $ . gs3-setup.sh" echo " not" echo " $ ./gs3-setup.sh" unset gsdl_not_sourced exit 1 fi if test ! -f gs3-setup.sh ; then echo "You must source the script from within the Greenstone home directory" exit 1 fi } function setGS3ENV() { echo "Setting up your environment for Greenstone3" ## main greenstone environment variables ## GSDL3SRCHOME="`pwd`" GSDL3HOME="$GSDL3SRCHOME/web" export GSDL3HOME export GSDL3SRCHOME GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` # check for running bash under cygwin if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then GSDLOS=windows fi export GSDLOS echo " - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS" #change this if external tomcat TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat" ## adjustments to users (existing) environment ## #PATH addtopath PATH "$GSDL3SRCHOME/bin/script" addtopath PATH "$GSDL3SRCHOME/bin" echo " - Adjusted PATH" #MANPATH addtopath MANPATH "$GSDL3SRCHOME/doc/man" echo " - Adjusted MANPATH" #CLASSPATH addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes" addtopath CLASSPATH "$GSDL3SRCHOME/resources/java" for JARFILE in "$GSDL3SRCHOME"/*.jar; do addtopath CLASSPATH "$JARFILE" done for JARFILE in "$GSDL3SRCHOME"/lib/jni/*.jar; do addtopath CLASSPATH "$JARFILE" done for JARFILE in "$GSDL3SRCHOME"/lib/java/*.jar; do addtopath CLASSPATH "$JARFILE" done for JARFILE in "$GSDL3HOME"/WEB-INF/lib/*.jar; do addtopath CLASSPATH "$JARFILE" done # Tomcat 5 jar files for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do addtopath CLASSPATH "$JARFILE" done # Tomcat 6 jar files for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do addtopath CLASSPATH "$JARFILE" done for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do addtopath CLASSPATH "$JARFILE" done echo " - Adjusted CLASSPATH" #LD_LIBRARY_PATH addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni" addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni" echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH" #ant if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then ANT_HOME="$GSDL3SRCHOME/packages/ant" export ANT_HOME addtopath PATH "$ANT_HOME/bin" echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)" else which ant &> /dev/null if [ "$?" == "0" ]; then echo " - Greenstone 'Ant' package missing - falling back to system Ant" else echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself" fi echo " (Greenstone requires Ant 1.7.1 or greater)" fi } function checkJava() { HINT="`pwd`/packages/jre" FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`" if [ "$?" == "0" ]; then #bundled java exists, set up export JAVA_HOME="$FOUNDJAVAHOME" addtopath PATH "$JAVA_HOME/bin" echo " - Exported JAVA_HOME to $FOUNDJAVAHOME" else #no suitable java exists echo " ERROR: Failed to locate java $java_min_version or greater" bin/search4j &> /dev/null; if [ "$?" == "0" ]; then echo " It looks like you hava java but it's too old"; fi echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java" echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH" fi } function pauseAndExit(){ echo -n "Please press any key to continue... " read } function isinpath() { for file in `echo $1 | sed 's/:/ /g'`; do if [ "$file" == "$2" ]; then echo true return fi done echo false } function addtopath() { eval "PV=\$$1" #echo "$1 += $2" if [ "$PV" == "" ]; then cmd="$1=\"$2\"" else cmd="$1=\"$2:\$$1\"" fi eval $cmd eval "export $1" } echo testSource setGS3ENV checkJava