Changeset 35668


Ignore:
Timestamp:
2021-10-22T16:39:57+13:00 (3 years ago)
Author:
davidb
Message:

Changes to bring the file more back in to line with being syntax friendly with 'sh' as opposed to 'bash'. Some work still to be done to eliminate use of few remaining tests

File:
1 edited

Legend:

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

    r35661 r35668  
    88
    99# java_min_version gets passed to search4j as the minimum java version
    10 java_min_version=1.5.0_00
     10java_min_version=1.8.0
    1111DEBUG=false
    1212
    13 function testSource(){
     13testSource() {
    1414
    1515  if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
     
    2424  if test -n "$gsdl_not_sourced" ; then
    2525     echo "  Error: Make sure you source this script, not execute it. Eg:"
    26      echo "    $ source gs3-setup.sh"
     26     echo "    $ . ./gs3-setup.sh"
    2727     echo "  or"
    28      echo "    $ . gs3-setup.sh"
     28     echo "    $ source ./gs3-setup.sh"
    2929     echo "  not"
    3030     echo "    $ ./gs3-setup.sh"
     
    4444# current directory in which case it was a different gs3 installation, so lets
    4545# do it now.
    46 function testAlreadySourced() {
    47   if [ ! -z "$GSDL3SRCHOME" ]; then
     46testAlreadySourced() {
     47  if [ ! -z "$GSDL3SRCHOME" ] ; then
    4848    localgs3sourcehome="`pwd`"
    49     if [ "$GSDL3SRCHOME" = "$localgs3sourcehome" ]; then
     49    if [ "$GSDL3SRCHOME" = "$localgs3sourcehome" ] ; then
    5050      echo "Your environment is already set up for Greenstone3"
    5151      return 1
     
    5757}
    5858
    59 function setGS3ENV() {
     59setGS3ENV() {
    6060
    6161  echo "Setting up your environment for Greenstone3"
     
    8989  addtopath PATH "$GSDL3SRCHOME/bin"
    9090  echo "  - Adjusted PATH"
    91   if [ "$DEBUG" = "true" ]; then
     91  if [ "$DEBUG" = "true" ] ; then
    9292    echo "     = $PATH"
    9393  fi
     
    9696  addtopath MANPATH "$GSDL3SRCHOME/doc/man"
    9797  echo "  - Adjusted MANPATH"
    98   if [ "$DEBUG" = "true" ]; then
     98  if [ "$DEBUG" = "true" ] ; then
    9999    echo "     = $MANPATH"
    100100  fi
     
    130130
    131131  echo "  - Adjusted CLASSPATH"
    132   if [ "$DEBUG" = "true" ]; then
     132  if [ "$DEBUG" = "true" ] ; then
    133133    echo "     = $CLASSPATH"
    134134  fi
     
    138138  addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
    139139  echo "  - Adjusted LD_LIBRARY_PATH"
    140   if [ "$DEBUG" = "true" ]; then
     140  if [ "$DEBUG" = "true" ] ; then
    141141    echo "     = $LD_LIBRARY_PATH"
    142142  fi
    143143
    144144  echo "  - Adjusted DYLD_LIBRARY_PATH"
    145   if [ "$DEBUG" = "true" ]; then
     145  if [ "$DEBUG" = "true" ] ; then
    146146    echo "     = $DYLD_LIBRARY_PATH"
    147147  fi
     
    185185}
    186186
    187 function checkJava() {
     187checkJava() {
    188188
    189189  # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs
     
    191191  HINT=$BUNDLED_JRE
    192192
    193   if [ "$GSDLOS" = "darwin" ]; then
     193  if [ "$GSDLOS" = "darwin" ] ; then
    194194    # try $JAVA_HOME first, if it is set
    195     if [ "$JAVA_HOME" != "" ] && [ -d "$JAVA_HOME" ]; then
     195    if [ "x$JAVA_HOME" != "x" ] && [ -d "$JAVA_HOME" ] ; then
    196196      HINT=$JAVA_HOME
    197     elif [ ! -d "$HINT" ]; then
     197    elif [ ! -d "$HINT" ] ; then
    198198    #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
    199199    # but if its not there, try the following:
     
    202202        # old code used as fallback:
    203203    # But actually this is not valid for Mojave and Catalina
    204       if [ ! -d "$HINT" ]; then
     204      if [ ! -d "$HINT" ] ; then
    205205              HINT=/System/Library/Frameworks/JavaVM.framework/Home
    206206      fi
     
    208208  fi
    209209
    210   if [ "$DEBUG" = "true" ]; then echo "**********************************************"; fi
     210  if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi
    211211
    212212  # If the file utility exists, use it to determine the bitness of this GS3,
     
    224224  # Check output string contains bitness: http://stackoverflow.com/questions/229551/string-contains-in-bash
    225225
    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"
    229231  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
    237237      echo "    'file' utility not found installed on this unix-based system."
    238238      echo "    Unable to use 'file' utility to determine bitness of this GS3 to see if it matches that of any Java found."
    239239      fi
    240240      bitness=-1
    241   elif [ ! -f "$TESTFILE" ]; then
     241  elif [ ! -f "$JNITESTFILE" ] ; then
    242242      # 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"
    244244      echo "  - No JNI files detected.  Skipping Java bitness test"
    245245      bitness=-1
    246246  else
    247       bitness=`file $TESTFILE` 
    248       if [[ $bitness = *"64-bit"* ]]; then
     247      bitness=`file $JNITESTFILE | sed 's/^.* \([0-9]\+-bit\).*$/\1/'`
     248      if [ $bitness = "64-bit" ] ; then
    249249      bitness=64
    250250#     echo "The installed Greenstone is $bitness bit"
    251       elif [[ $bitness = *"32-bit"* ]]; then
     251      elif [ $bitness = "32-bit" ]] ; then
    252252      bitness=32
    253253#     echo "The installed Greenstone is $bitness bit"
     
    277277
    278278  # 1. check the bitness of any JDK java found by search4j, and use if appropriate
    279   if [ "$javahome_retval" = "0" ]; then
     279  if [ "$javahome_retval" = "0" ] ; then
    280280      setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJAVAHOME" "JDK"
    281       if [ "$?" = "0" ]; then javaset="true"; fi
     281      if [ "$?" = "0" ] ; then javaset="true"; fi
    282282  fi
    283283
    284284  # 2. check the bitness of any JRE java found by search4j, and use if appropriate
    285   if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ]; then
     285  if [ "$javaset" != "true" ] && [ "$jrehome_retval" = "0" ] ; then
    286286      setJavaIfOK "$DEBUG" "$bitness" "$FOUNDJREHOME" "JRE"
    287       if [ "$?" = "0" ]; then javaset="true"; fi
     287      if [ "$?" = "0" ] ; then javaset="true"; fi
    288288  fi
    289289 
    290290  # 3. check the bitness of any bundled JRE, and use if appropriate
    291291  # For linux, the bundled JRE ought to be of a bitness matching this OS.
    292   if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ]; then
     292  if [ "$javaset" != "true" ] && [ -d "$BUNDLED_JRE" ] ; then
    293293      setJavaIfOK "$DEBUG" "$bitness" "$BUNDLED_JRE" "bundled JRE"
    294       if [ "$?" = "0" ]; then javaset="true"; fi
     294      if [ "$?" = "0" ] ; then javaset="true"; fi
    295295  fi
    296296
     
    300300  # We'll print a warning of bitness mismatch later
    301301
    302   if [ "$javaset" != "true" ]; then
     302  if [ "$javaset" != "true" ] ; then
    303303      # go with any JAVA_HOME else JRE_HOME that search4j found, else with any bundled JRE if present
    304       if [ "$javahome_retval" = "0" ]; then
     304      if [ "$javahome_retval" = "0" ] ; then
    305305      setupJavaAt "$FOUNDJAVAHOME" "JDK"
    306306      javaset=true
    307       elif [ "$jrehome_retval" = "0" ]; then
     307      elif [ "$jrehome_retval" = "0" ] ; then
    308308      setupJavaAt "$FOUNDJREHOME" "JRE"
    309309      javaset=true
    310       elif [ -d "$BUNDLED_JRE" ]; then
     310      elif [ -d "$BUNDLED_JRE" ] ; then
    311311      # bundled JRE should be >= than minimum version of java required
    312312      setupJavaAt "$BUNDLED_JRE" "JRE"
     
    316316
    317317  # 5. lastly, manually check if java already setup. Could be the case if search4j didn't exist
    318   if [ "$javaset" != "true" ]; then
    319 
    320     if [ -x bin/search4j ]; then
     318  if [ "$javaset" != "true" ] ; then
     319
     320    if [ -x bin/search4j ] ; then
    321321
    322322      # 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"
    326326
    327327    else
     
    330330      #echo "*** Attempting to use JAVA_HOME else JRE_HOME in the environment"
    331331      echo "  - search4j' not detected.  Checking for Java explicitly set through environment variables"
    332       if [ "$JAVA_HOME" != "" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ]; then
     332      if [ "x$JAVA_HOME" != "x" ] && [ "`which java`" = "$JAVA_HOME/bin/java" ] ; then
    333333      echo "  - Using Java at $JAVA_HOME"
    334334      if [ "$DEBUG" = "true" ] ; then
     
    339339          #       echo "             (SVN users may still use java 1.4)"
    340340      fi
    341       elif [ "$JRE_HOME" != "" ] && [ "`which java`" = "$JRE_HOME/bin/java" ]; then
     341      elif [ "x$JRE_HOME" != "x" ] && [ "`which java`" = "$JRE_HOME/bin/java" ] ; then
    342342      echo "  - Using java at $JRE_HOME"
    343343      if [ "$DEBUG" = "true" ] ; then
     
    367367  # with the bitness of the Java found
    368368
    369   if [ "$bitness" != "-1" ]; then
    370       if [ "$JAVA_HOME" != "" ]; then
     369  if [ "$bitness" != "-1" ] ; then
     370      if [ "x$JAVA_HOME" != "x" ] ; then
    371371      JAVA_FOUND=$JAVA_HOME
    372       elif [ "$JRE_HOME" != "" ]; then
     372      elif [ "x$JRE_HOME" != "x" ] ; then
    373373      JAVA_FOUND=$JRE_HOME
    374374      fi
    375375      checkJavaBitnessAgainstGSBitness "$JAVA_FOUND" "$bitness"
    376       if [ "$?" = "1" ]; then
     376      if [ "$?" = "1" ] ; then
    377377      echo "*** WARNING: Detected mismatch between the bit-ness of your GS installation ($bitness bit)"
    378378      echo "*** and the Java found at $JAVA_FOUND/bin/java"
     
    381381      echo "*** Else set JAVA_HOME or JRE_HOME to point to an appropriate $bitness bit Java"
    382382      echo "*** Or recompile GS with your system Java:"
    383       if [ "$JAVA_HOME" != "" ]; then
     383      if [ "x$JAVA_HOME" != "x" ] ; then
    384384          echo "*** JAVA_HOME at $JAVA_HOME"
    385385      else
     
    389389  fi
    390390
    391   if [ "$DEBUG" = "true" ]; then echo "**********************************************"; fi
     391  if [ "$DEBUG" = "true" ] ; then echo "**********************************************"; fi
    392392
    393393}
    394394
    395395# http://www.linuxjournal.com/content/return-values-bash-functions
    396 function setJavaIfOK {
    397 
    398     if [ "$DEBUG" = "true" ]; then echo "Testing java at $3"; fi
     396setJavaIfOK() {
     397
     398    if [ "$DEBUG" = "true" ] ; then echo "Testing java at $3"; fi
    399399
    400400    DEBUG=$1
     
    408408    isjavaset=false
    409409
    410     if [ "$check_status" = "0" ]; then
     410    if [ "$check_status" = "0" ] ; then
    411411    # http://tldp.org/LDP/abs/html/comparison-ops.html
    412     if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ]; then
     412    if [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then
    413413        # java matches GS bitness
    414         if [[ "$JDKorJRE" = *"bundled"* ]]; then
     414        if [[ "$JDKorJRE" = *"bundled"* ]] ; then
    415415        echo "*** Changing to use Greenstone's $bitness-bit $JDKorJRE at $PATHTOJAVA"
    416416        else
     
    421421    isjavaset=true
    422422   
    423     elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ]; then
    424     if [[ "$JDKorJRE" = *"bundled"* ]]; then
     423    elif [ "$bitness" != "-1" ] && [ "$DEBUG" = "true" ] ; then
     424    if [[ "$JDKorJRE" = *"bundled"* ]] ; then
    425425        echo "    The $JDKorJRE java is an incompatible bit architecture"
    426426    else
     
    429429    fi
    430430   
    431     if [ "$isjavaset" = "true" ]; then
     431    if [ "$isjavaset" = "true" ] ; then
    432432    return 0 # success
    433433    else
     
    437437
    438438# if bitness (parameter #2) is -1, then this function returns 0 (generally meaning success).
    439 function checkJavaBitnessAgainstGSBitness() {
    440 #    if [ "$DEBUG" = "true" ]; then echo "Testing bitness of java found at $java_installation"; fi
     439checkJavaBitnessAgainstGSBitness() {
     440#    if [ "$DEBUG" = "true" ] ; then echo "Testing bitness of java found at $java_installation"; fi
    441441    java_installation="$1"
    442442    bitness="$2"
     
    444444    # bitness can be -1 if the 'file' utility could not be found to determine bitness
    445445    # or if its output no longer prints "32-bit" or "64-bit". Should continue gracefully
    446     if [ "$bitness" = "-1" ]; then
     446    if [ "$bitness" = "-1" ] ; then
    447447    return 0
    448448    fi
     
    453453    `$java_installation/bin/java -d$bitness -version 2> /dev/null`
    454454
    455     if [ "$?" = "0" ]; then
     455    if [ "$?" = "0" ] ; then
    456456    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
    462463        return 0
    463464    else
     
    471472
    472473
    473 function setupJavaAt() {
     474setupJavaAt() {
    474475
    475476  # check the second parameter if non-null
    476   if [ -n "$2" ] && [ "$2" = "JRE" ]; then
     477  if [ -n "$2" ] && [ "$2" = "JRE" ] ; then
    477478    export JRE_HOME="$1"
    478479    addtopath PATH "$JRE_HOME/bin"
     
    482483   
    483484    BUNDLED_JRE="`pwd`/packages/jre"   
    484     if [[ "$JRE_HOME" = *"$BUNDLED_JRE"* ]]; then
     485    if [[ "$JRE_HOME" = *"$BUNDLED_JRE"* ]] ; then
    485486    msg="the bundled"
    486487    fi
     
    496497}
    497498
    498 function pauseAndExit(){
     499pauseAndExit(){
    499500 echo -n "Please press any key to continue... "
    500501 read
    501502}
    502503
    503 function isinpath() {
     504isinpath() {
    504505  for file in `echo $1 | sed 's/:/ /g'`; do
    505     if [ "$file" = "$2" ]; then
     506    if [ "$file" = "$2" ] ; then
    506507      echo true
    507508      return
     
    511512}
    512513
    513 function addtopath() {
     514addtopath() {
    514515  eval "PV=\$$1"
    515516  #echo "$1 += $2"
    516   if [ "$PV" = "" ]; then
     517  if [ "x$PV" = "x" ] ; then
    517518    cmd="$1=\"$2\""
    518519  else
     
    525526# Note: use return not exit from a sourced script otherwise it kills the shell
    526527testSource
    527 if [ "$?" = "1" ]; then
     528if [ "$?" = "1" ] ; then
    528529return
    529530fi
    530531
    531532testAlreadySourced
    532 if [ "$?" = "1" ]; then
     533if [ "$?" = "1" ] ; then
    533534return
    534535fi
     
    539540  echo ""
    540541  echo "Sourcing gs2build/setup.bash"
    541   cd gs2build ; source setup.bash ; cd ..
     542  cd gs2build ; . ./setup.bash ; cd ..
    542543fi
    543544
     
    549550        cd $gsdl_ext > /dev/null
    550551        if test -e gs3-setup.sh ; then
    551             source ./gs3-setup.sh
     552            . ./gs3-setup.sh
    552553        elif test -e setup.bash ; then
    553             source ./setup.bash
     554            . ./setup.bash
    554555        fi
    555556        cd ../.. 
     
    563564    echo ""
    564565    echo "Sourcing local/gs3-setup.sh"
    565     cd local ; source gs3-setup.sh ; cd ..
     566    cd local ; . ./gs3-setup.sh ; cd ..
    566567  fi
    567568fi
     
    627628    echo "  - `ant -version`"
    628629  else
    629     # which ant &> /dev/null
     630    # which ant > /dev/null 2>&1
    630631    # Posix friendly way to determine if a program exists:
    631632    #   https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
    632     command -v ant &> /dev/null
     633    command -v ant > /dev/null 2>&1
    633634     
    634635    if [ "$?" = "0" ] ; then
Note: See TracChangeset for help on using the changeset viewer.