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

Last change on this file since 20189 was 20189, checked in by kjdon, 13 years ago

added a test for setup already sourced, and don't run again if it was the same greenstone. if it has been sourced for a differnet greenstone then print a message and carry on. exit changed to return otherwise it kills the shell in a sourced script

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 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 "$GSDL3HOME/WEB-INF/classes"
93 addtopath CLASSPATH "$GSDL3SRCHOME/resources/java"
94 for JARFILE in "$GSDL3SRCHOME"/*.jar; do
95 addtopath CLASSPATH "$JARFILE"
96 done
97 for JARFILE in "$GSDL3SRCHOME"/lib/jni/*.jar; do
98 addtopath CLASSPATH "$JARFILE"
99 done
100 for JARFILE in "$GSDL3SRCHOME"/lib/java/*.jar; do
101 addtopath CLASSPATH "$JARFILE"
102 done
103 for JARFILE in "$GSDL3HOME"/WEB-INF/lib/*.jar; do
104 addtopath CLASSPATH "$JARFILE"
105 done
106 # Tomcat 5 jar files
107 for JARFILE in "$TOMCAT_HOME"/common/endorsed/*.jar; do
108 addtopath CLASSPATH "$JARFILE"
109 done
110 # Tomcat 6 jar files
111 for JARFILE in "$TOMCAT_HOME"/lib/*.jar; do
112 addtopath CLASSPATH "$JARFILE"
113 done
114
115 for JARFILE in "$GSDL3SRCHOME"/build/*.jar; do
116 addtopath CLASSPATH "$JARFILE"
117 done
118 echo " - Adjusted CLASSPATH"
119
120 #LD_LIBRARY_PATH
121 addtopath LD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
122 addtopath DYLD_LIBRARY_PATH "$GSDL3SRCHOME/lib/jni"
123 echo " - Adjusted LD_LIBRARY_PATH and DYLD_LIBRARY_PATH"
124
125 #ant
126 if [ -x "$GSDL3SRCHOME/packages/ant/bin/ant" ]; then
127 ANT_HOME="$GSDL3SRCHOME/packages/ant"
128 export ANT_HOME
129 addtopath PATH "$ANT_HOME/bin"
130 echo " - Setup Greenstone ant ($GSDL3SRCHOME/packages/ant)"
131 else
132 which ant &> /dev/null
133 if [ "$?" == "0" ]; then
134 echo " - Greenstone 'Ant' package missing - falling back to system Ant"
135 else
136 echo " - ERROR: Greenstone 'Ant' package missing - please install Ant yourself"
137 fi
138 echo " (Greenstone requires Ant 1.7.1 or greater)"
139 fi
140
141}
142
143function checkJava() {
144
145 HINT="`pwd`/packages/jre"
146 FOUNDJAVAHOME="`bin/search4j -p \"$HINT\" -m $java_min_version`"
147 if [ "$?" == "0" ]; then
148 #bundled java exists, set up
149 export JAVA_HOME="$FOUNDJAVAHOME"
150 addtopath PATH "$JAVA_HOME/bin"
151 echo " - Exported JAVA_HOME to $FOUNDJAVAHOME"
152 else
153 #no suitable java exists
154 echo " ERROR: Failed to locate java $java_min_version or greater"
155 bin/search4j &> /dev/null;
156 if [ "$?" == "0" ]; then echo " It looks like you hava java but it's too old"; fi
157 echo " Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
158 echo " And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
159 fi
160}
161
162function pauseAndExit(){
163 echo -n "Please press any key to continue... "
164 read
165}
166
167function isinpath() {
168 for file in `echo $1 | sed 's/:/ /g'`; do
169 if [ "$file" == "$2" ]; then
170 echo true
171 return
172 fi
173 done
174 echo false
175}
176
177function addtopath() {
178 eval "PV=\$$1"
179 #echo "$1 += $2"
180 if [ "$PV" == "" ]; then
181 cmd="$1=\"$2\""
182 else
183 cmd="$1=\"$2:\$$1\""
184 fi
185 eval $cmd
186 eval "export $1"
187}
188
189# Note: use return not exit from a sourced script otherwise it kills the shell
190echo
191testSource
192if [ "$?" == "1" ]; then
193return
194fi
195testAlreadySourced
196if [ "$?" == "1" ]; then
197return
198fi
199setGS3ENV
200checkJava
Note: See TracBrowser for help on using the repository browser.