[6433] | 1 | # if this file is executed, /bin/sh is used, as we don't start with #!
|
---|
| 2 | # this should work under ash, bash, zsh, ksh, sh style shells.
|
---|
| 3 |
|
---|
[15131] | 4 | #the purpose of this file is to check/set up the environment for greenstone3
|
---|
[16213] | 5 | #sorts out:
|
---|
[17442] | 6 | # - gsdl3home
|
---|
| 7 | # - java
|
---|
[14726] | 8 |
|
---|
[16213] | 9 | # java_min_version gets passed to search4j as the minimum java version
|
---|
[20093] | 10 | java_min_version=1.5.0_00
|
---|
[15131] | 11 |
|
---|
| 12 |
|
---|
[14726] | 13 | function testSource(){
|
---|
[15131] | 14 |
|
---|
[14726] | 15 | if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
|
---|
| 16 | # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
|
---|
| 17 | # One exception is zsh has an option to set it temporarily to the script name
|
---|
| 18 | if test -z "$ZSH_NAME" ; then
|
---|
| 19 | # we aren't using zsh
|
---|
| 20 | gsdl_not_sourced=true
|
---|
| 21 | fi
|
---|
[6433] | 22 | fi
|
---|
| 23 |
|
---|
[14726] | 24 | if test -n "$gsdl_not_sourced" ; then
|
---|
[17442] | 25 | echo " Error: Make sure you source this script, not execute it. Eg:"
|
---|
| 26 | echo " $ source gs3-setup.sh"
|
---|
| 27 | echo " or"
|
---|
| 28 | echo " $ . gs3-setup.sh"
|
---|
| 29 | echo " not"
|
---|
| 30 | echo " $ ./gs3-setup.sh"
|
---|
[14726] | 31 | unset gsdl_not_sourced
|
---|
| 32 | exit 1
|
---|
| 33 | fi
|
---|
[6433] | 34 |
|
---|
[14726] | 35 | if test ! -f gs3-setup.sh ; then
|
---|
| 36 | echo "You must source the script from within the Greenstone home directory"
|
---|
[20189] | 37 | return 1
|
---|
[14726] | 38 | fi
|
---|
[20189] | 39 | return 0
|
---|
| 40 | }
|
---|
[15131] | 41 |
|
---|
[20189] | 42 | # if GSDL3SRCHOME is set, then we assume that we have already sourced the
|
---|
| 43 | # script so don't do it again. UNLESS, GSDL3SRCHOME doesn't match the
|
---|
| 44 | # current directory in which case it was a different gs3 installation, so lets
|
---|
| 45 | # do it now.x
|
---|
| 46 | function testAlreadySourced() {
|
---|
| 47 | if [ ! -z "$GSDL3SRCHOME" ]; then
|
---|
| 48 | localgs3sourcehome="`pwd`"
|
---|
| 49 | if [ "$GSDL3SRCHOME" == "$localgs3sourcehome" ]; then
|
---|
[20305] | 50 | echo "Your environment is already set up for Greenstone3"
|
---|
| 51 | return 1
|
---|
[20189] | 52 | fi
|
---|
| 53 | echo "Your environment was set up for Greenstone 3 in $GSDL3SRCHOME."
|
---|
| 54 | echo "Overwriting that set up for the current Greenstone 3 in $localgs3sourcehome"
|
---|
| 55 | fi
|
---|
| 56 | return 0
|
---|
[14726] | 57 | }
|
---|
[6433] | 58 |
|
---|
[15131] | 59 | function setGS3ENV() {
|
---|
[6433] | 60 |
|
---|
[17442] | 61 | echo "Setting up your environment for Greenstone3"
|
---|
| 62 | ## main greenstone environment variables ##
|
---|
[20187] | 63 | GSDL3SRCHOME="`pwd`"
|
---|
| 64 | GSDL3HOME="$GSDL3SRCHOME/web"
|
---|
[17442] | 65 | export GSDL3HOME
|
---|
| 66 | export GSDL3SRCHOME
|
---|
[10645] | 67 |
|
---|
[17442] | 68 | GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
---|
| 69 | # check for running bash under cygwin
|
---|
| 70 | if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
|
---|
| 71 | GSDLOS=windows
|
---|
| 72 | fi
|
---|
| 73 | export GSDLOS
|
---|
| 74 | echo " - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
|
---|
[8060] | 75 |
|
---|
[17442] | 76 | #change this if external tomcat
|
---|
[20187] | 77 | TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
|
---|
[10303] | 78 |
|
---|
[17442] | 79 | ## adjustments to users (existing) environment ##
|
---|
[15134] | 80 |
|
---|
[17442] | 81 | #PATH
|
---|
[20077] | 82 | addtopath PATH "$GSDL3SRCHOME/bin/script"
|
---|
| 83 | addtopath PATH "$GSDL3SRCHOME/bin"
|
---|
| 84 | echo " - Adjusted PATH"
|
---|
[6433] | 85 |
|
---|
[20077] | 86 | #MANPATH
|
---|
| 87 | addtopath MANPATH "$GSDL3SRCHOME/doc/man"
|
---|
| 88 | echo " - Adjusted MANPATH"
|
---|
| 89 |
|
---|
[17442] | 90 | #CLASSPATH
|
---|
[20233] | 91 | addtopath CLASSPATH "."
|
---|
[20077] | 92 | addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
|
---|
| 93 | addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
|
---|
[20211] | 94 | addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
|
---|
| 95 |
|
---|
[20088] | 96 | # Tomcat 5 jar files
|
---|
[20187] | 97 | for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
|
---|
[20077] | 98 | addtopath CLASSPATH "$JARFILE"
|
---|
| 99 | done
|
---|
[20088] | 100 | # Tomcat 6 jar files
|
---|
[20187] | 101 | for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
|
---|
[20088] | 102 | addtopath CLASSPATH "$JARFILE"
|
---|
| 103 | done
|
---|
| 104 |
|
---|
[20211] | 105 | #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
|
---|
| 106 | #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
|
---|
| 107 | # addtopath CLASSPATH "$JARFILE"
|
---|
| 108 | #done
|
---|
[20219] | 109 |
|
---|
[20077] | 110 | echo " - Adjusted CLASSPATH"
|
---|
[8060] | 111 |
|
---|
[17442] | 112 | #LD_LIBRARY_PATH
|
---|
[20077] | 113 | addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
| 114 | addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
|
---|
| 115 | echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
|
---|
[15134] | 116 |
|
---|
[17442] | 117 | #ant
|
---|
[20252] | 118 | ANT_VERSION=1.7.1
|
---|
[20077] | 119 | if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
|
---|
| 120 | ANT_HOME="$GSDL3SRCHOME/packages/ant"
|
---|
| 121 | export ANT_HOME
|
---|
| 122 | addtopath PATH "$ANT_HOME/bin"
|
---|
[20093] | 123 | echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
|
---|
[17442] | 124 | else
|
---|
[20305] | 125 | which ant &> /dev/null
|
---|
| 126 | if [ "$?" == "0" ]; then
|
---|
| 127 | echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
|
---|
| 128 | echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
| 129 | elif [ "ANT_HOME" != "" ]; then
|
---|
| 130 | addtopath PATH "$ANT_HOME/bin"
|
---|
| 131 | echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
|
---|
| 132 | echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
| 133 | else
|
---|
| 134 | echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
|
---|
| 135 | echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
|
---|
| 136 | fi
|
---|
[17442] | 137 | fi
|
---|
[15134] | 138 |
|
---|
[20303] | 139 | #ImageMagick
|
---|
| 140 | if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
|
---|
| 141 | addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
|
---|
| 142 | MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
|
---|
| 143 | export MAGICK_HOME
|
---|
| 144 | if test "$GSDLOS" = "linux"; then
|
---|
| 145 | addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
|
---|
| 146 | elif test "$GSDLOS" = "darwin"; then
|
---|
| 147 | addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
|
---|
| 148 | fi
|
---|
| 149 | echo " - Setup ImageMagick"
|
---|
| 150 | fi
|
---|
| 151 |
|
---|
| 152 | #Ghostscript
|
---|
| 153 | if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
|
---|
| 154 | addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
|
---|
[20305] | 155 | GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
|
---|
| 156 | export GS_LIB
|
---|
| 157 | GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
|
---|
| 158 | export GS_FONTPATH
|
---|
[20303] | 159 | echo " - Setup GhostScript"
|
---|
| 160 | fi
|
---|
| 161 |
|
---|
| 162 | #wvWare
|
---|
| 163 | if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
|
---|
| 164 | if test "$GSDLOS" = "linux"; then
|
---|
| 165 | addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
|
---|
| 166 | elif test "$GSDLOS" = "darwin"; then
|
---|
| 167 | addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
|
---|
| 168 | fi
|
---|
| 169 | echo " - Setup wvWare"
|
---|
| 170 | fi
|
---|
| 171 |
|
---|
[14726] | 172 | }
|
---|
[6433] | 173 |
|
---|
[15131] | 174 | function checkJava() {
|
---|
[15138] | 175 |
|
---|
[20059] | 176 | HINT="`pwd`/packages/jre"
|
---|
[20216] | 177 | if [ $GSDLOS = darwin ]; then
|
---|
| 178 | HINT=/System/Library/Frameworks/JavaVM.framework/Home
|
---|
| 179 | fi
|
---|
[20217] | 180 |
|
---|
| 181 | #if search4j is present, use it
|
---|
| 182 | if [ -x bin/search4j ] ; then
|
---|
| 183 | FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`"
|
---|
| 184 | if [ "$?" == "0" ]; then
|
---|
| 185 | #found a suitible java
|
---|
| 186 | setupJavaAt "$FOUNDJAVAHOME"
|
---|
| 187 | else
|
---|
| 188 | #no suitable java exists
|
---|
| 189 | echo " - ERROR: Failed to locate java $java_min_version or greater"
|
---|
| 190 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
| 191 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
| 192 | fi
|
---|
| 193 |
|
---|
| 194 | #otherwise manually try the hint
|
---|
| 195 | elif [ -d "$HINT" ]; then
|
---|
| 196 | #found a suitible java
|
---|
| 197 | setupJavaAt "$HINT"
|
---|
| 198 |
|
---|
| 199 | #lastly, check if java already setup
|
---|
| 200 | elif [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
|
---|
| 201 | echo " - Using java at $JAVA_HOME"
|
---|
[20233] | 202 | echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
| 203 | echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
| 204 | echo " (SVN users may still use java 1.4)"
|
---|
[20217] | 205 | elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
|
---|
| 206 | echo " - Using java at $JRE_HOME"
|
---|
[20233] | 207 | echo " - WARNING: Greenstone has not checked the version number of this java installation"
|
---|
| 208 | echo " The source distribution of Greenstone3 requires java 1.5 or greater"
|
---|
| 209 | echo " (SVN users may still use java 1.4)"
|
---|
| 210 |
|
---|
[20217] | 211 | #failing all that, print a warning
|
---|
[20077] | 212 | else
|
---|
[20217] | 213 | #no suitable java exists
|
---|
| 214 | echo " - ERROR: Failed to locate java"
|
---|
| 215 | echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
|
---|
| 216 | echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
|
---|
[15131] | 217 | fi
|
---|
| 218 | }
|
---|
[6433] | 219 |
|
---|
[20217] | 220 | function setupJavaAt() {
|
---|
| 221 | export JAVA_HOME="$1"
|
---|
| 222 | addtopath PATH "$JAVA_HOME/bin"
|
---|
| 223 | echo " - Exported JAVA_HOME to $JAVA_HOME"
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[14726] | 226 | function pauseAndExit(){
|
---|
| 227 | echo -n "Please press any key to continue... "
|
---|
| 228 | read
|
---|
| 229 | }
|
---|
[6433] | 230 |
|
---|
[15131] | 231 | function isinpath() {
|
---|
[17442] | 232 | for file in `echo $1 | sed 's/:/ /g'`; do
|
---|
| 233 | if [ "$file" == "$2" ]; then
|
---|
| 234 | echo true
|
---|
| 235 | return
|
---|
| 236 | fi
|
---|
| 237 | done
|
---|
| 238 | echo false
|
---|
[15131] | 239 | }
|
---|
| 240 |
|
---|
[20077] | 241 | function addtopath() {
|
---|
[20078] | 242 | eval "PV=\$$1"
|
---|
[20083] | 243 | #echo "$1 += $2"
|
---|
| 244 | if [ "$PV" == "" ]; then
|
---|
| 245 | cmd="$1=\"$2\""
|
---|
| 246 | else
|
---|
| 247 | cmd="$1=\"$2:\$$1\""
|
---|
[20077] | 248 | fi
|
---|
[20083] | 249 | eval $cmd
|
---|
| 250 | eval "export $1"
|
---|
[20077] | 251 | }
|
---|
[20078] | 252 |
|
---|
[20189] | 253 | # Note: use return not exit from a sourced script otherwise it kills the shell
|
---|
[15131] | 254 | echo
|
---|
[14726] | 255 | testSource
|
---|
[20189] | 256 | if [ "$?" == "1" ]; then
|
---|
| 257 | return
|
---|
| 258 | fi
|
---|
| 259 | testAlreadySourced
|
---|
| 260 | if [ "$?" == "1" ]; then
|
---|
| 261 | return
|
---|
| 262 | fi
|
---|
[14726] | 263 | setGS3ENV
|
---|
[20982] | 264 |
|
---|
[21320] | 265 | if test -e gs2build/setup.bash ; then
|
---|
| 266 | echo ""
|
---|
| 267 | echo "Sourcing gs2build/setup.bash"
|
---|
| 268 | cd gs2build ; source setup.bash ; cd ..
|
---|
| 269 | fi
|
---|
| 270 |
|
---|
[23894] | 271 | if test "x$gsopt_noexts" != "x1" ; then
|
---|
| 272 | if test -e ext ; then
|
---|
| 273 | for gsdl_ext in ext/* ; do
|
---|
| 274 | if [ -d $gsdl_ext ] ; then
|
---|
| 275 | cd $gsdl_ext > /dev/null
|
---|
| 276 | if test -e setup.bash ; then
|
---|
| 277 | source ./setup.bash
|
---|
| 278 | fi
|
---|
| 279 | cd ../..
|
---|
| 280 | fi
|
---|
| 281 | done
|
---|
[20984] | 282 | fi
|
---|
| 283 | fi
|
---|
| 284 |
|
---|
[20982] | 285 | if test -e local ; then
|
---|
| 286 | if test -e local/gs3-setup.sh ; then
|
---|
[20984] | 287 | echo ""
|
---|
[20982] | 288 | echo "Sourcing local/gs3-setup.sh"
|
---|
| 289 | cd local ; source gs3-setup.sh ; cd ..
|
---|
| 290 | fi
|
---|
| 291 |
|
---|
[21320] | 292 | # Consider moving these into the local/gs3-setup.sh file
|
---|
| 293 |
|
---|
[20982] | 294 | PATH=$GSDL3SRCHOME/local/bin:$PATH
|
---|
| 295 | export PATH
|
---|
| 296 | LD_LIBRARY_PATH=$GSDL3SRCHOME/local/lib:$LD_LIBRARY_PATH
|
---|
| 297 | export LD_LIBRARY_PATH
|
---|
| 298 | DYLD_LIBRARY_PATH=$GSDL3SRCHOME/local/lib:$DYLD_LIBRARY_PATH
|
---|
| 299 | export DYLD_LIBRARY_PATH
|
---|
| 300 | fi
|
---|
| 301 |
|
---|
[20984] | 302 |
|
---|
| 303 | checkJava
|
---|
| 304 | echo ""
|
---|