# 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. # make sure we are sourced, and not run export RUNJAVA= JRE_HOME= JAVA_HOME= CLASSPATH=$CLASSPATH 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(){ 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 #change this if external tomcat TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH export PATH MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man export MANPATH 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 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni export LD_LIBRARY_PATH ## for mac DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni export DYLD_LIBRARY_PATH } function setJAVAHOME(){ # see if we can find java java="java" jfound=1 jok=1 # if JREHOME, JRE_HOME is set, we'll use it to determine where java lives if [ "$JRE_HOME" != "" ]; then java="$JRE_HOME/bin/java" export JRE_HOME=$JRE_HOME elif [ "$JREHOME" != "" ]; then java="$JREHOME/bin/java" export JRE_HOME=$JREHOME # JAVAHOME or JAVA_HOME is set we'll use it to determine where java lives, otherwise # we just hope it's on the search path elif [ "$JAVA_HOME" != "" ] ; then java="$JAVA_HOME/bin/java" export JAVA_HOME=$JAVA_HOME elif [ "$JAVAHOME" != "" ] ; then java="$JAVAHOME/bin/java" export JAVA_HOME=$JAVAHOME else java=`which java 2> /dev/null` if [ ! -x "$java" ]; then echo "Failed to locate Java. You must install a java runtime environment" echo "(version 1.4 or greater) before installing Greenstone 3." pauseAndExit else export JRE_HOME=`echo $java | sed -n 's/[\\\/]bin[\\\/]java$//p'` fi fi checkJAVAHOME } function checkJAVAHOME(){ # Make sure prerequisite environment variables are set if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined" echo "At least one of these environment variable is needed to run Greenstone3" pauseAndExit else # check JRE_HOME if [ -n "$JRE_HOME" ]; then if [ ! -x "$JRE_HOME"/bin/java ]; then echo "JRE_HOME: $JRE_HOME" echo "Couldn't find $JRE_HOME/bin/java" echo "The JRE_HOME environment variable is not defined correctly" echo "This environment variable is needed to run this program" pauseAndExit else export RUNJAVA="$JRE_HOME"/bin/java checkVersion fi else # check JAVA_HOME if JRE_HOME is not set if [ -n "$JAVA_HOME" ]; then if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then echo "JAVA_HOME: $JAVA_HOME" echo "Couldn't find $JAVA_HOME/bin/java or $JAVA_HOME/bin/javac" echo "The JAVA_HOME environment variable is not defined correctly" echo "This environment variable is needed to run this program" echo "NB: JAVA_HOME should point to a JDK not a JRE" pauseAndExit else export RUNJAVA="$JAVA_HOME"/bin/java checkVersion fi fi fi fi } function checkVersion(){ if [ $jfound -eq 1 ]; then javaversion=`$RUNJAVA -version 2>&1 | sed -n 's/^java version \"\(.*\)\"/\1/p'` jvmajor=`echo $javaversion | sed -n 's/^\([0-9]*\).*$/\1/p'` jvminor=`echo $javaversion | sed -n 's/^[0-9]*\.\([0-9]*\).*$/\1/p'` if [ $jvmajor -lt 1 ] ; then jok=0 fi if [ $jvmajor -eq 1 ] && [ $jvminor -lt 4 ] ; then jok=0 fi fi if [ $jfound -eq 1 ] && [ $jok -eq 0 ] ; then echo "The version of the java runtime environment you have installed is too" echo "old to run Greenstone 3. Please install a new version of the JRE (version" echo "1.4 or newer) and rerun this installation." export RUNJAVA= pauseAndExit else if [ -n "$JRE_HOME" ]; then echo "JRE_HOME: $JRE_HOME" export PATH="$JRE_HOME"\bin:$PATH fi if [ -n "$JAVA_HOME" ]; then echo "JAVA_HOME: $JAVA_HOME" export PATH="$JAVA_HOME"\bin:$PATH fi echo "Your environment has successfully been set up to run Greenstone3" fi } function pauseAndExit(){ echo -n "Please press any key to continue... " read } testSource setGS3ENV setJAVAHOME