This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build_te.sh
executable file
·494 lines (377 loc) · 12.6 KB
/
build_te.sh
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#!/bin/sh
echo ""
dir=$(pwd)
realpath(){
thedir=$1
cd $thedir
pwd
}
printHelp(){
echo "---------"
echo "Usage build_te [-t tomcat or -cb catalinabasefolder] [-options] "
echo ""
echo "There are two main ways to build."
echo "1. From scratch, Tomcat and catalina_base are not setup"
echo "2. catalina_base is already setup"
echo ""
echo "For the first case. -t parameter needs to be passed as argument."
echo "For the second case -cb needs to passed as argument."
echo "It is mandatory to use one or the other."
echo ""
echo "where:"
echo " tomcat Is the path to tomcat, e.g. /home/ubuntu/apache-tomcat-7.0.52"
echo " catalinabasefolder Is the path to the CATALINA_BASE directory. It should contain "
echo " webapps and lib folders, amongst others."
echo ""
echo "where options include:"
echo " -g (or --git-url) URL to a git repository (local or external) for the TEAM Engine source"
echo " For example: https://github.com/opengeospatial/teamengine.git"
echo " If not provided, then this URL will be used:"
echo " https://github.com/opengeospatial/teamengine.git"
echo ""
echo " -a (or --tag-or-branch) To build a specific tag or branch."
echo " If not provided, then master will be used."
echo ""
echo " -b (or --base-folder) Local path where teamengine will be build from scratch."
echo " If not given, then ~/te-build will be used."
echo ""
echo " -w (or --war) War name"
echo " If not given, then 'teamengine' will be used."
echo ""
echo " -s (or --start) If 'true', then the build will attempt to stop"
echo " a tomcat a process and will start again tomcat."
echo ""
echo " -d (or --dev) Local directory to build from to run in development mode."
echo " It will build from the source at the given path. No 'git pull' is issued."
echo " If the parameters -g and -a are also provided, then they will not be used"
echo ""
echo " -f (or -folder_site) If given, it will build with the provided site folder, if not it will"
echo " use a folder 'site' located in the same directory of this script"
echo " The site folder customizes the look and feel, welcome page, etc."
echo ""
echo " Examples:"
echo " ./build_te.sh -t /Applications/apache-tomcat-7.0.57 "
echo " ./build_te.sh -t /Applications/apache-tomcat-7.0.57 -a 4.1.0b -w /temp/te"
echo " ./build_te.sh -t /Applications/apache-tomcat-7.0.57 "
echo " ./build_te.sh -t /Applications/apache-tomcat-7.0.57 -d /Users/mike/git/teamengine/ -s true"
echo ""
echo "more information about TEAM Engine at https://github.com/opengeospatial/teamengine/ "
echo "more information about this builder at https://github.com/opengeospatial/teamengine-builder/ "
echo "----------"
exit 0
}
if [ "$1" = "-h" -o "$1" = "--help" ]; then
printHelp
fi
while [ "$1" ]; do
key="$1"
case $key in
-a|--tag-or-branch)
te_tag="$2"
shift
;;
-b|--base-folder)
base_folder="$2"
shift
;;
-t|--tomcat)
tomcat_base="$2"
shift
;;
-w|--war)
war="$2"
shift
;;
-g|--git-url)
te_git_url="$2"
shift
;;
-s|--start)
start="$2"
shift
;;
-d|--dev)
dev="$2"
shift
;;
-f|--folder_site)
folder_site="$2"
shift
;;
-cb|--catalina_base)
catalinabasefolder="$2"
shift
;;
esac
shift
done
#--------- Check pre-condtions for the java, git, maven, tomcat.
check_java=$(java -version 2>&1)
if [ -z "$check_java" ]; then
echo ""
echo "[ERROR] Java not found. Please install JAVA."
echo ""
exit 0
fi
check_mvn=$(mvn -version 2>&1)
if [ -z "$check_mvn" ]; then
echo ""
echo "[ERROR] Maven not found. Please install Maven."
echo ""
exit 0
fi
if echo $(git -version 2>&1) | grep -q -v "git"; then
echo ""
echo "[ERROR] Git not found. Please install git."
echo ""
exit 0
fi
#--- End of pre-conditions. -----
if [ $catalinabasefolder ];
then
if [ -d $catalinabasefolder ];
then
echo "[INFO] Using catalinabasefolder: " $catalinabasefolder
fi
else
if [ $tomcat_base ];
then
if [ -f $tomcat_base/bin/catalina.sh ]; then
tomcat_base=$(realpath $tomcat_base)
echo "[INFO] Using tomcat: " $tomcat_base
else
echo "[FAIL] Please provide a correct tomcat location, e.g. /home/ubuntu/apache-tomcat-7.0.52."
printHelp
fi
else
echo "[FAIL] Please provide a correct tomcat installation or CATALINA_BASE folder"
echo ""
printHelp
fi
fi
if [ $dev ]; then
echo "[INFO] Running in development mode. The local source to be used is "$dev
te_git_url=""
te_tag=""
else
if [ $te_git_url ];
then
echo "[INFO] Using git url: " $te_git_url
else
echo "[INFO] The git url was not provided, so 'https://github.com/opengeospatial/teamengine.git' will be used"
te_git_url=https://github.com/opengeospatial/teamengine.git
fi
if [ $te_tag ];
then
echo "[INFO] Building " $te_tag
else
echo "[INFO] Did not provide a tag to build 'te_tag', so building master"
te_tag="master"
fi
fi
# If a a specific tag or branch is not given then the master will be built
if [ $base_folder ];
then
if [ -d $base_folder ]; then
base_folder=$(realpath $base_folder)
echo "[INFO] Building in a fresh base folder: " $base_folder
else
echo "[FAIL] Base folder doesn't exist" $base_folder
exit 0
fi
else
echo "[INFO] Base folder was not provided, so it will attempt to build in the user's directory '~/te-build'"
if [ ! -d ~/te-build ]; then
mkdir -p ~/te-build
fi
base_folder=~/te-build
fi
echo "[INFO] Using Base folder: $base_folder"
if [ $war ];
then
echo "[INFO] Using war name: " $war
else
echo "[INFO] War name was not provide, so 'teamengine' will be used"
war=teamengine
fi
if $start ; then
if [ "$start" = "true" ]; then
echo "[INFO] tomcat will start after installing $start"
fi
else
$start="false"
fi
## optional: contains body, header and footer for the welcome page
if [ $folder_site ];
then
echo "[INFO] The folder to be used to create custom site content is : " $folder_site
folder_site=$(realpath $folder_site)
else
folder_site=$dir/site
## folder_site=realpath $folder_site/
echo "[INFO] The folder site was not provided, so $folder_site will be used: "
fi
folder_to_build=$base_folder
## location of tomcat
tomcat=$tomcat_base
## Contains example of a user: ogctest, ogctest
user_temp_folder=$dir/users
## no need to change anything else hereafter
##----------------------------------------------------------##
# Define more variables
war_name=$war
#repo_te=$folder_to_build/build
## clean
echo "[INFO] - cleaning - removing folder to build "$folder_to_build
if [ -d $folder_to_build ];
then
cp -f $folder_to_build $folder_to_build.bak
rm -rf $folder_to_build/*
fi
echo "[INFO] Installing TEAM Engine "
cd $folder_to_build
# if dev is not given
if [ ! $dev ] ; then
rm -rf teamengine
## download TE
git clone $te_git_url teamengine
mss=$(git clone $te_git_url teamengine)
if echo "$mss" | grep "fatal" ;
then
err="[FAIL] - Repository doesn't exist: $te_git_url"
echo "$err"
exit 0
fi
cd $folder_to_build/teamengine
if [ "$te_tag" = "master" ];then
echo "[INFO] Checking out: master branch "
else
tags=$(git tag)
if echo "$tags" | grep -q "$te_tag"; then
found="tag"
else
echo "Tag $te_tag not found, so looking for branches"
branches=$(git branch -a)
if echo "$branches" | grep -q "$te_tag"; then
found="branch"
else
echo "[FAIL] Branch or Tag $te_tag not found";
exit
fi
fi
echo "[INFO] Checking out: $te_tag $found"
fi
git checkout $te_tag
echo "[INFO] Building using Maven in quite mode (1-2 min)"
mvn -q clean install -DskipTests=true
else
echo "[INFO] Running development mode - building from local folder"
if [ -d $dev ]; then
if [ ! -d $folder_to_build/teamengine ]; then
mkdir $folder_to_build/teamengine
fi
echo "[INFO] Copying from $dev to $folder_to_build"
##cp -rf $dev $folder_to_build/teamengine
cp -rf $dev/* $folder_to_build/teamengine
cd $folder_to_build/teamengine
mvn -q clean install -DskipTests=true
else
echo "[FAIL] $dev doesn't seems to be a local folder. It should for example /users/home/.."
exit
fi
fi
echo "[SUCCESS] TE has been installed and built successfully"
echo " "
if [ ! $catalinabasefolder ];
then
echo "[INFO] Now building catalina_base "
cd $folder_to_build
catalina_base=$folder_to_build/catalina_base
if [ -d $catalina_base ]; then
rm -rf $catalina_base
fi
mkdir -p $catalina_base
echo "[INFO] clean, create and populate catalina base in $catalina_base"
cd $catalina_base
mkdir bin logs temp webapps work lib
## copy from tomcat bin and base files
cp $tomcat/bin/catalina.sh bin/
cp -r $tomcat/conf $catalina_base
else
catalina_base=$catalinabasefolder
fi
echo "[INFO] copying war: $war_name in $catalina_base/webapps/"
## move tomcat to catalina_base
#echo "updating war file with custom source" - not working
#jar -uvf $folder_to_build/teamengine/teamengine-web/target/teamengine.war $folder_site
cd $catalina_base
rm -rf webapps/*
mkdir -p webapps
cp $folder_to_build/teamengine/teamengine-web/target/teamengine.war $catalina_base/webapps/$war_name.war
echo "[INFO] unzipping common libs in $catalina_base/lib "
unzip -q -o $folder_to_build/teamengine/teamengine-web/target/teamengine-common-libs.zip -d $catalina_base/lib
echo "[INFO] building TE_BASE"
cd $catalina_base
rm -rf TE_BASE
mkdir -p $catalina_base/TE_BASE
export TE_BASE=$catalina_base/TE_BASE
## get the file that has base zip and copy it to TE_BASE
cd $folder_to_build/teamengine/teamengine-console/target/
base_zip=$(ls *base.zip | grep -m 1 "base")
unzip -q -o $folder_to_build/teamengine/teamengine-console/target/$base_zip -d $TE_BASE
echo "[INFO] copying sample of users"
cp -rf $user_temp_folder/ $TE_BASE/users
echo "[INFO] updating $TE_BASE/resources/site"
# The folder_site contains body, header and footer to customize TE.
if [ -d "$folder_site" ];then
rm -r $TE_BASE/resources/site/*
cp -rf $folder_site/* $TE_BASE/resources/site
else
echo "[WARNING] the following folder for site was not found: '$folder_site'. Site was not updated with custom information"
fi
if [ $catalinabasefolder ]; then
echo "[SUCCESS] TE build successfully"
echo "[INFO] Now start tomcat depending on your configuration"
exit 0
fi
echo '[INFO] creating setenv with environmental variables'
cd $catalina_base/bin
touch setenv.sh
cat <<EOF >setenv.sh
#!/bin/sh
## This file creates requeried environmental variables
## to properly run teamengine in tomcat
## path to tomcat
export CATALINA_HOME=$tomcat
## path to server instance
export CATALINA_BASE=$catalina_base
## catalina options
export CATALINA_OPTS='-server -Xmx1024m -XX:MaxPermSize=128m -DTE_BASE=$TE_BASE -Dderby.system.home=$catalina_base/derby_data'
EOF
chmod 777 *.sh
echo "[SUCCESS] TE build successfully"
echo "[INFO] TE_BASE is $TE_BASE"
echo "[INFO] catalina_base was built at $catalina_base"
echo "[INFO] to start run $catalina_base/bin/catalina.sh start"
echo "[INFO] to stop run $catalina_base/bin/catalina.sh stop"
## If you want the script to start catalina, remove (or comment) the exit command with caution. It will stop any tomcat process and will start catalina_base where teamengine.war was installed.
if [ "$start" = "true" ]; then
echo "[INFO] starting tomcat but first - check running tomcat processes.."
# gets the first process found "
# pid=$(ps axuw | grep tomcat | grep -v grep | awk 'END{print $2'})
pid=$(ps axuw | grep tomcat | grep -v grep)
echo "pid is $pid"
pidn=$(ps axuw | grep tomcat | grep -v grep | wc -l)
echo " "
echo "[INFO] number or processes: $pidn"
if [ $pidn -gt 1 ]; then
pidlast=$(ps axuw | grep tomcat | grep -v grep | awk 'END{print $2'})
kill -9 $pidlast
echo "[INFO] process $pidlast was terminated"
sleep 4
else
echo "[INFO] Tomcat processes not found"
fi
echo "[INFO] ... starting tomcat ... "
$catalina_base/bin/catalina.sh start
fi