source: main/trunk/greenstone3/gs3-setup.sh@ 30106

Last change on this file since 30106 was 30106, checked in by ak19, 9 years ago

HINT for search4j adjusted after JRE inclusion on Mac Lion.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
RevLine 
[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]10java_min_version=1.5.0_00
[15131]11
12
[14726]13function 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
46function 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]59function 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
[26795]68 if test "x$GSDLOS" = "x" ; then
69 GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
70 # check for running bash under cygwin
71 if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
72 GSDLOS=windows
73 fi
74 fi
[17442]75 export GSDLOS
76 echo " - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
[8060]77
[17442]78 #change this if external tomcat
[20187]79 TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
[10303]80
[17442]81 ## adjustments to users (existing) environment ##
[15134]82
[17442]83 #PATH
[20077]84 addtopath PATH "$GSDL3SRCHOME/bin/script"
85 addtopath PATH "$GSDL3SRCHOME/bin"
86 echo " - Adjusted PATH"
[6433]87
[20077]88 #MANPATH
89 addtopath MANPATH "$GSDL3SRCHOME/doc/man"
90 echo " - Adjusted MANPATH"
91
[17442]92 #CLASSPATH
[20233]93 addtopath CLASSPATH "."
[20077]94 addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
95 addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
[20211]96 addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
97
[20088]98 # Tomcat 5 jar files
[20187]99 for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
[20077]100 addtopath CLASSPATH "$JARFILE"
101 done
[20088]102 # Tomcat 6 jar files
[20187]103 for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
[20088]104 addtopath CLASSPATH "$JARFILE"
105 done
106
[20211]107 #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
108 #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
109 # addtopath CLASSPATH "$JARFILE"
110 #done
[20219]111
[20077]112 echo " - Adjusted CLASSPATH"
[8060]113
[17442]114 #LD_LIBRARY_PATH
[20077]115 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
116 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
117 echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
[15134]118
[17442]119 #ant
[20252]120 ANT_VERSION=1.7.1
[20077]121 if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
122 ANT_HOME="$GSDL3SRCHOME/packages/ant"
123 export ANT_HOME
124 addtopath PATH "$ANT_HOME/bin"
[20093]125 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
[17442]126 else
[20305]127 which ant &> /dev/null
128 if [ "$?" == "0" ]; then
129 echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
130 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
131 elif [ "ANT_HOME" != "" ]; then
132 addtopath PATH "$ANT_HOME/bin"
133 echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
134 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
135 else
136 echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
137 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
138 fi
[17442]139 fi
[15134]140
[20303]141 #ImageMagick
[25566]142 #if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
143 # addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
144 # MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
145 # export MAGICK_HOME
146 # if test "$GSDLOS" = "linux"; then
147 # addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
148 # elif test "$GSDLOS" = "darwin"; then
149 # addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
150 # fi
151 # echo " - Setup ImageMagick"
152 #fi
[20303]153
154 #Ghostscript
155 if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
156 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
[20305]157 GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
158 export GS_LIB
159 GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
160 export GS_FONTPATH
[20303]161 echo " - Setup GhostScript"
162 fi
163
[25448]164 #wvWare
165 # wvWare's environment is now set up by bin/script/wvware.pl
166 # The wvware.pl script can be called from the cmdline to perform wvware tasks.
167 # GLI calls gsConvert.pl which calls wvware.pl to similarly perform wvware tasks.
168# if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
169# if test "$GSDLOS" = "linux"; then
170# addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
171# elif test "$GSDLOS" = "darwin"; then
172# addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
173# fi
174# echo " - Setup wvWare"
175# fi
[20303]176
[14726]177}
[6433]178
[15131]179function checkJava() {
[15138]180
[30106]181 # we now include a JRE with Mac (Mountain) Lion too, because from Yosemite onwards there's no system Java on Macs
[20059]182 HINT="`pwd`/packages/jre"
[30106]183 if [ "$GSDLOS" = "darwin" ] && [ ! -d "$HINT" ]; then
184 HINT=`/usr/libexec/java_home`
185 # old code used as fallback:
186 if [ ! -d "$HINT" ]; then
187 HINT=/System/Library/Frameworks/JavaVM.framework/Home
188 fi
[20216]189 fi
[20217]190
191 #if search4j is present, use it
192 if [ -x bin/search4j ] ; then
193 FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`"
194 if [ "$?" == "0" ]; then
[30106]195 #found a suitable java
[20217]196 setupJavaAt "$FOUNDJAVAHOME"
197 else
198 #no suitable java exists
199 echo " - ERROR: Failed to locate java $java_min_version or greater"
200 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
201 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
202 fi
203
204 #otherwise manually try the hint
205 elif [ -d "$HINT" ]; then
206 #found a suitible java
207 setupJavaAt "$HINT"
208
209 #lastly, check if java already setup
210 elif [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
211 echo " - Using java at $JAVA_HOME"
[20233]212 echo " - WARNING: Greenstone has not checked the version number of this java installation"
213 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
214 echo " (SVN users may still use java 1.4)"
[20217]215 elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
216 echo " - Using java at $JRE_HOME"
[20233]217 echo " - WARNING: Greenstone has not checked the version number of this java installation"
218 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
219 echo " (SVN users may still use java 1.4)"
220
[20217]221 #failing all that, print a warning
[20077]222 else
[20217]223 #no suitable java exists
224 echo " - ERROR: Failed to locate java"
225 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
226 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
[15131]227 fi
228}
[6433]229
[20217]230function setupJavaAt() {
231 export JAVA_HOME="$1"
232 addtopath PATH "$JAVA_HOME/bin"
233 echo " - Exported JAVA_HOME to $JAVA_HOME"
234}
235
[14726]236function pauseAndExit(){
237 echo -n "Please press any key to continue... "
238 read
239}
[6433]240
[15131]241function isinpath() {
[17442]242 for file in `echo $1 | sed 's/:/ /g'`; do
243 if [ "$file" == "$2" ]; then
244 echo true
245 return
246 fi
247 done
248 echo false
[15131]249}
250
[20077]251function addtopath() {
[20078]252 eval "PV=\$$1"
[20083]253 #echo "$1 += $2"
254 if [ "$PV" == "" ]; then
255 cmd="$1=\"$2\""
256 else
257 cmd="$1=\"$2:\$$1\""
[20077]258 fi
[20083]259 eval $cmd
260 eval "export $1"
[20077]261}
[20078]262
[20189]263# Note: use return not exit from a sourced script otherwise it kills the shell
[15131]264echo
[14726]265testSource
[20189]266if [ "$?" == "1" ]; then
267return
268fi
269testAlreadySourced
270if [ "$?" == "1" ]; then
271return
272fi
[14726]273setGS3ENV
[20982]274
[21320]275if test -e gs2build/setup.bash ; then
276 echo ""
277 echo "Sourcing gs2build/setup.bash"
278 cd gs2build ; source setup.bash ; cd ..
279fi
280
[24335]281
[23894]282if test "x$gsopt_noexts" != "x1" ; then
283 if test -e ext ; then
284 for gsdl_ext in ext/* ; do
285 if [ -d $gsdl_ext ] ; then
286 cd $gsdl_ext > /dev/null
[24335]287 if test -e gs3-setup.sh ; then
288 source ./gs3-setup.sh
289 elif test -e setup.bash ; then
[23894]290 source ./setup.bash
291 fi
292 cd ../..
293 fi
294 done
[20984]295 fi
296fi
297
[20982]298if test -e local ; then
299 if test -e local/gs3-setup.sh ; then
[20984]300 echo ""
[20982]301 echo "Sourcing local/gs3-setup.sh"
302 cd local ; source gs3-setup.sh ; cd ..
303 fi
304fi
305
[20984]306
307checkJava
308echo ""
Note: See TracBrowser for help on using the repository browser.