Changeset 31462

Show
Ignore:
Timestamp:
06.03.2017 19:40:55 (2 years ago)
Author:
ak19
Message:

Related to commits 31447 and 31461 which were for windows. The Linux GS3-setup script now also checks bitness of the GS3 installation against the bitness of the Java found. Two problems remain. 1. Linux script always sets the JAVA_HOME env var, even if a JRE_HOME is actually found. 2. On Windows, search4j favours system JAVA_HOME or JRE_HOME to the JRE_HOME in HINT. On linux, it favours the JRE_HOME in HINT over the system vars. The reason may be linked to 1.

Files:
1 modified

Legend:

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

    r30755 r31462  
    195195  fi 
    196196 
    197   #if search4j is present, use it 
     197  echo "**********************************************" 
     198 
     199  # If the file utility exists, use it to determine the bitness of this GS3, 
     200  # particularly of this GS3's lib\jni\libgdbmjava.so (gdbmjava.dll), since we prefer a matching java 
     201  # If any executable doesn't exist, the return value is 127. 
     202  # If file utility exists, then 0 is returned on successful execution, 1 is an error exit code 
     203  # Running file without arg returns 1 therefore. 
     204 
     205  # Determine the bitness of this GS3 installation, by running: 
     206  # `file lib/jni/libgdbmjava.so` 
     207  # Output: 
     208  #    lib/jni/libgdbmjava.so: ELF 64-bit LSB  shared object, x86-64, version 1 (SYSV), 
     209  #    dynamically linked, BuildID[sha1]=5ae42cf69275408bdce97697d69e9e6fd481420d, not stripped 
     210  # On 32-bit linux, the output will contain "lib/jni/libgdbmjava.so: ELF 32-bit ..." 
     211  # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash 
     212 
     213  fileexists=`file 2&> /dev/null` 
     214 
     215  # Integer comparison, http://tldp.org/LDP/abs/html/comparison-ops.html 
     216  #    can also use double brackets:  if [[ $? > 1 ]]; then ... 
     217  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." 
     220      bitness=-1 
     221  else 
     222      bitness=`file $GSDL3SRCHOME/lib/jni/libgdbmjava.so` 
     223      if [[ $bitness == *"64-bit"* ]]; then 
     224      bitness=64 
     225      echo "The installed Greenstone is $bitness bit" 
     226      elif [[ $bitness == *"32-bit"* ]]; then 
     227      bitness=32 
     228      echo "The installed Greenstone is $bitness bit" 
     229      else 
     230      bitness=-1 
     231      echo "WARNING: Greenstone installation is of unknown bitness. \"$bitness\" is neither 32 nor 64 bit" 
     232      fi 
     233  fi 
     234 
     235  # If search4j is present, use it to locate a java. 
     236  # If search4j finds a Java, then: 
     237  # - If its bitness doesn't match and there's a bundled jre, use the bundled jre instead. 
     238  # - If its bitness doesn't match and there's no bundled jre, use the java found by search4j anyway, 
     239  # we'll print a warning about this bitness mismatch at the end 
     240 
    198241  if [ -x bin/search4j ] ; then 
    199242    FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`" 
    200243    if [ "$?" == "0" ]; then 
    201       #found a suitable java 
    202       setupJavaAt "$FOUNDJAVAHOME" 
     244      checkJavaBitnessAgainstGSBitness "$FOUNDJAVAHOME" "$bitness" 
     245 
     246      if [ "$?" == "0" ]; then 
     247          #found a suitable java 
     248      if [ "$bitness" != "-1" ]; then 
     249          echo "*** The detected java is a matching $bitness bit" 
     250      fi 
     251      setupJavaAt "$FOUNDJAVAHOME" 
     252      else 
     253      if [ "$bitness" != "-1" ]; then 
     254          echo "*** The detected java is an incompatible bit architecture" 
     255      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. 
     260          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" 
     266      fi 
     267      fi 
    203268    else 
    204269      #no suitable java exists 
     
    208273    fi 
    209274 
    210   #otherwise manually try the hint 
     275  #otherwise no search4j, manually try the hint (the bundled jre) if it exists 
    211276  elif [ -d "$HINT" ]; then 
    212277      #found a suitable java 
    213       setupJavaAt "$HINT" 
     278      setupJavaAt "$HINT" "JRE" 
    214279 
    215280  #lastly, check if java already setup 
    216   elif [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then 
    217     echo "  - Using java at $JAVA_HOME" 
    218     echo "  - WARNING: Greenstone has not checked the version number of this java installation" 
    219     echo "             The source distribution of Greenstone3 requires java 1.5 or greater" 
    220     echo "             (SVN users may still use java 1.4)" 
    221   elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then 
    222     echo "  - Using java at $JRE_HOME" 
    223     echo "  - WARNING: Greenstone has not checked the version number of this java installation" 
    224     echo "             The source distribution of Greenstone3 requires java 1.5 or greater" 
    225     echo "             (SVN users may still use java 1.4)" 
    226  
    227   #failing all that, print a warning 
    228281  else 
    229     #no suitable java exists 
    230     echo "  - ERROR: Failed to locate java" 
    231     echo "           Please set JAVA_HOME or JRE_HOME to point to an appropriate java" 
    232     echo "           And add JAVA_HOME/bin or JRE_HOME/bin to your PATH" 
    233   fi 
    234 } 
     282      echo "*** Could not find an appropriate JDK or JRE java" 
     283      echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment" 
     284 
     285      if [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then 
     286      echo "  - Using java at $JAVA_HOME" 
     287      echo "  - WARNING: Greenstone has not checked the version number of this java installation" 
     288      echo "             The source distribution of Greenstone3 requires java 1.5 or greater" 
     289      echo "             (SVN users may still use java 1.4)" 
     290      elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then 
     291      echo "  - Using java at $JRE_HOME" 
     292      echo "  - WARNING: Greenstone has not checked the version number of this java installation" 
     293      echo "             The source distribution of Greenstone3 requires java 1.5 or greater" 
     294      echo "             (SVN users may still use java 1.4)" 
     295       
     296      #failing all that, print a warning 
     297      else 
     298          #no suitable java exists 
     299      echo "  - ERROR: Failed to locate java" 
     300      echo "           Please set JAVA_HOME or JRE_HOME to point to an appropriate java" 
     301      echo "           And add JAVA_HOME/bin or JRE_HOME/bin to your PATH" 
     302      return 
     303      fi 
     304  fi 
     305 
     306  # If we know the bitness of this GS3 installation, then warn if there's a mismatch 
     307  # with the bitness of the Java found 
     308 
     309  if [ "$bitness" != "-1" ]; then 
     310      if [ "$JAVA_HOME" != "" ]; then 
     311      JAVA_FOUND=$JAVA_HOME 
     312      elif [ "$JRE_HOME" != "" ]; then 
     313      JAVA_FOUND=$JRE_HOME 
     314      fi 
     315      checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness" 
     316      if [ "$?" == "1" ]; then 
     317      echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)" 
     318      echo "*** and the Java found at $JAVA_FOUND/bin/java" 
     319      echo "*** Continuing with this Java anyway:" 
     320      echo "*** This will only affect MG/MGPP collections for searching, and GDBM database collections" 
     321      echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java" 
     322      echo "*** Or recompile GS with your system Java:" 
     323      if [ "$JAVA_HOME" != "" ]; then 
     324          echo "*** JAVA_HOME at $JAVA_HOME" 
     325      else 
     326          echo "*** JRE_HOME at $JRE_HOME" 
     327      fi 
     328      fi 
     329  fi 
     330 
     331  echo "**********************************************" 
     332} 
     333 
     334function checkJavaBitnessAgainstGSBitness() { 
     335#    echo "Checking bitness" 
     336    java_installation="$1" 
     337    bitness="$2" 
     338 
     339    # bitness can be -1 if the 'file' utility could not be found to determine bitness 
     340    # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully 
     341    if [ "$bitness" == "-1" ]; then 
     342    return 0 
     343    fi 
     344 
     345    # now we can actually work out if the java install's bitness matches that of GS ($bitness) 
     346    # java -d32 -version should return 0 if the Java is 32 bit, and 1 (failure) if the Java is 64 bit. 
     347    # Likewise, java -d64 -version will return 0 if the Java is 64 bit, and 1 (failure) if the Java is 32 bit. 
     348    `$java_installation/bin/java -d$bitness -version 2> /dev/null` 
     349 
     350    if [ "$?" == "0" ]; then 
     351    return 0 
     352    elif [ "$?" == "1" ]; then 
     353    return 1 
     354    else 
     355    echo "*** Problem determining bitness of java using java at $java_installation" 
     356    return $? 
     357    fi 
     358} 
     359 
    235360 
    236361function setupJavaAt() {