# 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=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 if [ `isinpath "$PATH" "$GSDL3SRCHOME/bin"` == "false" ]; then PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH export PATH MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man export MANPATH echo " - Adjusted PATH" else echo " - PATH already correct" fi #CLASSPATH if [ `isinpath "$CLASSPATH" "$GSDL3HOME/WEB-INF/classes"` == "false" ]; then CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH for JARFILE in $GSDL3SRCHOME/*.jar; do CLASSPATH=$CLASSPATH:$JARFILE done for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do CLASSPATH=$CLASSPATH:$JARFILE done for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do CLASSPATH=$CLASSPATH:$JARFILE done for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do CLASSPATH=$CLASSPATH:$JARFILE done for JARFILE in $GSDL3SRCHOME/build/*.jar; do CLASSPATH=$CLASSPATH:$JARFILE done export CLASSPATH echo " - Adjusted CLASSPATH" else echo " - CLASSPATH already correct" fi #LD_LIBRARY_PATH if [ `isinpath "$LD_LIBRARY_PATH" "$GSDL3SRCHOME/lib/jni"` == "false" ]; then LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni export LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni export DYLD_LIBRARY_PATH echo " - Adjusted LD_LIBRARY_PATH" else echo " - LD_LIBRARY_PATH already correct" fi #ant which ant &> /dev/null if [ "$?" != "0" ]; then ANT_HOME=$GSDL3SRCHOME/packages/ant PATH=$ANT_HOME/bin:$PATH echo " - Setup ant" else echo " - Ant already setup" fi echo } function checkJava() { echo "Checking Java" bin/search4j -m $java_min_version &> /dev/null if [ "$?" != "0" ]; then #java is not set up already bin/search4j -m $java_min_version -h packages/jre &> /dev/null if [ "$?" == "0" ]; then #bundled java exists, set up export JAVA_HOME=`pwd`/packages/jre echo " - Exported JAVA_HOME to point to bundled java" else #no java exists echo " - 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 else #java is already set up echo " - Found java at: `bin/search4j -m $java_min_version`" fi echo } 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 } echo testSource setGS3ENV checkJava