/
run_local.sh
executable file
·700 lines (559 loc) · 20.3 KB
/
run_local.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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
#!/usr/bin/env bash
# DO NOT EDIT THIS FILE!
# Generated by fulgens (https://www.npmjs.com/package/fulgens)
# Version: 0.0.19
trap cleanup 2
set -e
#---------------------
# START - FunctionsBuilder
jdk_version() {
# returns the JDK version.
# 8 for 1.8.0_nn, 9 for 9-ea etc, and "no_java" for undetected
# from https://stackoverflow.com/questions/7334754/correct-way-to-check-java-version-from-bash-script
local result
local java_cmd
if [[ -n $(type -p java) ]]; then
java_cmd=java
elif [[ (-n "$JAVA_HOME") && (-x "$JAVA_HOME/bin/java") ]]; then
java_cmd="$JAVA_HOME/bin/java"
fi
local IFS=$'\n'
# remove \r for Cygwin
local lines=$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n')
if [[ -z $java_cmd ]]; then
result=no_java
else
for line in $lines; do
if [[ (-z $result) && ($line == *"version \""*) ]]; then
local ver=$(echo $line | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q')
# on macOS, sed doesn't support '?'
if [[ $ver == "1."* ]]; then
result=$(echo $ver | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q')
else
result=$(echo $ver | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q')
fi
fi
done
fi
echo "$result"
}
# END - FunctionsBuilder
#---------------------
verbosePrint() {
if [ "$VERBOSE" == "YES" ]; then
echo -e "$1"
fi
}
startDockerNetwork() {
if [ -z "$DOCKER_NETWORKED_CHECKED" ]; then
DOCKER_NETWORKED_CHECKED=YES
if ! docker network ls | grep -s "toldyousonet"; then
verbosePrint "Starting docker network toldyousonet on 10.239.98.0/24"
docker network create -d bridge --subnet 10.239.98.0/24 --gateway 10.239.98.1 "toldyousonet"
else
verbosePrint "Docker network toldyousonet already running"
fi
fi
}
#---------------------
# START - CleanupBuilder
cleanup() {
echo "****************************************************************"
echo "Stopping software .....please wait...."
echo "****************************************************************"
set +e
ALL_COMPONENTS=(couchdb tomcat)
for componentToStop in "${ALL_COMPONENTS[@]}"; do
IFS=',' read -r -a keepRunningArray <<<"$KEEP_RUNNING"
componentFoundToKeepRunning=0
for keepRunningToFindeElement in "${keepRunningArray[@]}"; do
if [ "$componentToStop" == "$keepRunningToFindeElement" ]; then
echo "Not stopping $componentToStop!"
componentFoundToKeepRunning=1
fi
done
if [ "$componentFoundToKeepRunning" -eq 0 ]; then
if [ "$START_COUCHDB" = "YES" ]; then
if [ "$componentToStop" == "couchdb" ]; then
echo "Stopping $componentToStop ..."
if [ "$TYPE_SOURCE_COUCHDB" == "docker" ]; then
docker rm -f $dockerContainerIDcouchdb
rm -f .couchdbPid
fi
fi
fi
if [ "$START_TOMCAT" = "YES" ]; then
if [ "$componentToStop" == "tomcat" ]; then
echo "Stopping $componentToStop ..."
if [ "$TYPE_SOURCE_TOMCAT" == "docker" ]; then
docker rm -f $dockerContainerIDtomcat
rm -f .tomcatPid
fi
if [ "$TYPE_SOURCE_TOMCAT" == "download" ]; then
./localrun/apache-tomcat-$TOMCAT_VERSION/bin/shutdown.sh
rm -f .tomcatPid
fi
fi
fi
fi
done
exit 0
}
# END - CleanupBuilder
#---------------------
#---------------------
# START - OptionsBuilder
usage="
usage: $(basename "$0") [options] [<component(s)>]
Options:
-h show this help text
-s skip any build
-S skip consistency check against Fulgensfile
-c [all|build] clean local run directory, when a build is scheduled for execution it also does a full build
-k [component] keep comma sperarated list of components running
-t [component:type:[path|version]] run component inside [docker] container, [download] component or [local] use installed component from path
-v enable Verbose
-V start VirtualBox via vagrant, install all dependencies, ssh into the VM and run
-j version macOS only: set/overwrite JAVA_HOME to a specific locally installed version, use format from/for: /usr/libexec/java_home [-V]
-f tail the apache catalina log at the end
Url: http://localhost:8080/toldyouso
Details for components:
toldyouso {Source:\"mvn\", Default-Type:\"local\", Version-Info: \"Tested with 3-jdk-11\"}
-t toldyouso:local #build local and respect -j
-t toldyouso:docker:[TAG] #docker based build, default tag: latest, uses image https://hub.docker.com/_/maven
couchdb {Source:\"couchdb\", Default-Type:\"docker:latest\", Version-Info: \"Tested with 1.7 & 2\"}
-t couchdb:local #reuse a local, running CouchDB installation, does not start/stop this CouchDB
-t couchdb:docker:[TAG] #start docker, default tag latest, uses image https://hub.docker.com/_/couchdb
tomcat {Source:\"tomcat\", Default-Type:\"download:9\", Version-Info: \"Tested with 9\"}
-t tomcat:docker:[TAG] #start docker, default tag tomcat9-openjdk11-openj9, uses image https://hub.docker.com/r/oglimmer/adoptopenjdk-tomcat
-t tomcat:download:[7|8|9] #start fresh downloaded tomcat, default version 9 and respect -j
-t tomcat:local:TOMCAT_HOME_PATH #reuse tomcat installation from TOMCAT_HOME_PATH, does not start/stop this tomcat
"
cd "$(
cd "$(dirname "$0")"
pwd -P
)"
BASE_PWD=$(pwd)
BUILD=local
while getopts ':hsSc:k:x:t:vVj:f' option; do
case "$option" in
h)
echo "$usage"
exit
;;
s) SKIP_BUILD=YES ;;
S) SKIP_HASH_CHECK=YES ;;
c)
CLEAN=$OPTARG
if [ "$CLEAN" != "all" -a "$CLEAN" != "build" ]; then
echo "Illegal -c parameter" && exit 1
fi
;;
k) KEEP_RUNNING=$OPTARG ;;
x) SKIP_STARTING=$OPTARG ;;
t) TYPE_SOURCE=$OPTARG ;;
v) VERBOSE=YES ;;
V) VAGRANT=YES ;;
j) JAVA_VERSION=$OPTARG ;;
f) TAIL=YES ;;
:)
printf "missing argument for -%s\\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\\?)
printf "illegal option: -%s\\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ -z "$1" ]; then
declare START_TOLDYOUSO=YES
declare START_COUCHDB=YES
declare START_TOMCAT=YES
else
ALL_COMPONENTS=(TOLDYOUSO COUCHDB TOMCAT)
for comp in "$@"; do
compUpper=$(echo $comp | awk '{print toupper($0)}')
compValid=0
for compDefined in "${ALL_COMPONENTS[@]}"; do
if [ "$compDefined" = "$compUpper" ]; then
compValid=1
fi
done
if [ "$compValid" -eq 0 ]; then
echo "Component $comp is invalid!"
exit 1
fi
declare START_$compUpper=YES
done
fi
# END - OptionsBuilder
#---------------------
if [ "$SKIP_HASH_CHECK" != "YES" ]; then
if which md5 1>/dev/null; then
declare SELF_HASH_MD5="f3f85901e19b0c4bd51fce2773b745cf"
declare SOURCE_FILES=(Fulgensfile Fulgensfile.js)
for SOURCE_FILE in ${SOURCE_FILES[@]}; do
declare SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
if [ -f "$SCRIPT_DIR/$SOURCE_FILE" ]; then
if [ "$SELF_HASH_MD5" != "$(md5 -q $SCRIPT_DIR/$SOURCE_FILE)" ]; then
echo "$SOURCE_FILE doesn not match!"
exit 1
fi
fi
done
fi
fi
#---------------------
# START - DependencycheckBuilder
mvn --version 1>/dev/null || exit 1
docker --version 1>/dev/null || exit 1
java -version 2>/dev/null || exit 1
curl --version 1>/dev/null || exit 1
# END - DependencycheckBuilder
#---------------------
# clean if requested
if [ -n "$CLEAN" ]; then
if [ "$CLEAN" == "all" ]; then
if [ "$VERBOSE" == "YES" ]; then echo "rm -rf localrun"; fi
rm -rf localrun
fi
fi
#---------------------
# START - GlobalVariablesBuilder
verbosePrint "DEFAULT: TYPE_SOURCE_TOLDYOUSO=local"
TYPE_SOURCE_TOLDYOUSO=local
verbosePrint "DEFAULT: TYPE_SOURCE_COUCHDB=docker"
TYPE_SOURCE_COUCHDB=docker
verbosePrint "DEFAULT: TYPE_SOURCE_TOMCAT=download"
TYPE_SOURCE_TOMCAT=download
# END - GlobalVariablesBuilder
#---------------------
if [ "$(uname)" = "Linux" ]; then
if [ -n "$WSL_DISTRO_NAME" ]; then
ADD_HOST_INTERNAL="--add-host host.docker.internal:$(ip -4 addr show scope global dev eth0 | grep inet | awk '{print $2}' | cut -d / -f 1)"
else
ADD_HOST_INTERNAL="--add-host host.docker.internal:$(ip -4 addr show scope global dev docker0 | grep inet | awk '{print $2}' | cut -d / -f 1)"
fi
fi
mkdir -p localrun
f_deploy() {
echo "No plugin defined f_deploy()"
}
#---------------------
# START - PrepareBuilder
if [ "$(uname)" == "Darwin" ]; then
if [ -n "$JAVA_VERSION" ]; then
export JAVA_HOME=$(/usr/libexec/java_home -v $JAVA_VERSION)
fi
fi
if [ "$VAGRANT" == "YES" -a "$VAGRANT_IGNORE" != "YES" ]; then
mkdir -p localrun
cd localrun
cat <<-EOF >Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.synced_folder "../", "/share_host"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1536"
vb.cpus = 4
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
if [ "\$(cat /etc/*release|grep ^ID=)" = "ID=debian" ]; then \\
if [ "\$(cat /etc/debian_version)" = "8.11" ]; then \\
apt-get -qy install maven openjdk-8-jdk-headless docker.io; \\
elif [ "\$(cat /etc/debian_version)" = "9.5" ]; then \\
apt-get -qy install maven openjdk-8-jdk-headless docker.io; \\
else apt-get -qy install maven openjdk-8-jdk-headless docker.io; fi \\
elif [ "\$(cat /etc/*release|grep ^ID=)" = "ID=ubuntu" ]; then \\
apt-get -qy install maven openjdk-8-jdk-headless docker.io; \\
else \\
echo "only debian or ubuntu are supported."; \\
exit 1; \\
fi \\
echo "Now continue with..."
echo "\$ cd /share_host"
echo "\$ sudo ./run_local.sh -f"
echo "...then browse to http://localhost:8080/toldyouso"
SHELL
end
EOF
vagrant up
if [ -f "../run_local.sh" ]; then
vagrant ssh -c "cd /share_host && sudo ./run_local.sh -f"
else
echo "Save the fulgens output into a bash script (e.g. run_local.sh) and use it inside the new VM"
fi
exit 1
fi
# END - PrepareBuilder
#---------------------
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MvnPlugin // toldyouso
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verbosePrint "MvnPlugin // toldyouso"
if [ "$START_TOLDYOUSO" = "YES" ]; then
#---------------------
# START - Plugin-PrepareComp
IFS=',' read -r -a array <<<"$TYPE_SOURCE"
for typeSourceElement in "${array[@]}"; do
IFS=: read comp type pathOrVersion <<<"$typeSourceElement"
if [ "$comp" == "toldyouso" ]; then
TYPE_SOURCE_TOLDYOUSO=$type
if [ "$TYPE_SOURCE_TOLDYOUSO" == "local" ]; then
TYPE_SOURCE_TOLDYOUSO_PATH=$pathOrVersion
else
TYPE_SOURCE_TOLDYOUSO_VERSION=$pathOrVersion
fi
fi
done
if [ "$TYPE_SOURCE_TOLDYOUSO" == "docker" ]; then
if [ -z "$TYPE_SOURCE_TOLDYOUSO_VERSION" ]; then
TYPE_SOURCE_TOLDYOUSO_VERSION=latest
fi
fi
verbosePrint "TYPE_SOURCE_TOLDYOUSO = $TYPE_SOURCE_TOLDYOUSO // TYPE_SOURCE_TOLDYOUSO_PATH = $TYPE_SOURCE_TOLDYOUSO_PATH // TYPE_SOURCE_TOLDYOUSO_VERSION = $TYPE_SOURCE_TOLDYOUSO_VERSION"
# END - Plugin-PrepareComp
#---------------------
if [ "$TYPE_SOURCE_TOLDYOUSO" == "local" ]; then
f_build() {
verbosePrint "pwd=$(pwd)\nmvn $MVN_CLEAN $MVN_OPTS package"
if [ "$(jdk_version)" -lt 9 ]; then
cp pom.xml pom.xml.bak
sed '/<!-- needed since Java 9 - START -->/,/<!-- needed since Java 9 - END -->/d' pom.xml.bak >pom.xml
fi
mvn $MVN_CLEAN $MVN_OPTS package
if [ "$(jdk_version)" -lt 9 ]; then mv -f pom.xml.bak pom.xml; fi
}
fi
if [ "$TYPE_SOURCE_TOLDYOUSO" == "docker" ]; then
dockerImage=maven
f_build() {
verbosePrint "pwd=$(pwd)\ndocker run --name=toldyouso --rm -v $(pwd):/usr/src/build -v "$(pwd)/localrun/.m2":/root/.m2 -w /usr/src/build $dockerImage:$TYPE_SOURCE_TOLDYOUSO_VERSION mvn $MVN_CLEAN $MVN_OPTS package"
if [ "$(jdk_version)" -lt 9 ]; then
cp pom.xml pom.xml.bak
sed '/<!-- needed since Java 9 - START -->/,/<!-- needed since Java 9 - END -->/d' pom.xml.bak >pom.xml
fi
docker run --name=toldyouso --rm -v "$(pwd)":/usr/src/build -v "$(pwd)/localrun/.m2":/root/.m2 -w /usr/src/build $dockerImage:$TYPE_SOURCE_TOLDYOUSO_VERSION mvn $MVN_CLEAN $MVN_OPTS package
if [ "$(jdk_version)" -lt 9 ]; then mv -f pom.xml.bak pom.xml; fi
}
fi
if [ "$SKIP_BUILD" != "YES" ]; then
if [ -n "$CLEAN" ]; then
MVN_CLEAN=clean
fi
f_build
else
verbosePrint "Mvn build skipped."
fi
fi
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CouchdbPlugin // couchdb
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verbosePrint "CouchdbPlugin // couchdb"
if [ "$START_COUCHDB" = "YES" ]; then
#---------------------
# START - Plugin-PrepareComp
IFS=',' read -r -a array <<<"$TYPE_SOURCE"
for typeSourceElement in "${array[@]}"; do
IFS=: read comp type pathOrVersion <<<"$typeSourceElement"
if [ "$comp" == "couchdb" ]; then
TYPE_SOURCE_COUCHDB=$type
if [ "$TYPE_SOURCE_COUCHDB" == "local" ]; then
TYPE_SOURCE_COUCHDB_PATH=$pathOrVersion
else
TYPE_SOURCE_COUCHDB_VERSION=$pathOrVersion
fi
fi
done
if [ "$TYPE_SOURCE_COUCHDB" == "docker" ]; then
if [ -z "$TYPE_SOURCE_COUCHDB_VERSION" ]; then
TYPE_SOURCE_COUCHDB_VERSION=latest
fi
fi
verbosePrint "TYPE_SOURCE_COUCHDB = $TYPE_SOURCE_COUCHDB // TYPE_SOURCE_COUCHDB_PATH = $TYPE_SOURCE_COUCHDB_PATH // TYPE_SOURCE_COUCHDB_VERSION = $TYPE_SOURCE_COUCHDB_VERSION"
# END - Plugin-PrepareComp
#---------------------
if [ "$TYPE_SOURCE_COUCHDB" == "docker" ]; then
if [ ! -f ".couchdbPid" ]; then
startDockerNetwork
verbosePrint "docker run --rm -d -p 5984:5984 -m 200M --net=toldyousonet --name=couchdb $ADD_HOST_INTERNAL -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password couchdb:$TYPE_SOURCE_COUCHDB_VERSION"
dockerContainerIDcouchdb=$(docker run --rm -d -p 5984:5984 \
-m 200M \
-e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password \
--net=toldyousonet --name=couchdb $ADD_HOST_INTERNAL \
couchdb:$TYPE_SOURCE_COUCHDB_VERSION)
echo "$dockerContainerIDcouchdb" >.couchdbPid
else
dockerContainerIDcouchdb=$(<.couchdbPid)
echo "Reusing already running instance $dockerContainerIDcouchdb"
fi
fi
if [ "$TYPE_SOURCE_COUCHDB" == "local" ]; then
if [ -f ".couchdbPid" ]; then
echo "couchdb couchdb running but started from different source type"
exit 1
fi
fi
while [ "$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:5984)" != "200" ]; do
echo "waiting for couchdb..."
sleep 1
done
if [[ "$(curl -u 'admin:password' -s http://localhost:5984/toldyouso)" =~ .*"error".*"not_found".* ]]; then
curl -u 'admin:password' -X PUT http://localhost:5984/_users
curl -u 'admin:password' -X PUT http://localhost:5984/toldyouso
curl -u 'admin:password' -X POST -H "Content-Type: application/json" -d @src/couchdb/_design-User-view.json http://localhost:5984/toldyouso
fi
fi
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TomcatPlugin // tomcat
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verbosePrint "TomcatPlugin // tomcat"
if [ "$START_TOMCAT" = "YES" ]; then
#---------------------
# START - Plugin-PrepareComp
IFS=',' read -r -a array <<<"$TYPE_SOURCE"
for typeSourceElement in "${array[@]}"; do
IFS=: read comp type pathOrVersion <<<"$typeSourceElement"
if [ "$comp" == "tomcat" ]; then
TYPE_SOURCE_TOMCAT=$type
if [ "$TYPE_SOURCE_TOMCAT" == "local" ]; then
TYPE_SOURCE_TOMCAT_PATH=$pathOrVersion
else
TYPE_SOURCE_TOMCAT_VERSION=$pathOrVersion
fi
fi
done
if [ "$TYPE_SOURCE_TOMCAT" == "docker" ]; then
if [ -z "$TYPE_SOURCE_TOMCAT_VERSION" ]; then
TYPE_SOURCE_TOMCAT_VERSION=tomcat9-openjdk11-openj9
fi
fi
if [ "$TYPE_SOURCE_TOMCAT" == "download" ]; then
if [ -z "$TYPE_SOURCE_TOMCAT_VERSION" ]; then
TYPE_SOURCE_TOMCAT_VERSION=9
fi
# find latest tomcat version for $TYPE_SOURCE_TOMCAT_VERSION
if [ "$(uname)" == "Linux" ]; then
GREP_PERL_MODE="-P"
fi
TOMCAT_BASE_URL="http://mirror.vorboss.net/apache/tomcat"
TOMCAT_VERSION_PRE=$(curl -s "$TOMCAT_BASE_URL/tomcat-$TYPE_SOURCE_TOMCAT_VERSION/" | grep -m1 -o $GREP_PERL_MODE "<a href=\"v\d*.\d*.\d*" || echo "__________9.0.10")
TOMCAT_VERSION=${TOMCAT_VERSION_PRE:10}
TOMCAT_URL=$TOMCAT_BASE_URL/tomcat-$TYPE_SOURCE_TOMCAT_VERSION/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz
fi
verbosePrint "TYPE_SOURCE_TOMCAT = $TYPE_SOURCE_TOMCAT // TYPE_SOURCE_TOMCAT_PATH = $TYPE_SOURCE_TOMCAT_PATH // TYPE_SOURCE_TOMCAT_VERSION = $TYPE_SOURCE_TOMCAT_VERSION"
# END - Plugin-PrepareComp
#---------------------
if [ "$TYPE_SOURCE_TOMCAT" == "download" ]; then
if [ -f ".tomcatPid" ] && [ "$(<.tomcatPid)" != "download" ]; then
echo "Tomcat running but started from different source type"
exit 1
fi
# download tomcat
if [ ! -f "/${TMPDIR:-/tmp}/apache-tomcat-$TOMCAT_VERSION.tar" ]; then
curl -s $TOMCAT_URL | gzip -d >/${TMPDIR:-/tmp}/apache-tomcat-$TOMCAT_VERSION.tar
fi
# extract tomcat
if [ ! -d "./apache-tomcat-$TOMCAT_VERSION" ]; then
tar -xf /${TMPDIR:-/tmp}/apache-tomcat-$TOMCAT_VERSION.tar -C ./localrun
fi
fi
dockerAddLibRefs=()
if [ "$TYPE_SOURCE_TOMCAT" == "docker" ]; then
mkdir -p localrun/webapps
targetPath=localrun/webapps/
fi
if [ "$TYPE_SOURCE_TOMCAT" == "download" ]; then
targetPath=localrun/apache-tomcat-$TOMCAT_VERSION/webapps/
fi
if [ "$TYPE_SOURCE_TOMCAT" == "local" ]; then
targetPath=$TYPE_SOURCE_TOMCAT_PATH/webapps/
fi
f_deploy() {
cp target/toldyouso.war $targetPath
}
f_deploy
if [ "$TYPE_SOURCE_TOMCAT" == "download" ]; then
if [ ! -f ".tomcatPid" ]; then
REPLVAR_TOLDYOUSO_COUCHDB="localhost"
mkdir -p localrun/3b28238d
cat <<EOT3b28238d >localrun/3b28238d/java.properties
toldyouso.domain=http://localhost:8080/toldyouso
couchdb.host=$REPLVAR_TOLDYOUSO_COUCHDB
EOT3b28238d
export JAVA_OPTS="-Dtoldyouso.properties=localrun/3b28238d/java.properties"
export JAVA_OPTS="$JAVA_OPTS "
./localrun/apache-tomcat-$TOMCAT_VERSION/bin/startup.sh
echo "download" >.tomcatPid
else
echo "Reusing already running instance"
fi
tailCmd="tail -f ./localrun/apache-tomcat-$TOMCAT_VERSION/logs/catalina.out"
fi
if [ "$TYPE_SOURCE_TOMCAT" == "docker" ]; then
if [ -f ".tomcatPid" ] && [ "$(<.tomcatPid)" == "download" ]; then
echo "Tomcat running but started from different source type"
exit 1
fi
if [ ! -f ".tomcatPid" ]; then
startDockerNetwork
if [ "$TYPE_SOURCE_COUCHDB" == "docker" ]; then
REPLVAR_TOLDYOUSO_COUCHDB="couchdb"
elif [ "$TYPE_SOURCE_COUCHDB" == "local" ]; then
REPLVAR_TOLDYOUSO_COUCHDB="host.docker.internal"
fi
mkdir -p localrun/3b28238d
cat <<EOT3b28238d >localrun/3b28238d/java.properties
toldyouso.domain=http://localhost:8080/toldyouso
couchdb.host=$REPLVAR_TOLDYOUSO_COUCHDB
EOT3b28238d
verbosePrint "docker run --rm -d ${dockerAddLibRefs[@]} -p 8080:8080 -m 70M --net=toldyousonet --name=tomcat $ADD_HOST_INTERNAL -v "$(pwd)/localrun/3b28238d:/tmp/3b28238d" -e JAVA_OPTS="-Dtoldyouso.properties=/tmp/3b28238d/java.properties" -v "$(pwd)/localrun/webapps":/usr/local/tomcat/webapps oglimmer/adoptopenjdk-tomcat:$TYPE_SOURCE_TOMCAT_VERSION"
dockerContainerIDtomcat=$(docker run --rm -d ${dockerAddLibRefs[@]} -p 8080:8080 \
-m 70M \
--net=toldyousonet --name=tomcat $ADD_HOST_INTERNAL \
-v "$(pwd)/localrun/3b28238d:/tmp/3b28238d" -e JAVA_OPTS="-Dtoldyouso.properties=/tmp/3b28238d/java.properties" \
-v "$(pwd)/localrun/webapps":/usr/local/tomcat/webapps oglimmer/adoptopenjdk-tomcat:$TYPE_SOURCE_TOMCAT_VERSION)
echo "$dockerContainerIDtomcat" >.tomcatPid
else
dockerContainerIDtomcat=$(<.tomcatPid)
echo "Reusing already running instance $dockerContainerIDtomcat"
fi
tailCmd="docker logs -f $dockerContainerIDtomcat"
fi
if [ "$TYPE_SOURCE_TOMCAT" == "local" ]; then
if [ -f ".tomcatPid" ]; then
echo "Tomcat running but started from different source type"
exit 1
fi
tailCmd="tail -f $TYPE_SOURCE_TOMCAT_PATH/logs/catalina.out"
fi
fi
#---------------------
# START - WaitBuilder
# waiting for ctrl-c
echo "*************************************************************"
echo "**** SCRIPT COMPLETED, STARTUP IN PROGRESS ******************"
if [ "$TAIL" == "YES" ]; then
echo "http://localhost:8080/toldyouso"
echo "**** now tailing log: $tailCmd"
$tailCmd
else
echo "http://localhost:8080/toldyouso"
echo "$tailCmd"
echo "<return> to rebuild, ctrl-c to stop couchdb, tomcat"
while true; do
read </dev/tty
f_build
f_deploy
done
fi
# END - WaitBuilder
#---------------------