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