[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
|
---|
[31483] | 11 | DEBUG=false
|
---|
[15131] | 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
|
---|
[20305] | 50 | echo "Your environment is already set up for Greenstone3"
|
---|
| 51 | return 1
|
---|
[20189] | 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 |
|
---|
[26795] | 68 | if test "x$GSDLOS" = "x" ; then
|
---|
| 69 | GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
---|
| 70 | # check for running bash under cygwin
|
---|
| 71 | if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
|
---|
| 72 | GSDLOS=windows
|
---|
| 73 | fi
|
---|
| 74 | fi
|
---|
[17442] | 75 | export GSDLOS
|
---|
| 76 | echo " - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
|
---|
[8060] | 77 |
|
---|
[17442] | 78 | #change this if external tomcat
|
---|
[20187] | 79 | TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
|
---|
[10303] | 80 |
|
---|
[17442] | 81 | ## adjustments to users (existing) environment ##
|
---|
[15134] | 82 |
|
---|
[17442] | 83 | #PATH
|
---|
[20077] | 84 | addtopath PATH "$GSDL3SRCHOME/bin/script"
|
---|
| 85 | addtopath PATH "$GSDL3SRCHOME/bin"
|
---|
| 86 | echo " - Adjusted PATH"
|
---|
[6433] | 87 |
|
---|
[20077] | 88 | #MANPATH
|
---|
| 89 | addtopath MANPATH "$GSDL3SRCHOME/doc/man"
|
---|
| 90 | echo " - Adjusted MANPATH"
|
---|
| 91 |
|
---|
[17442] | 92 | #CLASSPATH
|
---|
[20233] | 93 | addtopath CLASSPATH "."
|
---|
[20077] | 94 | addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
|
---|
| 95 | addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
|
---|
[20211] | 96 | addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
|
---|
| 97 |
|
---|
[32488] | 98 | # Greenstone JAR files
|
---|
| 99 | for JARFILE in "$GSDL3HOME/WEB-INF/lib"/*.jar; do
|
---|
| 100 | addtopath CLASSPATH "$JARFILE"
|
---|
| 101 | done
|
---|
| 102 |
|
---|
[20088] | 103 | # Tomcat 5 jar files
|
---|
[20187] | 104 | for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
|
---|
[20077] | 105 | addtopath CLASSPATH "$JARFILE"
|
---|
| 106 | done
|
---|
[20088] | 107 | # Tomcat 6 jar files
|
---|
[20187] | 108 | for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
|
---|
[20088] | 109 | addtopath CLASSPATH "$JARFILE"
|
---|
| 110 | done
|
---|
| 111 |
|
---|
[20211] | 112 | #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
|
---|
| 113 | #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
|
---|
| 114 | # addtopath CLASSPATH "$JARFILE"
|
---|
| 115 | #done
|
---|
[20219] | 116 |
|
---|
[20077] | 117 | echo " - Adjusted CLASSPATH"
|
---|
[8060] | 118 |
|
---|
[17442] | 119 | #LD_LIBRARY_PATH
|
---|
[20077] | 120 | addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
| 121 | addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
| 122 | echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
|
---|
[15134] | 123 |
|
---|
[17442] | 124 | #ant
|
---|
[20252] | 125 | ANT_VERSION=1.7.1
|
---|
[20077] | 126 | if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
|
---|
| 127 | ANT_HOME="$GSDL3SRCHOME/packages/ant"
|
---|
| 128 | export ANT_HOME
|
---|
| 129 | addtopath PATH "$ANT_HOME/bin"
|
---|
[20093] | 130 | echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
|
---|
[17442] | 131 | else
|
---|
[20305] | 132 | which ant &> /dev/null
|
---|
| 133 | if [ "$?" == "0" ]; then
|
---|
| 134 | echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
|
---|
| 135 | echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
| 136 | elif [ "ANT_HOME" != "" ]; then
|
---|
| 137 | addtopath PATH "$ANT_HOME/bin"
|
---|
| 138 | echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
|
---|
| 139 | echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
| 140 | else
|
---|
| 141 | echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
|
---|
| 142 | echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
| 143 | fi
|
---|
[17442] | 144 | fi
|
---|
[15134] | 145 |
|
---|
[20303] | 146 | #ImageMagick
|
---|
[25566] | 147 | #if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
|
---|
| 148 | # addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
|
---|
| 149 | # MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
|
---|
| 150 | # export MAGICK_HOME
|
---|
| 151 | # if test "$GSDLOS" = "linux"; then
|
---|
| 152 | # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
|
---|
| 153 | # elif test "$GSDLOS" = "darwin"; then
|
---|
| 154 | # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
|
---|
| 155 | # fi
|
---|
| 156 | # echo " - Setup ImageMagick"
|
---|
| 157 | #fi
|
---|
[20303] | 158 |
|
---|
| 159 | #Ghostscript
|
---|
| 160 | if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
|
---|
| 161 | addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
|
---|
[20305] | 162 | GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
|
---|
| 163 | export GS_LIB
|
---|
| 164 | GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
|
---|
| 165 | export GS_FONTPATH
|
---|
[20303] | 166 | echo " - Setup GhostScript"
|
---|
| 167 | fi
|
---|
| 168 |
|
---|
[25448] | 169 | #wvWare
|
---|
| 170 | # wvWare's environment is now set up by bin/script/wvware.pl
|
---|
| 171 | # The wvware.pl script can be called from the cmdline to perform wvware tasks.
|
---|
| 172 | # GLI calls gsConvert.pl which calls wvware.pl to similarly perform wvware tasks.
|
---|
| 173 | # if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
|
---|
| 174 | # if test "$GSDLOS" = "linux"; then
|
---|
| 175 | # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
|
---|
| 176 | # elif test "$GSDLOS" = "darwin"; then
|
---|
| 177 | # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
|
---|
| 178 | # fi
|
---|
| 179 | # echo " - Setup wvWare"
|
---|
| 180 | # fi
|
---|
[20303] | 181 |
|
---|
[14726] | 182 | }
|
---|
[6433] | 183 |
|
---|
[15131] | 184 | function checkJava() {
|
---|
[15138] | 185 |
|
---|
[30106] | 186 | # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs
|
---|
[31481] | 187 | BUNDLED_JRE="`pwd`/packages/jre"
|
---|
| 188 | HINT=$BUNDLED_JRE
|
---|
[30755] | 189 |
|
---|
| 190 | #if [ "$GSDLOS" = "darwin" ] && [ ! -d "$HINT" ]; then
|
---|
| 191 | if [ "$GSDLOS" = "darwin" ]; then
|
---|
| 192 | if [ "$JAVA_HOME" != "" ] && [ -d "$JAVA_HOME" ]; then
|
---|
| 193 | HINT=$JAVA_HOME
|
---|
| 194 | elif [ ! -d "$HINT" ]; then
|
---|
| 195 | HINT=`/usr/libexec/java_home`
|
---|
| 196 | # old code used as fallback:
|
---|
| 197 | if [ ! -d "$HINT" ]; then
|
---|
| 198 | HINT=/System/Library/Frameworks/JavaVM.framework/Home
|
---|
| 199 | fi
|
---|
[30106] | 200 | fi
|
---|
[20216] | 201 | fi
|
---|
[20217] | 202 |
|
---|
[31481] | 203 | if [ "$DEBUG" == "true" ]; then echo "**********************************************"; fi
|
---|
[31462] | 204 |
|
---|
| 205 | # If the file utility exists, use it to determine the bitness of this GS3,
|
---|
| 206 | # particularly of this GS3's lib\jni\libgdbmjava.so (gdbmjava.dll), since we prefer a matching java
|
---|
| 207 | # If any executable doesn't exist, the return value is 127.
|
---|
| 208 | # If file utility exists, then 0 is returned on successful execution, 1 is an error exit code
|
---|
| 209 | # Running file without arg returns 1 therefore.
|
---|
| 210 |
|
---|
| 211 | # Determine the bitness of this GS3 installation, by running:
|
---|
| 212 | # `file lib/jni/libgdbmjava.so`
|
---|
| 213 | # Output:
|
---|
| 214 | # lib/jni/libgdbmjava.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
|
---|
| 215 | # dynamically linked, BuildID[sha1]=5ae42cf69275408bdce97697d69e9e6fd481420d, not stripped
|
---|
| 216 | # On 32-bit linux, the output will contain "lib/jni/libgdbmjava.so: ELF 32-bit ..."
|
---|
| 217 | # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash
|
---|
| 218 |
|
---|
| 219 | fileexists=`file 2&> /dev/null`
|
---|
| 220 |
|
---|
| 221 | # Integer comparison, http://tldp.org/LDP/abs/html/comparison-ops.html
|
---|
| 222 | # can also use double brackets: if [[ $? > 1 ]]; then ...
|
---|
| 223 | if [ "$?" -gt "1" ]; then
|
---|
[31481] | 224 | if [ "$DEBUG" == "true" ]; then
|
---|
| 225 | echo " 'file' utility not found installed on this unix-based system."
|
---|
| 226 | echo " Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found."
|
---|
| 227 | fi
|
---|
[31462] | 228 | bitness=-1
|
---|
[31481] | 229 | elif [ ! -f "$GSDL3SRCHOME/lib/jni/libgdbmjava.so" ]; then
|
---|
| 230 | # the file we want to test the bitness of, to determine GS3's bitness by, doesn't exist yet
|
---|
| 231 | bitness=-1
|
---|
[31462] | 232 | else
|
---|
| 233 | bitness=`file $GSDL3SRCHOME/lib/jni/libgdbmjava.so`
|
---|
| 234 | if [[ $bitness == *"64-bit"* ]]; then
|
---|
| 235 | bitness=64
|
---|
| 236 | echo "The installed Greenstone is $bitness bit"
|
---|
| 237 | elif [[ $bitness == *"32-bit"* ]]; then
|
---|
| 238 | bitness=32
|
---|
| 239 | echo "The installed Greenstone is $bitness bit"
|
---|
| 240 | else
|
---|
| 241 | bitness=-1
|
---|
| 242 | echo "WARNING: Greenstone installation is of unknown bitness. \"$bitness\" is neither 32 nor 64 bit"
|
---|
| 243 | fi
|
---|
| 244 | fi
|
---|
| 245 |
|
---|
| 246 | # If search4j is present, use it to locate a java.
|
---|
| 247 | # If search4j finds a Java, then:
|
---|
| 248 | # - If its bitness doesn't match and there's a bundled jre, use the bundled jre instead.
|
---|
| 249 | # - If its bitness doesn't match and there's no bundled jre, use the java found by search4j anyway,
|
---|
| 250 | # we'll print a warning about this bitness mismatch at the end
|
---|
| 251 |
|
---|
[31481] | 252 | javaset=false
|
---|
[20217] | 253 | if [ -x bin/search4j ] ; then
|
---|
[31481] | 254 | FOUNDJAVAHOME="`bin/search4j -d -p \"$HINT\" -m $java_min_version`"
|
---|
| 255 | javahome_retval=$?
|
---|
| 256 | FOUNDJREHOME="`bin/search4j -r -p \"$HINT\" -m $java_min_version`"
|
---|
| 257 | jrehome_retval=$?
|
---|
| 258 | fi
|
---|
| 259 |
|
---|
| 260 | # 1. check the bitness of any JDK java found by search4j, and use if appropriate
|
---|
| 261 | if [ "$javahome_retval" == "0" ]; then
|
---|
[31486] | 262 | setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
|
---|
| 263 | if [ "$?" == "0" ]; then javaset="true"; fi
|
---|
[31481] | 264 | fi
|
---|
| 265 |
|
---|
[31486] | 266 | # 2. check the bitness of any JRE java found by search4j, and use if appropriate
|
---|
| 267 | if [ "$javaset" != "true" ] && [ "$jrehome_retval" == "0" ]; then
|
---|
| 268 | setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
|
---|
| 269 | if [ "$?" == "0" ]; then javaset="true"; fi
|
---|
[31481] | 270 | fi
|
---|
[31486] | 271 |
|
---|
[31481] | 272 | # 3. check the bitness of any bundled JRE, and use if appropriate
|
---|
[31486] | 273 | # For linux, the bundled JRE ought to be of a bitness matching this OS.
|
---|
[31481] | 274 | if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ]; then
|
---|
[31486] | 275 | setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "bundled JRE"
|
---|
| 276 | if [ "$?" == "0" ]; then javaset="true"; fi
|
---|
[31481] | 277 | fi
|
---|
| 278 |
|
---|
[31486] | 279 |
|
---|
| 280 | # 4. None of the java found so far (via search4j, bundled_jre), if any, may have matched bitness wise
|
---|
[31481] | 281 | # So, fall back to using whichever is available in sequence anyway.
|
---|
| 282 | # We'll print a warning of bitness mismatch later
|
---|
| 283 |
|
---|
| 284 | if [ "$javaset" != "true" ]; then
|
---|
| 285 | # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present
|
---|
| 286 | if [ "$javahome_retval" == "0" ]; then
|
---|
| 287 | setupJavaAt "$FOUNDJAVAHOME" "JDK"
|
---|
| 288 | javaset=true
|
---|
| 289 | elif [ "$jrehome_retval" == "0" ]; then
|
---|
| 290 | setupJavaAt "$FOUNDJREHOME" "JRE"
|
---|
| 291 | javaset=true
|
---|
| 292 | elif [ -d "$BUNDLED_JRE" ]; then
|
---|
| 293 | # bundled JRE should be >= than minimum version of java required
|
---|
| 294 | setupJavaAt "$BUNDLED_JRE" "JRE"
|
---|
| 295 | javaset=true
|
---|
| 296 | fi
|
---|
| 297 | fi
|
---|
| 298 |
|
---|
[31486] | 299 | # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
|
---|
[31481] | 300 | if [ "$javaset" != "true" ]; then
|
---|
| 301 |
|
---|
| 302 | if [ -x bin/search4j ]; then
|
---|
| 303 |
|
---|
| 304 | # no suitable java could be found by search4j
|
---|
| 305 | echo " - ERROR: Failed to locate java $java_min_version or greater"
|
---|
[20217] | 306 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
| 307 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
| 308 |
|
---|
[31481] | 309 | else
|
---|
| 310 | # search4j wasn't present, and no bundled JRE, so check JAVA_HOME or JRE_HOME manually
|
---|
[31462] | 311 | echo "*** Could not find an appropriate JDK or JRE java"
|
---|
| 312 | echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment"
|
---|
[20233] | 313 |
|
---|
[31462] | 314 | if [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
|
---|
| 315 | echo " - Using java at $JAVA_HOME"
|
---|
| 316 | echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
| 317 | echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
| 318 | echo " (SVN users may still use java 1.4)"
|
---|
| 319 | elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
|
---|
| 320 | echo " - Using java at $JRE_HOME"
|
---|
| 321 | echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
| 322 | echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
| 323 | echo " (SVN users may still use java 1.4)"
|
---|
| 324 |
|
---|
| 325 | #failing all that, print a warning
|
---|
| 326 | else
|
---|
| 327 | #no suitable java exists
|
---|
| 328 | echo " - ERROR: Failed to locate java"
|
---|
| 329 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
| 330 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
| 331 | return
|
---|
| 332 | fi
|
---|
[31481] | 333 | fi
|
---|
[15131] | 334 | fi
|
---|
[31462] | 335 |
|
---|
| 336 | # If we know the bitness of this GS3 installation, then warn if there's a mismatch
|
---|
| 337 | # with the bitness of the Java found
|
---|
| 338 |
|
---|
| 339 | if [ "$bitness" != "-1" ]; then
|
---|
| 340 | if [ "$JAVA_HOME" != "" ]; then
|
---|
| 341 | JAVA_FOUND=$JAVA_HOME
|
---|
| 342 | elif [ "$JRE_HOME" != "" ]; then
|
---|
| 343 | JAVA_FOUND=$JRE_HOME
|
---|
| 344 | fi
|
---|
| 345 | checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness"
|
---|
| 346 | if [ "$?" == "1" ]; then
|
---|
| 347 | echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)"
|
---|
| 348 | echo "*** and the Java found at $JAVA_FOUND/bin/java"
|
---|
| 349 | echo "*** Continuing with this Java anyway:"
|
---|
| 350 | echo "*** This will only affect MG/MGPP collections for searching, and GDBM database collections"
|
---|
| 351 | echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java"
|
---|
| 352 | echo "*** Or recompile GS with your system Java:"
|
---|
| 353 | if [ "$JAVA_HOME" != "" ]; then
|
---|
| 354 | echo "*** JAVA_HOME at $JAVA_HOME"
|
---|
| 355 | else
|
---|
| 356 | echo "*** JRE_HOME at $JRE_HOME"
|
---|
| 357 | fi
|
---|
| 358 | fi
|
---|
| 359 | fi
|
---|
| 360 |
|
---|
[31481] | 361 | if [ "$DEBUG" == "true" ]; then echo "**********************************************"; fi
|
---|
| 362 |
|
---|
[15131] | 363 | }
|
---|
[6433] | 364 |
|
---|
[31486] | 365 | # http://www.linuxjournal.com/content/return-values-bash-functions
|
---|
| 366 | function setJavaIfOK {
|
---|
| 367 |
|
---|
| 368 | if [ "$DEBUG" == "true" ]; then echo "Testing java at $3"; fi
|
---|
| 369 |
|
---|
| 370 | DEBUG=$1
|
---|
| 371 | bitness=$2
|
---|
| 372 | PATHTOJAVA=$3
|
---|
| 373 | JDKorJRE=$4
|
---|
| 374 |
|
---|
| 375 | checkJavaBitnessAgainstGSBitness "$PATHTOJAVA" "$bitness"
|
---|
| 376 |
|
---|
| 377 | isjavaset=false
|
---|
| 378 |
|
---|
| 379 | if [ "$?" == "0" ]; then
|
---|
| 380 | # http://tldp.org/LDP/abs/html/comparison-ops.html
|
---|
| 381 | if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
|
---|
| 382 | # java matches GS bitness
|
---|
| 383 | if [[ "$JDKorJRE" == *"bundled"* ]]; then
|
---|
| 384 | echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
|
---|
| 385 | else
|
---|
| 386 | echo " The detected $JDKorJRE at $PATHTOJAVA is a matching $bitness bit"
|
---|
| 387 | fi
|
---|
| 388 | fi
|
---|
| 389 | setupJavaAt "$PATHTOJAVA" "$JDKorJRE"
|
---|
| 390 | isjavaset=true
|
---|
| 391 |
|
---|
| 392 | elif [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
|
---|
| 393 | if [[ "$JDKorJRE" == *"bundled"* ]]; then
|
---|
| 394 | echo " The $JDKorJRE java is an incompatible bit architecture"
|
---|
| 395 | else
|
---|
| 396 | echo " The detected $JDKorJRE java is an incompatible bit architecture"
|
---|
| 397 | fi
|
---|
| 398 | fi
|
---|
| 399 |
|
---|
| 400 | if [ "$isjavaset" == "true" ]; then
|
---|
| 401 | return 0 # success
|
---|
| 402 | else
|
---|
| 403 | return 1
|
---|
| 404 | fi
|
---|
| 405 | }
|
---|
| 406 |
|
---|
[31481] | 407 | # if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
|
---|
[31462] | 408 | function checkJavaBitnessAgainstGSBitness() {
|
---|
[31481] | 409 | # if [ "$DEBUG" == "true" ]; then echo "Testing bitness of java found at $java_installation"; fi
|
---|
[31462] | 410 | java_installation="$1"
|
---|
| 411 | bitness="$2"
|
---|
| 412 |
|
---|
| 413 | # bitness can be -1 if the 'file' utility could not be found to determine bitness
|
---|
| 414 | # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully
|
---|
| 415 | if [ "$bitness" == "-1" ]; then
|
---|
| 416 | return 0
|
---|
| 417 | fi
|
---|
| 418 |
|
---|
| 419 | # now we can actually work out if the java install's bitness matches that of GS ($bitness)
|
---|
| 420 | # java -d32 -version should return 0 if the Java is 32 bit, and 1 (failure) if the Java is 64 bit.
|
---|
| 421 | # Likewise, java -d64 -version will return 0 if the Java is 64 bit, and 1 (failure) if the Java is 32 bit.
|
---|
| 422 | `$java_installation/bin/java -d$bitness -version 2> /dev/null`
|
---|
| 423 |
|
---|
| 424 | if [ "$?" == "0" ]; then
|
---|
| 425 | return 0
|
---|
| 426 | elif [ "$?" == "1" ]; then
|
---|
| 427 | return 1
|
---|
| 428 | else
|
---|
| 429 | echo "*** Problem determining bitness of java using java at $java_installation"
|
---|
| 430 | return $?
|
---|
| 431 | fi
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 |
|
---|
[20217] | 435 | function setupJavaAt() {
|
---|
[31481] | 436 |
|
---|
| 437 | # check the second parameter if non-null
|
---|
| 438 | if [ -n "$2" ] && [ "$2" == "JRE" ]; then
|
---|
| 439 | export JRE_HOME="$1"
|
---|
[31746] | 440 | addtopath PATH "$JRE_HOME/bin"
|
---|
[31481] | 441 |
|
---|
| 442 | BUNDLED_JRE="`pwd`/packages/jre"
|
---|
| 443 | if [[ "$JRE_HOME" == *"$BUNDLED_JRE"* ]]; then
|
---|
| 444 | msg="the bundled"
|
---|
| 445 | fi
|
---|
| 446 |
|
---|
| 447 | echo " - Exported JRE_HOME to $msg $JRE_HOME"
|
---|
| 448 | else
|
---|
| 449 | export JAVA_HOME="$1"
|
---|
| 450 | addtopath PATH "$JAVA_HOME/bin"
|
---|
| 451 | echo " - Exported JAVA_HOME to $JAVA_HOME"
|
---|
| 452 | fi
|
---|
| 453 |
|
---|
| 454 |
|
---|
[20217] | 455 | }
|
---|
| 456 |
|
---|
[14726] | 457 | function pauseAndExit(){
|
---|
| 458 | echo -n "Please press any key to continue... "
|
---|
| 459 | read
|
---|
| 460 | }
|
---|
[6433] | 461 |
|
---|
[15131] | 462 | function isinpath() {
|
---|
[17442] | 463 | for file in `echo $1 | sed 's/:/ /g'`; do
|
---|
| 464 | if [ "$file" == "$2" ]; then
|
---|
| 465 | echo true
|
---|
| 466 | return
|
---|
| 467 | fi
|
---|
| 468 | done
|
---|
| 469 | echo false
|
---|
[15131] | 470 | }
|
---|
| 471 |
|
---|
[20077] | 472 | function addtopath() {
|
---|
[20078] | 473 | eval "PV=\$$1"
|
---|
[20083] | 474 | #echo "$1 += $2"
|
---|
| 475 | if [ "$PV" == "" ]; then
|
---|
| 476 | cmd="$1=\"$2\""
|
---|
| 477 | else
|
---|
| 478 | cmd="$1=\"$2:\$$1\""
|
---|
[20077] | 479 | fi
|
---|
[20083] | 480 | eval $cmd
|
---|
| 481 | eval "export $1"
|
---|
[20077] | 482 | }
|
---|
[20078] | 483 |
|
---|
[20189] | 484 | # Note: use return not exit from a sourced script otherwise it kills the shell
|
---|
[15131] | 485 | echo
|
---|
[14726] | 486 | testSource
|
---|
[20189] | 487 | if [ "$?" == "1" ]; then
|
---|
| 488 | return
|
---|
| 489 | fi
|
---|
| 490 | testAlreadySourced
|
---|
| 491 | if [ "$?" == "1" ]; then
|
---|
| 492 | return
|
---|
| 493 | fi
|
---|
[14726] | 494 | setGS3ENV
|
---|
[20982] | 495 |
|
---|
[21320] | 496 | if test -e gs2build/setup.bash ; then
|
---|
| 497 | echo ""
|
---|
| 498 | echo "Sourcing gs2build/setup.bash"
|
---|
| 499 | cd gs2build ; source setup.bash ; cd ..
|
---|
| 500 | fi
|
---|
| 501 |
|
---|
[24335] | 502 |
|
---|
[23894] | 503 | if test "x$gsopt_noexts" != "x1" ; then
|
---|
| 504 | if test -e ext ; then
|
---|
| 505 | for gsdl_ext in ext/* ; do
|
---|
| 506 | if [ -d $gsdl_ext ] ; then
|
---|
| 507 | cd $gsdl_ext > /dev/null
|
---|
[24335] | 508 | if test -e gs3-setup.sh ; then
|
---|
| 509 | source ./gs3-setup.sh
|
---|
| 510 | elif test -e setup.bash ; then
|
---|
[23894] | 511 | source ./setup.bash
|
---|
| 512 | fi
|
---|
| 513 | cd ../..
|
---|
| 514 | fi
|
---|
| 515 | done
|
---|
[20984] | 516 | fi
|
---|
| 517 | fi
|
---|
| 518 |
|
---|
[20982] | 519 | if test -e local ; then
|
---|
| 520 | if test -e local/gs3-setup.sh ; then
|
---|
[20984] | 521 | echo ""
|
---|
[20982] | 522 | echo "Sourcing local/gs3-setup.sh"
|
---|
| 523 | cd local ; source gs3-setup.sh ; cd ..
|
---|
| 524 | fi
|
---|
| 525 | fi
|
---|
| 526 |
|
---|
[20984] | 527 |
|
---|
| 528 | checkJava
|
---|
| 529 | echo ""
|
---|