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

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

doover: modeled setup of imagemagick, ghostscript and wvware on the code from greenstone2

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 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 echo " - Adjusted PATH"
86
87 #MANPATH
88 addtopath MANPATH "$GSDL3SRCHOME/doc/man"
89 echo " - Adjusted MANPATH"
90
91 #CLASSPATH
92 addtopath CLASSPATH "."
93 addtopath CLASSPATH "$GSDL3HOME/WEB-INF/classes"
94 addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
95 addtopath CLASSPATH "$GSDL3SRCHOME/cp.jar"
96
97 # Tomcat 5 jar files
98 for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
99 addtopath CLASSPATH "$JARFILE"
100 done
101 # Tomcat 6 jar files
102 for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
103 addtopath CLASSPATH "$JARFILE"
104 done
105
106 #shouldn't need these as they will have been copied to their correct locations elsewhere in the greenstone3 installation
107 #for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
108 # addtopath CLASSPATH "$JARFILE"
109 #done
110
111 echo " - Adjusted CLASSPATH"
112
113 #LD_LIBRARY_PATH
114 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
115 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
116 echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
117
118 #ant
119 ANT_VERSION=1.7.1
120 if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
121 ANT_HOME="$GSDL3SRCHOME/packages/ant"
122 export ANT_HOME
123 addtopath PATH "$ANT_HOME/bin"
124 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
125 else
126 # check if ANT_HOME is already set
127 if [ "$ANT_HOME" != "" ]; then
128 echo " - Falling back to using existing ANT_HOME which is set to: $ANT_HOME"
129 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
130 # export ANT_HOME
131 # Add ANT_HOME/bin to PATH if it does not already contain it
132 ANT_BIN=$ANT_HOME/bin
133 if [[ $PATH != *$ANT_BIN* ]]; then
134 addtopath PATH "$ANT_BIN"
135 fi
136 else
137 which ant &> /dev/null
138 if [ "$?" == "0" ]; then
139 echo " - WARNING: Greenstone 'Ant' package missing - falling back to system Ant"
140 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
141 else
142 echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
143 echo " Note that Greenstone requires Ant $ANT_VERSION or greater"
144 fi
145 fi
146 fi
147
148 #ImageMagick
149 if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick" ; then
150 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/bin"
151 MAGICK_HOME="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick"
152 export MAGICK_HOME
153 if test "$GSDLOS" = "linux"; then
154 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
155 elif test "$GSDLOS" = "darwin"; then
156 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/imagemagick/lib"
157 fi
158 echo " - Setup ImageMagick"
159 fi
160
161 #Ghostscript
162 if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript"; then
163 addtopath PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/bin"
164 GS_LIB="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/lib"
165 export GS_LIB
166 GS_FONTPATH="$GSDL3SRCHOME/gs2build/bin/$GSDLOS/ghostscript/share/ghostscript/8.63/Resource/Font"
167 export GS_FONTPATH
168 echo " - Setup GhostScript"
169 fi
170
171 #wvWare
172 if test -d "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv"; then
173 if test "$GSDLOS" = "linux"; then
174 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
175 elif test "$GSDLOS" = "darwin"; then
176 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/gs2build/bin/$GSDLOS/wv/lib"
177 fi
178 echo " - Setup wvWare"
179 fi
180
181}
182
183function checkJava() {
184
185 HINT="`pwd`/packages/jre"
186 if [ $GSDLOS = darwin ]; then
187 HINT=/System/Library/Frameworks/JavaVM.framework/Home
188 fi
189
190 #if search4j is present, use it
191 if [ -x bin/search4j ] ; then
192 FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`"
193 if [ "$?" == "0" ]; then
194 #found a suitible java
195 setupJavaAt "$FOUNDJAVAHOME"
196 else
197 #no suitable java exists
198 echo " - ERROR: Failed to locate java $java_min_version or greater"
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 #otherwise manually try the hint
204 elif [ -d "$HINT" ]; then
205 #found a suitible java
206 setupJavaAt "$HINT"
207
208 #lastly, check if java already setup
209 elif [ "$JAVA_HOME" != "" ] && [ "`which java`" == "$JAVA_HOME/bin/java" ]; then
210 echo " - Using java at $JAVA_HOME"
211 echo " - WARNING: Greenstone has not checked the version number of this java installation"
212 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
213 echo " (SVN users may still use java 1.4)"
214 elif [ "$JRE_HOME" != "" ] && [ "`which java`" == "$JRE_HOME/bin/java" ]; then
215 echo " - Using java at $JRE_HOME"
216 echo " - WARNING: Greenstone has not checked the version number of this java installation"
217 echo " The source distribution of Greenstone3 requires java 1.5 or greater"
218 echo " (SVN users may still use java 1.4)"
219
220 #failing all that, print a warning
221 else
222 #no suitable java exists
223 echo " - ERROR: Failed to locate java"
224 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
225 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
226 fi
227}
228
229function setupJavaAt() {
230 export JAVA_HOME="$1"
231 addtopath PATH "$JAVA_HOME/bin"
232 echo " - Exported JAVA_HOME to $JAVA_HOME"
233}
234
235function pauseAndExit(){
236 echo -n "Please press any key to continue... "
237 read
238}
239
240function isinpath() {
241 for file in `echo $1 | sed 's/:/ /g'`; do
242 if [ "$file" == "$2" ]; then
243 echo true
244 return
245 fi
246 done
247 echo false
248}
249
250function addtopath() {
251 eval "PV=\$$1"
252 #echo "$1 += $2"
253 if [ "$PV" == "" ]; then
254 cmd="$1=\"$2\""
255 else
256 cmd="$1=\"$2:\$$1\""
257 fi
258 eval $cmd
259 eval "export $1"
260}
261
262# Note: use return not exit from a sourced script otherwise it kills the shell
263echo
264testSource
265if [ "$?" == "1" ]; then
266return
267fi
268testAlreadySourced
269if [ "$?" == "1" ]; then
270return
271fi
272setGS3ENV
273checkJava
Note: See TracBrowser for help on using the repository browser.