source: greenstone3/trunk/gs3-setup.sh@ 20301

Last change on this file since 20301 was 20301, checked in by oranfry, 15 years ago

added some more directories to DYLD_ and LD_LIBRARY_PATH so bundled imagemagick and ghostscript are findable by whoever needs them (gli, build system etc)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
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
4#the purpose of this file is to check/set up the environment for greenstone3
5#sorts out:
6# - gsdl3home
7# - java
8
9# java_min_version gets passed to search4j as the minimum java version
10java_min_version=1.5.0_00
11
12
13function testSource(){
14
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
22 fi
23
24 if test -n "$gsdl_not_sourced" ; then
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"
31 unset gsdl_not_sourced
32 exit 1
33 fi
34
35 if test ! -f gs3-setup.sh ; then
36 echo "You must source the script from within the Greenstone home directory"
37 return 1
38 fi
39 return 0
40}
41
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
50 echo "Your environment is already set up for Greenstone3"
51 return 1
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
57}
58
59function setGS3ENV() {
60
61 echo "Setting up your environment for Greenstone3"
62 ## main greenstone environment variables ##
63 GSDL3SRCHOME="`pwd`"
64 GSDL3HOME="$GSDL3SRCHOME/web"
65 export GSDL3HOME
66 export GSDL3SRCHOME
67
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"
75
76 #change this if external tomcat
77 TOMCAT_HOME="$GSDL3SRCHOME/packages/tomcat"
78
79
80 ## adjustments to users (existing) environment ##
81
82 #PATH
83 addtopath PATH "$GSDL3SRCHOME/bin/script"
84 addtopath PATH "$GSDL3SRCHOME/bin"
85 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/linux/imagemagick/bin"
86 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/darwin/imagemagick/bin"
87 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/linux/ghostscript/bin"
88 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/darwin/ghostscript/bin"
89 echo " - Adjusted PATH"
90
91 #MANPATH
92 addtopath MANPATH "$GSDL3SRCHOME/doc/man"
93 echo " - Adjusted MANPATH"
94
95 #CLASSPATH
96 addtopath CLASSPATH "."
97 addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
98 addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
99 addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
100
101 # Tomcat 5 jar files
102 for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
103 addtopath CLASSPATH "$JARFILE"
104 done
105 # Tomcat 6 jar files
106 for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
107 addtopath CLASSPATH "$JARFILE"
108 done
109
110 #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
111 #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
112 # addtopath CLASSPATH "$JARFILE"
113 #done
114
115 echo " - Adjusted CLASSPATH"
116
117 #LD_LIBRARY_PATH
118 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
119 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
120 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/linux/imagemagick/lib"
121 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/darwin/imagemagick/lib"
122 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/linux/ghostscript/lib"
123 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/darwin/ghostscript/lib"
124 echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
125
126 #ant
127 ANT_VERSION=1.7.1
128 if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
129 ANT_HOME="$GSDL3SRCHOME/packages/ant"
130 export ANT_HOME
131 addtopath PATH "$ANT_HOME/bin"
132 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
133 else
134 # check if ANT_HOME is already set
135 if [ "$ANT_HOME" != "" ]; then
136 echo " - Falling back to using existing ANT_HOME which is set to: $ANT_HOME"
137 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
138 # export ANT_HOME
139 # Add ANT_HOME/bin to PATH if it does not already contain it
140 ANT_BIN=$ANT_HOME/bin
141 if [[ $PATH != *$ANT_BIN* ]]; then
142 addtopath PATH "$ANT_BIN"
143 fi
144 else
145 which ant &> /dev/null
146 if [ "$?" == "0" ]; then
147 echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
148 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
149 else
150 echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
151 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
152 fi
153 fi
154 fi
155
156}
157
158function checkJava() {
159
160 HINT="`pwd`/packages/jre"
161 if [ $GSDLOS = darwin ]; then
162 HINT=/System/Library/Frameworks/JavaVM.framework/Home
163 fi
164
165 #if search4j is present, use it
166 if [ -x bin/search4j ] ; then
167 FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`"
168 if [ "$?" == "0" ]; then
169 #found a suitible java
170 setupJavaAt "$FOUNDJAVAHOME"
171 else
172 #no suitable java exists
173 echo " - ERROR: Failed to locate java $java_min_version or greater"
174 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
175 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
176 fi
177
178 #otherwise manually try the hint
179 elif [ -d "$HINT" ]; then
180 #found a suitible java
181 setupJavaAt "$HINT"
182
183 #lastly, check if java already setup
184 elif [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
185 echo " - Using java at $JAVA_HOME"
186 echo " - WARNING: Greenstone has not checked the version number of this java installation"
187 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
188 echo " (SVN users may still use java 1.4)"
189 elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
190 echo " - Using java at $JRE_HOME"
191 echo " - WARNING: Greenstone has not checked the version number of this java installation"
192 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
193 echo " (SVN users may still use java 1.4)"
194
195 #failing all that, print a warning
196 else
197 #no suitable java exists
198 echo " - ERROR: Failed to locate java"
199 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
200 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
201 fi
202}
203
204function setupJavaAt() {
205 export JAVA_HOME="$1"
206 addtopath PATH "$JAVA_HOME/bin"
207 echo " - Exported JAVA_HOME to $JAVA_HOME"
208}
209
210function pauseAndExit(){
211 echo -n "Please press any key to continue... "
212 read
213}
214
215function isinpath() {
216 for file in `echo $1 | sed 's/:/ /g'`; do
217 if [ "$file" == "$2" ]; then
218 echo true
219 return
220 fi
221 done
222 echo false
223}
224
225function addtopath() {
226 eval "PV=\$$1"
227 #echo "$1 += $2"
228 if [ "$PV" == "" ]; then
229 cmd="$1=\"$2\""
230 else
231 cmd="$1=\"$2:\$$1\""
232 fi
233 eval $cmd
234 eval "export $1"
235}
236
237# Note: use return not exit from a sourced script otherwise it kills the shell
238echo
239testSource
240if [ "$?" == "1" ]; then
241return
242fi
243testAlreadySourced
244if [ "$?" == "1" ]; then
245return
246fi
247setGS3ENV
248checkJava
Note: See TracBrowser for help on using the repository browser.