Changeset 31481

Show
Ignore:
Timestamp:
09.03.2017 19:10:38 (3 years ago)
Author:
ak19
Message:

Major overhaul of how linux gs3-setup.sh script finds java. This was necessary because the linux script didn't use to call search4j to locate a jre and jdk separately, and consequently was always setting only JAVA_HOME. The script has now been brought in line with what windows does, which required rewriting and restructuring some of the logic. It matches better with what the windows gs3-setup.bat does, and also includes the DEBUG flag to increase verbosity when needed.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/gs3-setup.sh

    r31462 r31481  
    99# java_min_version gets passed to search4j as the minimum java version 
    1010java_min_version=1.5.0_00 
    11  
     11DEBUG=false 
    1212 
    1313function testSource(){ 
     
    180180 
    181181  # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs 
    182   HINT="`pwd`/packages/jre" 
     182  BUNDLED_JRE="`pwd`/packages/jre" 
     183  HINT=$BUNDLED_JRE 
    183184   
    184185  #if [ "$GSDLOS" = "darwin" ] && [ ! -d "$HINT" ]; then 
     
    195196  fi 
    196197 
    197   echo "**********************************************" 
     198  if [ "$DEBUG" == "true" ]; then echo "**********************************************"; fi 
    198199 
    199200  # If the file utility exists, use it to determine the bitness of this GS3, 
     
    216217  #    can also use double brackets:  if [[ $? > 1 ]]; then ... 
    217218  if [ "$?" -gt "1" ]; then 
    218       echo "*** 'file' utility not found installed on this unix-based system." 
    219       echo "*** Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found." 
     219      if [ "$DEBUG" == "true" ]; then  
     220      echo "    'file' utility not found installed on this unix-based system." 
     221      echo "    Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found." 
     222      fi 
     223      bitness=-1 
     224  elif [ ! -f "$GSDL3SRCHOME/lib/jni/libgdbmjava.so" ]; then 
     225      # the file we want to test the bitness of, to determine GS3's bitness by, doesn't exist yet 
    220226      bitness=-1 
    221227  else 
     
    239245  # we'll print a warning about this bitness mismatch at the end 
    240246 
     247  javaset=false 
    241248  if [ -x bin/search4j ] ; then 
    242     FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`" 
    243     if [ "$?" == "0" ]; then 
     249      FOUNDJAVAHOME="`bin/search4j -d -p \"$HINT\" -m $java_min_version`" 
     250      javahome_retval=$? 
     251      FOUNDJREHOME="`bin/search4j -r -p \"$HINT\" -m $java_min_version`" 
     252      jrehome_retval=$? 
     253  fi 
     254 
     255  # 1. check the bitness of any JDK java found by search4j, and use if appropriate 
     256  if [ "$javahome_retval" == "0" ]; then 
    244257      checkJavaBitnessAgainstGSBitness "$FOUNDJAVAHOME" "$bitness" 
    245258 
    246259      if [ "$?" == "0" ]; then 
    247260          #found a suitable java 
    248       if [ "$bitness" != "-1" ]; then 
    249           echo "*** The detected java is a matching $bitness bit" 
     261      if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then 
     262          echo "    The detected JDK at $FOUNDJAVAHOME is a matching $bitness bit" 
    250263      fi 
    251       setupJavaAt "$FOUNDJAVAHOME" 
    252       else 
    253       if [ "$bitness" != "-1" ]; then 
    254           echo "*** The detected java is an incompatible bit architecture" 
     264      setupJavaAt "$FOUNDJAVAHOME" "JDK" 
     265      javaset=true 
     266 
     267      elif [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then      
     268      echo "    The detected JDK java at $FOUNDJAVAHOME is an incompatible bit architecture" 
     269      fi 
     270  fi 
     271 
     272  # 2. check bitness of any JRE java found by search4j, and use if appropriate 
     273  # http://tldp.org/LDP/abs/html/comparison-ops.html 
     274  if [ "$javaset" != "true" ] && [ "$jrehome_retval" == "0" ]; then       
     275      checkJavaBitnessAgainstGSBitness "$FOUNDJREHOME" "$bitness" 
     276       
     277      if [ "$?" == "0" ]; then 
     278          #found a suitable jre 
     279      if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then 
     280          echo "    The detected JRE at $FOUNDJREHOME is a matching $bitness bit" 
    255281      fi 
    256  
    257       # check any bundled JRE 
    258       if [ -d "$HINT" ]; then      
    259           # For linux, the bundled JRE will be of a bitness matching this OS. 
     282      setupJavaAt "$FOUNDJREHOME" "JRE" 
     283      javaset=true 
     284       
     285      elif [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then 
     286      echo "    The detected JRE java at $FOUNDJREHOME is an incompatible bit architecture" 
     287      fi       
     288  fi 
     289 
     290  # 3. check the bitness of any bundled JRE, and use if appropriate 
     291  if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ]; then 
     292      checkJavaBitnessAgainstGSBitness "$FOUNDJREHOME" "$bitness" 
     293       
     294      # For linux, the bundled JRE ought to be of a bitness matching this OS. 
     295      if [ "$?" == "0" ]; then 
     296      if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then 
     297          # bundled JRE matches GS bitness 
    260298          echo "*** Changing to use Greenstone's bundled $bitness-bit jre" 
    261           setupJavaAt "$HINT" "JRE" 
    262       else 
    263           # go with the JAVA_HOME that search4j found 
    264           echo "*** Using the Java detected: " 
    265           setupJavaAt "$FOUNDJAVAHOME" 
    266299      fi 
    267       fi 
    268     else 
    269       #no suitable java exists 
    270       echo "  - ERROR: Failed to locate java $java_min_version or greater" 
     300      setupJavaAt "$BUNDLED_JRE" "JRE" 
     301      javaset=true 
     302 
     303      elif [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then 
     304      echo "    The bundled JRE java is an incompatible bit architecture" 
     305      fi 
     306  fi 
     307 
     308  # 4. None of the java found so far, if any (via search4j, bundled_jre), may have matched bitness wise 
     309  # So, fall back to using whichever is available in sequence anyway. 
     310  # We'll print a warning of bitness mismatch later 
     311 
     312  if [ "$javaset" != "true" ]; then 
     313      # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present 
     314      if [ "$javahome_retval" == "0" ]; then 
     315      setupJavaAt "$FOUNDJAVAHOME" "JDK" 
     316      javaset=true 
     317      elif [ "$jrehome_retval" == "0" ]; then 
     318      setupJavaAt "$FOUNDJREHOME" "JRE" 
     319      javaset=true 
     320      elif [ -d "$BUNDLED_JRE" ]; then 
     321      # bundled JRE should be >= than minimum version of java required 
     322      setupJavaAt "$BUNDLED_JRE" "JRE" 
     323      javaset=true 
     324      fi 
     325  fi 
     326 
     327  # 5. lastly, check if java already setup 
     328  if [ "$javaset" != "true" ]; then 
     329 
     330    if [ -x bin/search4j ]; then 
     331 
     332      # no suitable java could be found by search4j 
     333      echo "  - ERROR: Failed to locate java $java_min_version or greater"     
    271334      echo "           Please set JAVA_HOME or JRE_HOME to point to an appropriate java" 
    272335      echo "           And add JAVA_HOME/bin or JRE_HOME/bin to your PATH" 
    273     fi 
    274  
    275   #otherwise no search4j, manually try the hint (the bundled jre) if it exists 
    276   elif [ -d "$HINT" ]; then 
    277       #found a suitable java 
    278       setupJavaAt "$HINT" "JRE" 
    279  
    280   #lastly, check if java already setup 
    281   else 
     336 
     337    else 
     338      # search4j wasn't present, and no bundled JRE, so check JAVA_HOME or JRE_HOME manually 
    282339      echo "*** Could not find an appropriate JDK or JRE java" 
    283340      echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment" 
     
    302359      return 
    303360      fi 
     361    fi 
    304362  fi 
    305363 
     
    329387  fi 
    330388 
    331   echo "**********************************************" 
    332 } 
    333  
     389  if [ "$DEBUG" == "true" ]; then echo "**********************************************"; fi 
     390 
     391} 
     392 
     393# if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success). 
    334394function checkJavaBitnessAgainstGSBitness() { 
    335 #    echo "Checking bitness" 
     395#    if [ "$DEBUG" == "true" ]; then echo "Testing bitness of java found at $java_installation"; fi 
    336396    java_installation="$1" 
    337397    bitness="$2" 
     
    360420 
    361421function setupJavaAt() { 
    362   export JAVA_HOME="$1" 
    363   addtopath PATH "$JAVA_HOME/bin" 
    364   echo "  - Exported JAVA_HOME to $JAVA_HOME" 
     422 
     423  # check the second parameter if non-null 
     424  if [ -n "$2" ] && [ "$2" == "JRE" ]; then 
     425    export JRE_HOME="$1" 
     426    addtopath PATH "$JAVA_HOME/bin" 
     427 
     428    BUNDLED_JRE="`pwd`/packages/jre"     
     429    if [[ "$JRE_HOME" == *"$BUNDLED_JRE"* ]]; then 
     430    msg="the bundled" 
     431    fi 
     432 
     433    echo "  - Exported JRE_HOME to $msg $JRE_HOME" 
     434  else 
     435    export JAVA_HOME="$1" 
     436    addtopath PATH "$JAVA_HOME/bin" 
     437    echo "  - Exported JAVA_HOME to $JAVA_HOME" 
     438  fi 
     439 
     440   
    365441} 
    366442