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