Changeset 31486 for main


Ignore:
Timestamp:
2017-03-10T17:21:09+13:00 (7 years ago)
Author:
ak19
Message:

Moved repetitive code structure into a function.

File:
1 edited

Legend:

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

    r31483 r31486  
    255255  # 1. check the bitness of any JDK java found by search4j, and use if appropriate
    256256  if [ "$javahome_retval" == "0" ]; then
    257       checkJavaBitnessAgainstGSBitness "$FOUNDJAVAHOME" "$bitness"
    258 
    259       if [ "$?" == "0" ]; then
    260           #found a suitable java
    261       if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
    262           echo "    The detected JDK at $FOUNDJAVAHOME is a matching $bitness bit"
    263       fi
    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"
    281       fi
    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 
     257      setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
     258      if [ "$?" == "0" ]; then javaset="true"; fi
     259  fi
     260
     261  # 2. check the bitness of any JRE java found by search4j, and use if appropriate
     262  if [ "$javaset" != "true" ] && [ "$jrehome_retval" == "0" ]; then
     263      setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
     264      if [ "$?" == "0" ]; then javaset="true"; fi
     265  fi
     266 
    290267  # 3. check the bitness of any bundled JRE, and use if appropriate
     268  # For linux, the bundled JRE ought to be of a bitness matching this OS.
    291269  if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ]; then
    292       checkJavaBitnessAgainstGSBitness "$BUNDLED_JRE" "$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
    298           echo "*** Changing to use Greenstone's bundled $bitness-bit jre at $BUNDLED_JRE"
    299       fi
    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
     270      setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "bundled JRE"
     271      if [ "$?" == "0" ]; then javaset="true"; fi
     272  fi
     273
     274
     275  # 4. None of the java found so far (via search4j, bundled_jre), if any, may have matched bitness wise
    309276  # So, fall back to using whichever is available in sequence anyway.
    310277  # We'll print a warning of bitness mismatch later
     
    325292  fi
    326293
    327   # 5. lastly, check if java already setup
     294  # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
    328295  if [ "$javaset" != "true" ]; then
    329296
     
    391358}
    392359
     360# http://www.linuxjournal.com/content/return-values-bash-functions
     361function setJavaIfOK {
     362
     363    if [ "$DEBUG" == "true" ]; then echo "Testing java at $3"; fi
     364
     365    DEBUG=$1
     366    bitness=$2
     367    PATHTOJAVA=$3
     368    JDKorJRE=$4
     369
     370    checkJavaBitnessAgainstGSBitness "$PATHTOJAVA" "$bitness"
     371   
     372    isjavaset=false
     373
     374    if [ "$?" == "0" ]; then
     375    # http://tldp.org/LDP/abs/html/comparison-ops.html
     376    if [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
     377        # java matches GS bitness
     378        if [[ "$JDKorJRE" == *"bundled"* ]]; then
     379        echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
     380        else
     381        echo "    The detected $JDKorJRE at $PATHTOJAVA is a matching $bitness bit"
     382        fi
     383    fi
     384    setupJavaAt "$PATHTOJAVA" "$JDKorJRE"
     385    isjavaset=true
     386   
     387    elif [ "$bitness" != "-1" ] && [ "$DEBUG" == "true" ]; then
     388    if [[ "$JDKorJRE" == *"bundled"* ]]; then
     389        echo "    The $JDKorJRE java is an incompatible bit architecture"
     390    else
     391        echo "    The detected $JDKorJRE java is an incompatible bit architecture"
     392    fi
     393    fi
     394   
     395    if [ "$isjavaset" == "true" ]; then
     396    return 0 # success
     397    else
     398    return 1
     399    fi
     400}
     401
    393402# if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
    394403function checkJavaBitnessAgainstGSBitness() {
Note: See TracChangeset for help on using the changeset viewer.