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

Last change on this file since 15138 was 15138, checked in by oranfry, 16 years ago

if during gs3-setup no (appropriate) java is found except the bundled one, export JAVA_HOME to point to the bundled one

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 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
9java_min_version=1.5.0_00
10
11
12function testSource(){
13
14 if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
15 # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
16 # One exception is zsh has an option to set it temporarily to the script name
17 if test -z "$ZSH_NAME" ; then
18 # we aren't using zsh
19 gsdl_not_sourced=true
20 fi
21 fi
22
23 if test -n "$gsdl_not_sourced" ; then
24 echo " Error: Make sure you source this script, not execute it. Eg:"
25 echo " $ source gs3-setup.sh"
26 echo " or"
27 echo " $ . gs3-setup.sh"
28 echo " not"
29 echo " $ ./gs3-setup.sh"
30 unset gsdl_not_sourced
31 exit 1
32 fi
33
34 if test ! -f gs3-setup.sh ; then
35 echo "You must source the script from within the Greenstone home directory"
36 exit 1
37 fi
38
39}
40
41function setGS3ENV() {
42
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
49
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"
57
58 #change this if external tomcat
59 TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
60
61
62 ## adjustments to users (existing) environment ##
63
64 #PATH
65 if [ `isinpath "$PATH" "$GSDL3SRCHOME/bin"` == "false" ]; then
66 PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
67 export PATH
68 MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
69 export MANPATH
70 echo " - Adjusted PATH"
71 else
72 echo " - PATH already correct"
73 fi
74
75 #CLASSPATH
76 if [ `isinpath "$CLASSPATH" "$GSDL3HOME/WEB-INF/classes"` == "false" ]; then
77 CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
78 for JARFILE in $GSDL3SRCHOME/*.jar; do
79 CLASSPATH=$CLASSPATH:$JARFILE
80 done
81 for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
82 CLASSPATH=$CLASSPATH:$JARFILE
83 done
84 for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
85 CLASSPATH=$CLASSPATH:$JARFILE
86 done
87 for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
88 CLASSPATH=$CLASSPATH:$JARFILE
89 done
90 for JARFILE in $GSDL3SRCHOME/build/*.jar; do
91 CLASSPATH=$CLASSPATH:$JARFILE
92 done
93 export CLASSPATH
94 echo " - Adjusted CLASSPATH"
95 else
96 echo " - CLASSPATH already correct"
97 fi
98
99 #LD_LIBRARY_PATH
100 if [ `isinpath "$LD_LIBRARY_PATH" "$GSDL3SRCHOME/lib/jni"` == "false" ]; then
101 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
102 export LD_LIBRARY_PATH
103 DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
104 export DYLD_LIBRARY_PATH
105 echo " - Adjusted LD_LIBRARY_PATH"
106 else
107 echo " - LD_LIBRARY_PATH already correct"
108 fi
109
110 #ant
111 which ant &> /dev/null
112 if [ "$?" != "0" ]; then
113 ANT_HOME=$GSDL3SRCHOME/packages/ant
114 PATH=$ANT_HOME/bin:$PATH
115 echo " - Setup ant"
116 else
117 echo " - Ant already setup"
118 fi
119
120 echo
121}
122
123function checkJava() {
124 echo "Checking Java"
125
126 bin/search4j -m $java_min_version &> /dev/null
127 if [ "$?" != "0" ]; then
128
129 #java is not set up already
130 bin/search4j -m $java_min_version -h jre &> /dev/null
131 if [ "$?" == "0" ]; then
132 #bundled java exists, set up
133 export JAVA_HOME=`pwd`/jre
134 echo " - Exported JAVA_HOME to point to bundled java"
135 else
136 #no java exists
137 echo " - Failed to locate java ($java_min_version or greater)"
138 bin/search4j &> /dev/null; if [ "$?" == "0" ]; then echo " (It looks like you hava java but it's too old)"; fi
139 echo " - Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
140 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
141 fi
142
143 else
144
145 #java is already set up
146 echo " - Found java at: `bin/search4j -m $java_min_version`"
147
148 fi
149 echo
150}
151
152function pauseAndExit(){
153 echo -n "Please press any key to continue... "
154 read
155}
156
157function isinpath() {
158 for file in `echo $1 | sed 's/:/ /g'`; do
159 if [ "$file" == "$2" ]; then
160 echo true
161 return
162 fi
163 done
164 echo false
165}
166
167echo
168testSource
169setGS3ENV
170checkJava
Note: See TracBrowser for help on using the repository browser.