-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·305 lines (267 loc) · 6.66 KB
/
bootstrap
File metadata and controls
executable file
·305 lines (267 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/bin/sh
#
# Installation bootstrap script.
#
# Arguments:
#
# runtime-dir
# optional path defining top-of-release
#
# The top-of-release path will be set to the output of /bin/pwd;
# it may be specified if (due to automounters, for instance) /bin/pwd
# returns an unacceptable form of the path.
#
fail () {
echo $1 1>&2
exit 1
}
wrap_perl () {
src=$1
dst=$2
cat > $dst <<EOF
#!/bin/sh
export KB_TOP=$top_dir
export KB_RUNTIME=$rt_dir
export KB_PERL_PATH=$perl_lib
export KB_PYTHON_PATH=$python_lib
export KB_R_PATH=$rscript_lib
$rt_dir/bin/perl $top_dir/$src "\$@"
EOF
chmod +x $dst
}
wrap_sh () {
src=$1
dst=$2
cat > $dst <<EOF
#!/bin/sh
export KB_TOP=$top_dir
export KB_RUNTIME=$rt_dir
export KB_PERL_PATH=$perl_lib
export KB_PYTHON_PATH=$python_lib
export KB_R_PATH=$rscript_lib
bash $top_dir/$src "\$@"
EOF
chmod +x $dst
}
if [ $# -lt 1 ] ; then
if [ ! -L runtime ] ; then
fail "Usage: $0 runtime-dir [top-dir]"
fi
rt_dir=`readlink runtime`
top_dir=`pwd`
else
rt_dir=$1
top_dir=$2
fi
if [ "$top_dir" = "" ] ; then
top_dir=`pwd`
fi
if [ ! -d $rt_dir ] ; then
fail "Runtime directory $rt_dir does not exist"
fi
if [ ! -x $rt_dir/bin/perl ] ; then
fail "Runtime directory $rt_dir does not contain an executable perl"
fi
if [ -d $top_dir/runtime ] ; then
t=`readlink $top_dir/runtime`
if [ "$t" != "$rt_dir" ] ; then
fail "Runtime already configured; remove $top_dir/runtime if you wish to re-bootstrap."
fi
fi
#if [ ! -x $rt_dir/java/bin/javac ] ; then
# fail "Runtime directory $rt_dir does not contain an executable javac"
#fi
#if [ ! -x $rt_dir/glassfish3/bin/asadmin ] ; then
# fail "Runtime directory $rt_dir does not contain an executable asadmin"
#fi
#
# Check for the existence of our dependencies.
#
missing_deps=""
for moddir in modules/* ; do
if [ -f $moddir/DEPENDENCIES ] ; then
mod=`basename $moddir`
for dep in `cat $moddir/DEPENDENCIES`; do
if [ ! -d modules/$dep ] ; then
missing_deps="$missing_deps $mod:$dep"
fi
done
fi
done
if [ "$missing_deps" != "" ] ; then
echo "ERROR: The following modules were listed as dependencies but were not present in the modules directory:" 1>&2
for missing in $missing_deps; do
echo $missing | sed -e 's/\(.*\):/ from module \1: /' 1>&2
done
if [ "$KB_IGNORE_MISSING_DEPENDENCIES" ] ; then
echo "Ignoring missing dependencies."
else
echo "Please check these modules out and rerun '$0'"
exit 1
fi
fi
if [ ! -h $top_dir/runtime ] ; then
ln -s $rt_dir $top_dir/runtime
fi
#
# Construct a CLASSPATH from the runtime's libdir and from the
# libdirs of the modules we have.
#
# There is a subtlety here involving the wildcard path. Ant will not
# expand wildcards that come in from the classpath, so this classpath
# is really useless to it. However, since we know the runtime in a dev
# container is linked to $KB_TOP/runtime, we can hand that to ant as
# the top of a hierarchy to search for jar files.
#
classpath="\$KB_RUNTIME/lib/*"
for moddir in modules/* ; do
p=$top_dir/$moddir
if [ -d $p ] ; then
elt="\$KB_TOP/$moddir/dist/lib"
classpath="${classpath}:$elt/*"
fi
done
#
# Configure the appropriate JAVA_HOME.
#
# If we come in with a JAVA_HOME set, use that.
#
java_path=''
if [ "$JAVA_HOME" = "" ] ; then
if [ -d "$rt_dir/java" ] ; then
elt="\$KB_RUNTIME/java"
java_path=$elt
elif [ -x /usr/libexec/java_home ] ; then
java_path=`/usr/libexec/java_home`
elif [ -d "/Library/Java/Home" ] ; then
# Mac
java_path="/Library/Java/Home"
else
echo "JAVA_HOME not found" 1>&2
exit 1
#
# Try to find javac, and set based on that.
#
fi
else
java_path="$JAVA_HOME"
fi
#
# Configure the appropriate CATALINA_HOME.
#
# If we come in with a CATALINA_HOME set, use that.
#
tomcat_path=''
if [ "$CATALINA_HOME" = "" ] ; then
if [ -d "$rt_dir/tomcat" ] ; then
elt="\$KB_RUNTIME/tomcat"
tomcat_path=$elt
elif [ -d "/Library/Tomcat/Home" ] ; then
# Mac
tomcat_path="/Library/Tomcat/Home"
else
echo "CATALINA_HOME not found" 1>&2
fi
else
tomcat_path="$CATALINA_HOME"
fi
modlist=""
modlistc=""
perl_lib=""
for moddir in modules/* ; do
p=$top_dir/$moddir/lib
if [ -d $p ] ; then
elt="\$KB_TOP/$moddir/lib"
if [ "$perl_lib" = "" ] ; then perl_lib=$elt ; else perl_lib="$perl_lib:$elt" ; fi
modname=`basename $moddir`
if [ "$modlist" = "" ] ; then modlist=$modname ; else modlist="$modlist $modname" ; fi
if [ "$modlistc" = "" ] ; then modlistc=$modname ; else modlistc="$modlistc, $modname" ; fi
fi
done
dcfg=$top_dir/bootstrap.cfg
cat > $dcfg <<EOF
[default]
target = /kb/deployment
deploy-runtime = $rt_dir
deploy-client = $modlistc
deploy-service =
EOF
for mod in $modlist ; do
md=modules/$mod
if [ -f "$md/deploy.cfg" ] ; then
cat $md/deploy.cfg >> $dcfg
else
echo "[$mod]" >> $dcfg
fi
echo "" >> $dcfg
done
#
# Construct python path
#
python_lib=""
for moddir in modules/* ; do
p=$top_dir/$moddir/lib
if [ -d $p ] ; then
elt="\$KB_TOP/$moddir/lib"
if [ "$python_lib" = "" ] ; then python_lib=$elt ; else python_lib="$python_lib:$elt" ; fi
fi
done
#
# Construct rscript path
#
rscript_lib=""
for moddir in modules/* ; do
p=$top_dir/$moddir/lib
if [ -d $p ] ; then
elt="\$KB_TOP/$moddir/lib"
if [ "$rscript_lib" = "" ] ; then rscript_lib=$elt ; else rscript_lib="$rscript_lib:$elt" ; fi
fi
done
#
# Wrap scripts.
#
for script in tools/*.pl ; do
if [ -f $script ] ; then
base=`basename $script .pl`
wrap_perl $script tools/$base
fi
done
for script in tools/*.sh ; do
if [ -f $script ] ; then
base=`basename $script .sh`
wrap_sh $script tools/$base
fi
done
path_str="\$KB_RUNTIME/bin:\$KB_TOP/bin:\$KB_RUNTIME/glassfish3/bin:\$JAVA_HOME/bin:\$KB_RUNTIME/thrift/bin:\$PATH"
cat > $top_dir/user-env.sh <<EOF
export KB_TOP=$top_dir
export KB_RUNTIME=$rt_dir
export KB_PERL_PATH=$perl_lib
export KB_PYTHON_PATH=$python_lib
export KB_R_PATH=$rscript_lib
export JAVA_HOME=$java_path
export CATALINA_HOME=$tomcat_path
export PATH=$path_str
export PERL5LIB=\$KB_PERL_PATH
export PYTHONPATH=\$KB_PYTHON_PATH:\$PYTHONPATH
export R_LIBS=\$KB_R_PATH:\$R_LIBS
export GLASSFISH_HOME=\$KB_RUNTIME/glassfish3
export CLASSPATH=$classpath
hash -r
EOF
cat > $top_dir/user-env.csh <<EOF
setenv KB_TOP $top_dir
setenv KB_RUNTIME $rt_dir
setenv KB_PERL_PATH $perl_lib
setenv KB_PYTHON_PATH $python_lib
setenv KB_R_PATH $rscript_lib
setenv JAVA_HOME $java_path
setenv CATALINA_HOME $tomcat_path
setenv PATH $path_str
setenv PERL5LIB \$KB_PERL_PATH
setenv PYTHONPATH \$KB_PYTHON_PATH:\$PYTHONPATH
setenv R_LIBS \$KB_R_PATH:\$R_LIBS
setenv GLASSFISH_HOME \$KB_RUNTIME/glassfish3
setenv CLASSPATH $classpath
rehash
EOF