Changeset 15131


Ignore:
Timestamp:
2008-03-26T15:01:32+13:00 (14 years ago)
Author:
oranfry
Message:

modified these scripts so they don't polute the user's environment so much, to be more upfront about what their doing, and to make use of the search4j tool instead of searching and checking java with bash code

Location:
greenstone3/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/gs3-server.sh

    r14727 r15131  
    11#!/bin/sh
    22serverlang=en
     3
     4java_min_version=1.4.0_00
    35
    46echo "Greenstone 3 Server"
     
    2426fi
    2527
     28# Setup Greenstone3, unless it has already been done
    2629if [ -z "$GSDL3SRCHOME" ]; then
    27   # Setup Greenstone3, unless it has already been done
    2830  pushd $gsdl3path > /dev/null
    2931  source gs3-setup.sh
     
    3335
    3436# JRE_HOME or JAVA_HOME must be set correctly to run this program
    35 if [ -n "$RUNJAVA" ]; then
    36   "$RUNJAVA" -cp $CLASSPATH org.greenstone.server.Server $GSDL3SRCHOME
    37 fi
     37`search4j -m $java_min_version -e` org.greenstone.server.Server $GSDL3SRCHOME
    3838
  • greenstone3/trunk/gs3-setup.sh

    r14726 r15131  
    11# if this file is executed, /bin/sh is used, as we don't start with #!
    22# this should work under ash, bash, zsh, ksh, sh style shells.
    3 # make sure we are sourced, and not run
    43
    5 export RUNJAVA=
    6 JRE_HOME=
    7 JAVA_HOME=
    8 CLASSPATH=$CLASSPATH
     4#the purpose of this file is to check/set up the environment for greenstone3
     5#sorts out
     6#   - gsdl3home
     7#   - java
     8
     9java_min_version=1.4.0_00
     10
    911
    1012function testSource(){
     13
    1114  if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
    1215  # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
     
    2225     echo "     $ source gs3-setup.sh"
    2326     echo " or"
    24      echo "     $ . ./gs3-setup.sh"
     27     echo "     $ . gs3-setup.sh"
    2528     echo " not"
    2629     echo "     $ ./gs3-setup.sh"
     
    3336    exit 1
    3437  fi
     38
    3539}
    3640
    37 function setGS3ENV(){
    38    GSDL3SRCHOME=`pwd`
    39    GSDL3HOME=$GSDL3SRCHOME/web
    40    export GSDL3HOME
    41    export GSDL3SRCHOME
    42    GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
    43     # check for running bash under cygwin
    44     if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
    45         GSDLOS=windows
    46     fi
    47     export GSDLOS
     41function setGS3ENV() {
    4842
    49     #change this if external tomcat
    50     TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
     43    echo "Setting up your environment for Greenstone3"
     44    ## main greenstone environment variables ##
     45    GSDL3SRCHOME=`pwd`
     46    GSDL3HOME=$GSDL3SRCHOME/web
     47    export GSDL3HOME
     48    export GSDL3SRCHOME
    5149
    52     PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
    53     export PATH
    54     MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
    55     export MANPATH
     50    GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
     51    # check for running bash under cygwin
     52    if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
     53        GSDLOS=windows
     54    fi
     55    export GSDLOS
     56    echo "  - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
    5657
    57     CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
    58      for JARFILE in $GSDL3SRCHOME/*.jar; do
    59        CLASSPATH=$CLASSPATH:$JARFILE
    60      done
    61      for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
    62         CLASSPATH=$CLASSPATH:$JARFILE
    63      done
    64      for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
    65         CLASSPATH=$CLASSPATH:$JARFILE
    66      done
    67      for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
    68         CLASSPATH=$CLASSPATH:$JARFILE
    69      done   
    70      for JARFILE in $GSDL3SRCHOME/build/*.jar; do
    71        CLASSPATH=$CLASSPATH:$JARFILE
    72      done
    73      export CLASSPATH
    74      LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
    75      export LD_LIBRARY_PATH
    76       ## for mac
    77      DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
    78      export DYLD_LIBRARY_PATH
     58    #change this if external tomcat
     59    TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
     60
     61
     62    ## adjustments to users (existing) environment ##
     63    if [ `isinpath "$PATH" "$GSDL3SRCHOME/bin"` == "false" ]; then
     64        PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
     65        export PATH
     66        MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
     67        export MANPATH
     68        echo "  - Adjusted PATH"
     69    else
     70        echo "  - PATH already correct"
     71    fi
     72
     73    if [ `isinpath "$CLASSPATH" "$GSDL3HOME/WEB-INF/classes"` == "false" ]; then
     74        CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
     75        for JARFILE in $GSDL3SRCHOME/*.jar; do
     76            CLASSPATH=$CLASSPATH:$JARFILE
     77        done
     78        for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
     79            CLASSPATH=$CLASSPATH:$JARFILE
     80        done
     81        for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
     82            CLASSPATH=$CLASSPATH:$JARFILE
     83        done
     84        for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
     85            CLASSPATH=$CLASSPATH:$JARFILE
     86        done   
     87        for JARFILE in $GSDL3SRCHOME/build/*.jar; do
     88            CLASSPATH=$CLASSPATH:$JARFILE
     89        done
     90        export CLASSPATH
     91        echo "  - Adjusted CLASSPATH"
     92    else
     93        echo "  - CLASSPATH already correct"
     94    fi
     95
     96    if [ `isinpath "$LD_LIBRARY_PATH" "$GSDL3SRCHOME/lib/jni"` == "false" ]; then
     97        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
     98        export LD_LIBRARY_PATH
     99        DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
     100        export DYLD_LIBRARY_PATH
     101        echo "  - Adjusted LD_LIBRARY_PATH"
     102    else
     103        echo "  - LD_LIBRARY_PATH already correct"
     104    fi
     105    echo
    79106}
    80107
    81 function setJAVAHOME(){
    82     # see if we can find java
    83     java="java"
    84     jfound=1
    85     jok=1
    86     # if JREHOME, JRE_HOME is set, we'll use it to determine where java lives
    87     if [ "$JRE_HOME" != "" ]; then
    88        java="$JRE_HOME/bin/java"
    89        export JRE_HOME=$JRE_HOME
    90     elif [ "$JREHOME" != "" ]; then
    91        java="$JREHOME/bin/java"
    92        export JRE_HOME=$JREHOME
    93      # JAVAHOME or JAVA_HOME is set we'll use it to determine where java lives, otherwise
    94      #  we just hope it's on the search path
    95      elif [ "$JAVA_HOME" != "" ] ; then
    96        java="$JAVA_HOME/bin/java"
    97        export JAVA_HOME=$JAVA_HOME
    98      elif [ "$JAVAHOME" != "" ] ; then
    99        java="$JAVAHOME/bin/java"
    100        export JAVA_HOME=$JAVAHOME
    101     else
    102         java=`which java 2> /dev/null`
    103         if [ ! -x "$java" ]; then
    104         echo "Failed to locate Java. You must install a java runtime environment"
    105         echo "(version 1.4 or greater) before installing Greenstone 3."
    106             pauseAndExit
    107         else
    108       export JRE_HOME=`echo $java | sed -n 's/[\\\/]bin[\\\/]java$//p'`
    109         fi
    110    fi
    111    checkJAVAHOME
     108function checkJava() {
     109    echo "Checking Java"
     110  #check java
     111  bin/search4j -m $java_min_version &> /dev/null
     112  if [ "$?" != "0" ]; then
     113    echo "  - Failed to locate java ($java_min_version or greater)"
     114        bin/search4j &> /dev/null
     115        if [ "$?" == "0" ]; then echo "  (It looks like you hava java but it's too old)"; fi
     116        echo "  - Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
     117    echo "    And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
     118    else
     119        echo "  - Found java at: `bin/search4j -m $java_min_version`"
     120  fi
     121    echo
    112122}
    113 
    114 function checkJAVAHOME(){
    115 # Make sure prerequisite environment variables are set
    116   if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
    117     echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
    118     echo "At least one of these environment variable is needed to run Greenstone3" 
    119     pauseAndExit
    120   else # check JRE_HOME
    121       if [ -n "$JRE_HOME" ]; then
    122          if [ ! -x "$JRE_HOME"/bin/java ]; then
    123         echo "JRE_HOME: $JRE_HOME"
    124         echo "Couldn't find $JRE_HOME/bin/java"
    125             echo "The JRE_HOME environment variable is not defined correctly"
    126             echo "This environment variable is needed to run this program"
    127         pauseAndExit
    128          else
    129        export RUNJAVA="$JRE_HOME"/bin/java
    130            checkVersion
    131          fi     
    132       else
    133           # check JAVA_HOME if JRE_HOME is not set   
    134           if [ -n "$JAVA_HOME" ]; then
    135               if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
    136         echo "JAVA_HOME: $JAVA_HOME" 
    137                 echo "Couldn't find $JAVA_HOME/bin/java or $JAVA_HOME/bin/javac"
    138                 echo "The JAVA_HOME environment variable is not defined correctly"
    139                 echo "This environment variable is needed to run this program"
    140                 echo "NB: JAVA_HOME should point to a JDK not a JRE"
    141         pauseAndExit
    142           else
    143                export RUNJAVA="$JAVA_HOME"/bin/java
    144                checkVersion
    145               fi
    146            fi
    147         fi
    148   fi
    149 }
    150 
    151 function checkVersion(){
    152 if [ $jfound -eq 1 ]; then
    153     javaversion=`$RUNJAVA -version 2>&1 | sed -n 's/^java version \"\(.*\)\"/\1/p'`
    154     jvmajor=`echo $javaversion | sed -n 's/^\([0-9]*\).*$/\1/p'`
    155     jvminor=`echo $javaversion | sed -n 's/^[0-9]*\.\([0-9]*\).*$/\1/p'`
    156    
    157     if [ $jvmajor -lt 1 ] ; then
    158     jok=0
    159     fi
    160     if [ $jvmajor -eq 1 ] && [ $jvminor -lt 4 ] ; then
    161     jok=0
    162     fi
    163 fi
    164 
    165 if [ $jfound -eq 1 ] && [ $jok -eq 0 ] ; then
    166     echo "The version of the java runtime environment you have installed is too"
    167     echo "old to run Greenstone 3. Please install a new version of the JRE (version"
    168     echo "1.4 or newer) and rerun this installation."
    169     export RUNJAVA=
    170     pauseAndExit
    171 else
    172     if [ -n "$JRE_HOME" ]; then
    173      echo "JRE_HOME: $JRE_HOME"
    174      export PATH="$JRE_HOME"\bin:$PATH
    175     fi
    176     if [ -n "$JAVA_HOME" ]; then
    177      echo "JAVA_HOME: $JAVA_HOME"
    178      export PATH="$JAVA_HOME"\bin:$PATH
    179     fi
    180     echo "Your environment has successfully been set up to run Greenstone3"
    181 fi
    182 }
    183 
    184123
    185124function pauseAndExit(){
     
    188127}
    189128
     129function isinpath() {
     130    for file in `echo $1 | sed 's/:/ /g'`; do
     131        if [ "$file" == "$2" ]; then
     132            echo true
     133            return
     134        fi
     135    done
     136    echo false
     137}
     138
     139echo
    190140testSource
    191141setGS3ENV
    192 setJAVAHOME
    193 
    194 
     142checkJava
Note: See TracChangeset for help on using the changeset viewer.