[6433] | 1 | # if this file is executed, /bin/sh is used, as we don't start with #!
|
---|
| 2 | # this should work under ash, bash, zsh, ksh, sh style shells.
|
---|
| 3 |
|
---|
[15131] | 4 | #the purpose of this file is to check/set up the environment for greenstone3
|
---|
[16213] | 5 | #sorts out:
|
---|
[17442] | 6 | # - gsdl3home
|
---|
| 7 | # - java
|
---|
[14726] | 8 |
|
---|
[16213] | 9 | # java_min_version gets passed to search4j as the minimum java version
|
---|
[20093] | 10 | java_min_version=1.5.0_00
|
---|
[15131] | 11 |
|
---|
| 12 |
|
---|
[14726] | 13 | function testSource(){
|
---|
[15131] | 14 |
|
---|
[14726] | 15 | if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
|
---|
| 16 | # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
|
---|
| 17 | # One exception is zsh has an option to set it temporarily to the script name
|
---|
| 18 | if test -z "$ZSH_NAME" ; then
|
---|
| 19 | # we aren't using zsh
|
---|
| 20 | gsdl_not_sourced=true
|
---|
| 21 | fi
|
---|
[6433] | 22 | fi
|
---|
| 23 |
|
---|
[14726] | 24 | if test -n "$gsdl_not_sourced" ; then
|
---|
[17442] | 25 | echo " Error: Make sure you source this script, not execute it. Eg:"
|
---|
| 26 | echo " $ source gs3-setup.sh"
|
---|
| 27 | echo " or"
|
---|
| 28 | echo " $ . gs3-setup.sh"
|
---|
| 29 | echo " not"
|
---|
| 30 | echo " $ ./gs3-setup.sh"
|
---|
[14726] | 31 | unset gsdl_not_sourced
|
---|
| 32 | exit 1
|
---|
| 33 | fi
|
---|
[6433] | 34 |
|
---|
[14726] | 35 | if test ! -f gs3-setup.sh ; then
|
---|
| 36 | echo "You must source the script from within the Greenstone home directory"
|
---|
[20189] | 37 | return 1
|
---|
[14726] | 38 | fi
|
---|
[20189] | 39 | return 0
|
---|
| 40 | }
|
---|
[15131] | 41 |
|
---|
[20189] | 42 | # if GSDL3SRCHOME is set, then we assume that we have already sourced the
|
---|
| 43 | # script so don't do it again. UNLESS, GSDL3SRCHOME doesn't match the
|
---|
| 44 | # current directory in which case it was a different gs3 installation, so lets
|
---|
| 45 | # do it now.x
|
---|
| 46 | function testAlreadySourced() {
|
---|
| 47 | if [ ! -z "$GSDL3SRCHOME" ]; then
|
---|
| 48 | localgs3sourcehome="`pwd`"
|
---|
| 49 | if [ "$GSDL3SRCHOME" == "$localgs3sourcehome" ]; then
|
---|
| 50 | echo "Your environment is already set up for Greenstone3"
|
---|
| 51 | return 1
|
---|
| 52 | fi
|
---|
| 53 | echo "Your environment was set up for Greenstone 3 in $GSDL3SRCHOME."
|
---|
| 54 | echo "Overwriting that set up for the current Greenstone 3 in $localgs3sourcehome"
|
---|
| 55 | fi
|
---|
| 56 | return 0
|
---|
[14726] | 57 | }
|
---|
[6433] | 58 |
|
---|
[15131] | 59 | function setGS3ENV() {
|
---|
[6433] | 60 |
|
---|
[17442] | 61 | echo "Setting up your environment for Greenstone3"
|
---|
| 62 | ## main greenstone environment variables ##
|
---|
[20187] | 63 | GSDL3SRCHOME="`pwd`"
|
---|
| 64 | GSDL3HOME="$GSDL3SRCHOME/web"
|
---|
[17442] | 65 | export GSDL3HOME
|
---|
| 66 | export GSDL3SRCHOME
|
---|
[10645] | 67 |
|
---|
[17442] | 68 | GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
---|
| 69 | # check for running bash under cygwin
|
---|
| 70 | if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
|
---|
| 71 | GSDLOS=windows
|
---|
| 72 | fi
|
---|
| 73 | export GSDLOS
|
---|
| 74 | echo " - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
|
---|
[8060] | 75 |
|
---|
[17442] | 76 | #change this if external tomcat
|
---|
[20187] | 77 | TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
|
---|
[10303] | 78 |
|
---|
[6433] | 79 |
|
---|
[17442] | 80 | ## adjustments to users (existing) environment ##
|
---|
[15134] | 81 |
|
---|
[17442] | 82 | #PATH
|
---|
[20077] | 83 | addtopath PATH "$GSDL3SRCHOME/bin/script"
|
---|
| 84 | addtopath PATH "$GSDL3SRCHOME/bin"
|
---|
| 85 | echo " - Adjusted PATH"
|
---|
[6433] | 86 |
|
---|
[20077] | 87 | #MANPATH
|
---|
| 88 | addtopath MANPATH "$GSDL3SRCHOME/doc/man"
|
---|
| 89 | echo " - Adjusted MANPATH"
|
---|
| 90 |
|
---|
[17442] | 91 | #CLASSPATH
|
---|
[20233] | 92 | addtopath CLASSPATH "."
|
---|
[20077] | 93 | addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
|
---|
| 94 | addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
|
---|
[20211] | 95 | addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
|
---|
| 96 |
|
---|
[20088] | 97 | # Tomcat 5 jar files
|
---|
[20187] | 98 | for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
|
---|
[20077] | 99 | addtopath CLASSPATH "$JARFILE"
|
---|
| 100 | done
|
---|
[20088] | 101 | # Tomcat 6 jar files
|
---|
[20187] | 102 | for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
|
---|
[20088] | 103 | addtopath CLASSPATH "$JARFILE"
|
---|
| 104 | done
|
---|
| 105 |
|
---|
[20211] | 106 | #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
|
---|
| 107 | #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
|
---|
| 108 | # addtopath CLASSPATH "$JARFILE"
|
---|
| 109 | #done
|
---|
[20219] | 110 |
|
---|
| 111 | addtopath CLASSPATH "."
|
---|
[20077] | 112 | echo " - Adjusted CLASSPATH"
|
---|
[8060] | 113 |
|
---|
[17442] | 114 | #LD_LIBRARY_PATH
|
---|
[20077] | 115 | addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
| 116 | addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
| 117 | echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
|
---|
[15134] | 118 |
|
---|
[17442] | 119 | #ant
|
---|
[20077] | 120 | if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
|
---|
| 121 | ANT_HOME="$GSDL3SRCHOME/packages/ant"
|
---|
| 122 | export ANT_HOME
|
---|
| 123 | addtopath PATH "$ANT_HOME/bin"
|
---|
[20093] | 124 | echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
|
---|
[17442] | 125 | else
|
---|
[20077] | 126 | which ant &> /dev/null
|
---|
| 127 | if [ "$?" == "0" ]; then
|
---|
[20217] | 128 | echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
|
---|
| 129 | echo " Note that Greenstone requires Ant 1.7.1 or greater"
|
---|
[20077] | 130 | else
|
---|
[20093] | 131 | echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
|
---|
[20217] | 132 | echo " Note that Greenstone requires Ant 1.7.1 or greater"
|
---|
[20077] | 133 | fi
|
---|
[20217] | 134 |
|
---|
[17442] | 135 | fi
|
---|
[15134] | 136 |
|
---|
[14726] | 137 | }
|
---|
[6433] | 138 |
|
---|
[15131] | 139 | function checkJava() {
|
---|
[15138] | 140 |
|
---|
[20059] | 141 | HINT="`pwd`/packages/jre"
|
---|
[20216] | 142 | if [ $GSDLOS = darwin ]; then
|
---|
| 143 | HINT=/System/Library/Frameworks/JavaVM.framework/Home
|
---|
| 144 | fi
|
---|
[20217] | 145 |
|
---|
| 146 | #if search4j is present, use it
|
---|
| 147 | if [ -x bin/search4j ] ; then
|
---|
| 148 | FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`"
|
---|
| 149 | if [ "$?" == "0" ]; then
|
---|
| 150 | #found a suitible java
|
---|
| 151 | setupJavaAt "$FOUNDJAVAHOME"
|
---|
| 152 | else
|
---|
| 153 | #no suitable java exists
|
---|
| 154 | echo " - ERROR: Failed to locate java $java_min_version or greater"
|
---|
| 155 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
| 156 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
| 157 | fi
|
---|
| 158 |
|
---|
| 159 | #otherwise manually try the hint
|
---|
| 160 | elif [ -d "$HINT" ]; then
|
---|
| 161 | #found a suitible java
|
---|
| 162 | setupJavaAt "$HINT"
|
---|
| 163 |
|
---|
| 164 | #lastly, check if java already setup
|
---|
| 165 | elif [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
|
---|
| 166 | echo " - Using java at $JAVA_HOME"
|
---|
[20233] | 167 | echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
| 168 | echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
| 169 | echo " (SVN users may still use java 1.4)"
|
---|
[20217] | 170 | elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
|
---|
| 171 | echo " - Using java at $JRE_HOME"
|
---|
[20233] | 172 | echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
| 173 | echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
| 174 | echo " (SVN users may still use java 1.4)"
|
---|
| 175 |
|
---|
[20217] | 176 | #failing all that, print a warning
|
---|
[20077] | 177 | else
|
---|
[20217] | 178 | #no suitable java exists
|
---|
| 179 | echo " - ERROR: Failed to locate java"
|
---|
| 180 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
| 181 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
[15131] | 182 | fi
|
---|
| 183 | }
|
---|
[6433] | 184 |
|
---|
[20217] | 185 | function setupJavaAt() {
|
---|
| 186 | export JAVA_HOME="$1"
|
---|
| 187 | addtopath PATH "$JAVA_HOME/bin"
|
---|
| 188 | echo " - Exported JAVA_HOME to $JAVA_HOME"
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[14726] | 191 | function pauseAndExit(){
|
---|
| 192 | echo -n "Please press any key to continue... "
|
---|
| 193 | read
|
---|
| 194 | }
|
---|
[6433] | 195 |
|
---|
[15131] | 196 | function isinpath() {
|
---|
[17442] | 197 | for file in `echo $1 | sed 's/:/ /g'`; do
|
---|
| 198 | if [ "$file" == "$2" ]; then
|
---|
| 199 | echo true
|
---|
| 200 | return
|
---|
| 201 | fi
|
---|
| 202 | done
|
---|
| 203 | echo false
|
---|
[15131] | 204 | }
|
---|
| 205 |
|
---|
[20077] | 206 | function addtopath() {
|
---|
[20078] | 207 | eval "PV=\$$1"
|
---|
[20083] | 208 | #echo "$1 += $2"
|
---|
| 209 | if [ "$PV" == "" ]; then
|
---|
| 210 | cmd="$1=\"$2\""
|
---|
| 211 | else
|
---|
| 212 | cmd="$1=\"$2:\$$1\""
|
---|
[20077] | 213 | fi
|
---|
[20083] | 214 | eval $cmd
|
---|
| 215 | eval "export $1"
|
---|
[20077] | 216 | }
|
---|
[20078] | 217 |
|
---|
[20189] | 218 | # Note: use return not exit from a sourced script otherwise it kills the shell
|
---|
[15131] | 219 | echo
|
---|
[14726] | 220 | testSource
|
---|
[20189] | 221 | if [ "$?" == "1" ]; then
|
---|
| 222 | return
|
---|
| 223 | fi
|
---|
| 224 | testAlreadySourced
|
---|
| 225 | if [ "$?" == "1" ]; then
|
---|
| 226 | return
|
---|
| 227 | fi
|
---|
[14726] | 228 | setGS3ENV
|
---|
[15131] | 229 | checkJava
|
---|