Changeset 35668
- Timestamp:
- 2021-10-22T16:39:57+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/gs3-setup.sh
r35661 r35668 8 8 9 9 # java_min_version gets passed to search4j as the minimum java version 10 java_min_version=1. 5.0_0010 java_min_version=1.8.0 11 11 DEBUG=false 12 12 13 function testSource(){13 testSource() { 14 14 15 15 if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then … … 24 24 if test -n "$gsdl_not_sourced" ; then 25 25 echo " Error: Make sure you source this script, not execute it. Eg:" 26 echo " $ sourcegs3-setup.sh"26 echo " $ . ./gs3-setup.sh" 27 27 echo " or" 28 echo " $ .gs3-setup.sh"28 echo " $ source ./gs3-setup.sh" 29 29 echo " not" 30 30 echo " $ ./gs3-setup.sh" … … 44 44 # current directory in which case it was a different gs3 installation, so lets 45 45 # do it now. 46 functiontestAlreadySourced() {47 if [ ! -z "$GSDL3SRCHOME" ] ; then46 testAlreadySourced() { 47 if [ ! -z "$GSDL3SRCHOME" ] ; then 48 48 localgs3sourcehome="`pwd`" 49 if [ "$GSDL3SRCHOME" = "$localgs3sourcehome" ] ; then49 if [ "$GSDL3SRCHOME" = "$localgs3sourcehome" ] ; then 50 50 echo "Your environment is already set up for Greenstone3" 51 51 return 1 … … 57 57 } 58 58 59 functionsetGS3ENV() {59 setGS3ENV() { 60 60 61 61 echo "Setting up your environment for Greenstone3" … … 89 89 addtopath PATH "$GSDL3SRCHOME/bin" 90 90 echo " - Adjusted PATH" 91 if [ "$DEBUG" = "true" ] ; then91 if [ "$DEBUG" = "true" ] ; then 92 92 echo " = $PATH" 93 93 fi … … 96 96 addtopath MANPATH "$GSDL3SRCHOME/doc/man" 97 97 echo " - Adjusted MANPATH" 98 if [ "$DEBUG" = "true" ] ; then98 if [ "$DEBUG" = "true" ] ; then 99 99 echo " = $MANPATH" 100 100 fi … … 130 130 131 131 echo " - Adjusted CLASSPATH" 132 if [ "$DEBUG" = "true" ] ; then132 if [ "$DEBUG" = "true" ] ; then 133 133 echo " = $CLASSPATH" 134 134 fi … … 138 138 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni" 139 139 echo " - Adjusted LD_LIBRARY_PATH" 140 if [ "$DEBUG" = "true" ] ; then140 if [ "$DEBUG" = "true" ] ; then 141 141 echo " = $LD_LIBRARY_PATH" 142 142 fi 143 143 144 144 echo " - Adjusted DYLD_LIBRARY_PATH" 145 if [ "$DEBUG" = "true" ] ; then145 if [ "$DEBUG" = "true" ] ; then 146 146 echo " = $DYLD_LIBRARY_PATH" 147 147 fi … … 185 185 } 186 186 187 functioncheckJava() {187 checkJava() { 188 188 189 189 # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs … … 191 191 HINT=$BUNDLED_JRE 192 192 193 if [ "$GSDLOS" = "darwin" ] ; then193 if [ "$GSDLOS" = "darwin" ] ; then 194 194 # try $JAVA_HOME first, if it is set 195 if [ " $JAVA_HOME" != "" ] && [ -d "$JAVA_HOME" ]; then195 if [ "x$JAVA_HOME" != "x" ] && [ -d "$JAVA_HOME" ] ; then 196 196 HINT=$JAVA_HOME 197 elif [ ! -d "$HINT" ] ; then197 elif [ ! -d "$HINT" ] ; then 198 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 199 # but if its not there, try the following: … … 202 202 # old code used as fallback: 203 203 # But actually this is not valid for Mojave and Catalina 204 if [ ! -d "$HINT" ] ; then204 if [ ! -d "$HINT" ] ; then 205 205 HINT=/System/Library/Frameworks/JavaVM.framework/Home 206 206 fi … … 208 208 fi 209 209 210 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi210 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi 211 211 212 212 # If the file utility exists, use it to determine the bitness of this GS3, … … 224 224 # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash 225 225 226 fileexists=`file 2&> /dev/null` 227 228 TESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.so" 226 echo "" 227 command -v file > /dev/null 2>&1 228 file_cmd_status=$? 229 230 JNITESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.so" 229 231 if test "$GSDLOS" = "darwin"; then 230 TESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.jnilib" 231 fi 232 233 # Integer comparison, http://tldp.org/LDP/abs/html/comparison-ops.html 234 # can also use double brackets: if [[ $? > 1 ]]; then ... 235 if [ "$?" -gt "1" ]; then 236 if [ "$DEBUG" = "true" ]; then 232 JNITESTFILE="$GSDL3SRCHOME/lib/jni/libgdbmjava.jnilib" 233 fi 234 235 if [ $file_cmd_status != 0 ] ; then 236 if [ "$DEBUG" = "true" ] ; then 237 237 echo " 'file' utility not found installed on this unix-based system." 238 238 echo " Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found." 239 239 fi 240 240 bitness=-1 241 elif [ ! -f "$ TESTFILE" ]; then241 elif [ ! -f "$JNITESTFILE" ] ; then 242 242 # the file we want to test the bitness of, to determine GS3's bitness by, doesn't exist yet 243 # echo " $ TESTFILE is not found, unable to determine bitness of this Greenstone3"243 # echo " $JNITESTFILE is not found, unable to determine bitness of this Greenstone3" 244 244 echo " - No JNI files detected. Skipping Java bitness test" 245 245 bitness=-1 246 246 else 247 bitness=`file $ TESTFILE`248 if [ [ $bitness = *"64-bit"* ]]; then247 bitness=`file $JNITESTFILE | sed 's/^.* \([0-9]\+-bit\).*$/\1/'` 248 if [ $bitness = "64-bit" ] ; then 249 249 bitness=64 250 250 # echo "The installed Greenstone is $bitness bit" 251 elif [ [ $bitness = *"32-bit"* ]]; then251 elif [ $bitness = "32-bit" ]] ; then 252 252 bitness=32 253 253 # echo "The installed Greenstone is $bitness bit" … … 277 277 278 278 # 1. check the bitness of any JDK java found by search4j, and use if appropriate 279 if [ "$javahome_retval" = "0" ] ; then279 if [ "$javahome_retval" = "0" ] ; then 280 280 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK" 281 if [ "$?" = "0" ] ; then javaset="true"; fi281 if [ "$?" = "0" ] ; then javaset="true"; fi 282 282 fi 283 283 284 284 # 2. check the bitness of any JRE java found by search4j, and use if appropriate 285 if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ] ; then285 if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ] ; then 286 286 setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE" 287 if [ "$?" = "0" ] ; then javaset="true"; fi287 if [ "$?" = "0" ] ; then javaset="true"; fi 288 288 fi 289 289 290 290 # 3. check the bitness of any bundled JRE, and use if appropriate 291 291 # For linux, the bundled JRE ought to be of a bitness matching this OS. 292 if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ] ; then292 if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ] ; then 293 293 setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "bundled JRE" 294 if [ "$?" = "0" ] ; then javaset="true"; fi294 if [ "$?" = "0" ] ; then javaset="true"; fi 295 295 fi 296 296 … … 300 300 # We'll print a warning of bitness mismatch later 301 301 302 if [ "$javaset" != "true" ] ; then302 if [ "$javaset" != "true" ] ; then 303 303 # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present 304 if [ "$javahome_retval" = "0" ] ; then304 if [ "$javahome_retval" = "0" ] ; then 305 305 setupJavaAt "$FOUNDJAVAHOME" "JDK" 306 306 javaset=true 307 elif [ "$jrehome_retval" = "0" ] ; then307 elif [ "$jrehome_retval" = "0" ] ; then 308 308 setupJavaAt "$FOUNDJREHOME" "JRE" 309 309 javaset=true 310 elif [ -d "$BUNDLED_JRE" ] ; then310 elif [ -d "$BUNDLED_JRE" ] ; then 311 311 # bundled JRE should be >= than minimum version of java required 312 312 setupJavaAt "$BUNDLED_JRE" "JRE" … … 316 316 317 317 # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist 318 if [ "$javaset" != "true" ] ; then319 320 if [ -x bin/search4j ] ; then318 if [ "$javaset" != "true" ] ; then 319 320 if [ -x bin/search4j ] ; then 321 321 322 322 # no suitable java could be found by search4j 323 echo " - ERROR: 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"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" 326 326 327 327 else … … 330 330 #echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment" 331 331 echo " - search4j' not detected. Checking for Java explicitly set through environment variables" 332 if [ " $JAVA_HOME" != "" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ]; then332 if [ "x$JAVA_HOME" != "x" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ] ; then 333 333 echo " - Using Java at $JAVA_HOME" 334 334 if [ "$DEBUG" = "true" ] ; then … … 339 339 # echo " (SVN users may still use java 1.4)" 340 340 fi 341 elif [ " $JRE_HOME" != "" ] && [ "`which java`" = "$JRE_HOME/bin/java" ]; then341 elif [ "x$JRE_HOME" != "x" ] && [ "`which java`" = "$JRE_HOME/bin/java" ] ; then 342 342 echo " - Using java at $JRE_HOME" 343 343 if [ "$DEBUG" = "true" ] ; then … … 367 367 # with the bitness of the Java found 368 368 369 if [ "$bitness" != "-1" ] ; then370 if [ " $JAVA_HOME" != "" ]; then369 if [ "$bitness" != "-1" ] ; then 370 if [ "x$JAVA_HOME" != "x" ] ; then 371 371 JAVA_FOUND=$JAVA_HOME 372 elif [ " $JRE_HOME" != "" ]; then372 elif [ "x$JRE_HOME" != "x" ] ; then 373 373 JAVA_FOUND=$JRE_HOME 374 374 fi 375 375 checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness" 376 if [ "$?" = "1" ] ; then376 if [ "$?" = "1" ] ; then 377 377 echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)" 378 378 echo "*** and the Java found at $JAVA_FOUND/bin/java" … … 381 381 echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java" 382 382 echo "*** Or recompile GS with your system Java:" 383 if [ " $JAVA_HOME" != "" ]; then383 if [ "x$JAVA_HOME" != "x" ] ; then 384 384 echo "*** JAVA_HOME at $JAVA_HOME" 385 385 else … … 389 389 fi 390 390 391 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi391 if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi 392 392 393 393 } 394 394 395 395 # http://www.linuxjournal.com/content/return-values-bash-functions 396 function setJavaIfOK{397 398 if [ "$DEBUG" = "true" ] ; then echo "Testing java at $3"; fi396 setJavaIfOK() { 397 398 if [ "$DEBUG" = "true" ] ; then echo "Testing java at $3"; fi 399 399 400 400 DEBUG=$1 … … 408 408 isjavaset=false 409 409 410 if [ "$check_status" = "0" ] ; then410 if [ "$check_status" = "0" ] ; then 411 411 # http://tldp.org/LDP/abs/html/comparison-ops.html 412 if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then412 if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then 413 413 # java matches GS bitness 414 if [[ "$JDKorJRE" = *"bundled"* ]] ; then414 if [[ "$JDKorJRE" = *"bundled"* ]] ; then 415 415 echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA" 416 416 else … … 421 421 isjavaset=true 422 422 423 elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then424 if [[ "$JDKorJRE" = *"bundled"* ]] ; then423 elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then 424 if [[ "$JDKorJRE" = *"bundled"* ]] ; then 425 425 echo " The $JDKorJRE java is an incompatible bit architecture" 426 426 else … … 429 429 fi 430 430 431 if [ "$isjavaset" = "true" ] ; then431 if [ "$isjavaset" = "true" ] ; then 432 432 return 0 # success 433 433 else … … 437 437 438 438 # if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success). 439 functioncheckJavaBitnessAgainstGSBitness() {440 # if [ "$DEBUG" = "true" ] ; then echo "Testing bitness of java found at $java_installation"; fi439 checkJavaBitnessAgainstGSBitness() { 440 # if [ "$DEBUG" = "true" ] ; then echo "Testing bitness of java found at $java_installation"; fi 441 441 java_installation="$1" 442 442 bitness="$2" … … 444 444 # bitness can be -1 if the 'file' utility could not be found to determine bitness 445 445 # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully 446 if [ "$bitness" = "-1" ] ; then446 if [ "$bitness" = "-1" ] ; then 447 447 return 0 448 448 fi … … 453 453 `$java_installation/bin/java -d$bitness -version 2> /dev/null` 454 454 455 if [ "$?" = "0" ] ; then455 if [ "$?" = "0" ] ; then 456 456 return 0 457 elif [ "$?" = "1" ]; then 458 459 # Newer Java's don't support -d, so result to using 'file' to determin bitness of 'java' binary 460 java_bitness=`file $java_installation/bin/java` 461 if [[ $java_bitness = *"$bitness-bit"* ]]; then 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 462 463 return 0 463 464 else … … 471 472 472 473 473 functionsetupJavaAt() {474 setupJavaAt() { 474 475 475 476 # check the second parameter if non-null 476 if [ -n "$2" ] && [ "$2" = "JRE" ] ; then477 if [ -n "$2" ] && [ "$2" = "JRE" ] ; then 477 478 export JRE_HOME="$1" 478 479 addtopath PATH "$JRE_HOME/bin" … … 482 483 483 484 BUNDLED_JRE="`pwd`/packages/jre" 484 if [[ "$JRE_HOME" = *"$BUNDLED_JRE"* ]] ; then485 if [[ "$JRE_HOME" = *"$BUNDLED_JRE"* ]] ; then 485 486 msg="the bundled" 486 487 fi … … 496 497 } 497 498 498 functionpauseAndExit(){499 pauseAndExit(){ 499 500 echo -n "Please press any key to continue... " 500 501 read 501 502 } 502 503 503 functionisinpath() {504 isinpath() { 504 505 for file in `echo $1 | sed 's/:/ /g'`; do 505 if [ "$file" = "$2" ] ; then506 if [ "$file" = "$2" ] ; then 506 507 echo true 507 508 return … … 511 512 } 512 513 513 functionaddtopath() {514 addtopath() { 514 515 eval "PV=\$$1" 515 516 #echo "$1 += $2" 516 if [ " $PV" = "" ]; then517 if [ "x$PV" = "x" ] ; then 517 518 cmd="$1=\"$2\"" 518 519 else … … 525 526 # Note: use return not exit from a sourced script otherwise it kills the shell 526 527 testSource 527 if [ "$?" = "1" ] ; then528 if [ "$?" = "1" ] ; then 528 529 return 529 530 fi 530 531 531 532 testAlreadySourced 532 if [ "$?" = "1" ] ; then533 if [ "$?" = "1" ] ; then 533 534 return 534 535 fi … … 539 540 echo "" 540 541 echo "Sourcing gs2build/setup.bash" 541 cd gs2build ; sourcesetup.bash ; cd ..542 cd gs2build ; . ./setup.bash ; cd .. 542 543 fi 543 544 … … 549 550 cd $gsdl_ext > /dev/null 550 551 if test -e gs3-setup.sh ; then 551 source./gs3-setup.sh552 . ./gs3-setup.sh 552 553 elif test -e setup.bash ; then 553 source./setup.bash554 . ./setup.bash 554 555 fi 555 556 cd ../.. … … 563 564 echo "" 564 565 echo "Sourcing local/gs3-setup.sh" 565 cd local ; sourcegs3-setup.sh ; cd ..566 cd local ; . ./gs3-setup.sh ; cd .. 566 567 fi 567 568 fi … … 627 628 echo " - `ant -version`" 628 629 else 629 # which ant &> /dev/null630 # which ant > /dev/null 2>&1 630 631 # Posix friendly way to determine if a program exists: 631 632 # https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script 632 command -v ant &> /dev/null633 command -v ant > /dev/null 2>&1 633 634 634 635 if [ "$?" = "0" ] ; then
Note:
See TracChangeset
for help on using the changeset viewer.