-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstart_cards.sh
executable file
·544 lines (496 loc) · 24 KB
/
start_cards.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
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
BIND_TESTS=2
BIND_TEST_SPACING=30
TERMINAL_NOCOLOR='\033[0m'
TERMINAL_RED='\033[0;31m'
TERMINAL_GREEN='\033[0;32m'
TERMINAL_YELLOW='\033[0;33m'
#CTRL+C should stop everything started by this script
trap ctrl_c INT
function ctrl_c() {
if [ ! -z $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID ]
then
echo "Shutting down keycloak_headermod_http_proxy.js"
kill $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID
wait $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID
fi
echo "Shutting down CARDS"
kill $CARDS_PID
wait $CARDS_PID
exit
}
function check_cards_running() {
jobs -pr | grep '^'$CARDS_PID'$' > /dev/null
}
function print_length_of() {
local i
for i in `seq 1 $(echo -n "$1" | wc -c)`
do
echo -n "$2"
done
#Print extra
for i in `seq 1 $3`
do
echo -n "$2"
done
}
function print_pad_right() {
printf "%-$2s" "$1"
}
function get_error_log_last_modified() {
echo "$((stat --format="%.Y" .cards-data/logs/error.log 2>/dev/null) || echo 0.00)"
}
function handle_missing_sling_commons_crypto_warning() {
echo -e "${TERMINAL_YELLOW}*************************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* The SLING_COMMONS_CRYPTO_PASSWORD enviroment variable is missing. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* Using the default value of 'password'. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}*************************************************************************${TERMINAL_NOCOLOR}"
}
function handle_missing_mailcap_fail() {
echo -e "${TERMINAL_RED}********************************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* The file ~/.mailcap is missing. Exiting. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* You can create ~/.mailcap by running: cp distribution/mailcap ~/.mailcap *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}********************************************************************************${TERMINAL_NOCOLOR}"
exit -1
}
function warn_different_mailcap() {
echo -e "${TERMINAL_YELLOW}********************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* Warning: The file ~/.mailcap differs from what is expected. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* Sending emails may not work properly! *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}********************************************************************${TERMINAL_NOCOLOR}"
}
function handle_cards_java_fail() {
echo -e "${TERMINAL_RED}**********************************************$(print_length_of $BIND_PORT '*' 4)${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* $(print_length_of $BIND_PORT ' ' 3)*${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* The CARDS Java process has failed at port ${BIND_PORT} *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* $(print_length_of $BIND_PORT ' ' 3)*${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}**********************************************$(print_length_of $BIND_PORT '*' 4)${TERMINAL_NOCOLOR}"
exit -1
}
function handle_tcp_bind_fail() {
echo -e "${TERMINAL_RED}*******************************$(print_length_of $BIND_PORT '*' 4)${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* $(print_length_of $BIND_PORT ' ' 3)*${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* Unable to bind to TCP port ${BIND_PORT} *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* $(print_length_of $BIND_PORT ' ' 3)*${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}*******************************$(print_length_of $BIND_PORT '*' 4)${TERMINAL_NOCOLOR}"
exit -1
}
function handle_tcp_bind_ok_optimal() {
echo -e "${TERMINAL_GREEN}*****************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* CARDS Socket BIND: OK *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}*****************************${TERMINAL_NOCOLOR}"
}
function handle_tcp_bind_ok_suboptimal() {
echo -e "${TERMINAL_YELLOW}*********************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* CARDS Socket BIND: OK - used suboptimal bind test *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}*********************************************************${TERMINAL_NOCOLOR}"
}
function message_bioportal_apikey_missing() {
echo -e "${TERMINAL_RED}********************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* BIOPORTAL_APIKEY not specified, skipping HANCESTRO installation. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}********************************************************************${TERMINAL_NOCOLOR}"
}
function message_hancestro_install_ok() {
echo -e "${TERMINAL_GREEN}***********************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* Installed HANCESTRO *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}***********************${TERMINAL_NOCOLOR}"
}
function message_hancestro_install_fail() {
echo -e "${TERMINAL_RED}****************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* HANCESTRO install failed *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}****************************${TERMINAL_NOCOLOR}"
}
function message_sha256_cloud_iam_ok() {
echo -e "${TERMINAL_GREEN}****************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* Setup Cloud-IAM.com Demo as a SAML IdP for CARDS *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}****************************************************${TERMINAL_NOCOLOR}"
}
function message_sha256_cloud_iam_error() {
echo -e "${TERMINAL_YELLOW}********************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* Invalid Sha256 hash for samlKeystore.p12 for Cloud-IAM.com demo. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* SAML authentication via Cloud-IAM.com IdP may not work. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}********************************************************************${TERMINAL_NOCOLOR}"
}
function message_saml_proxy_port_conflict_fail() {
echo -e "${TERMINAL_RED}***************************************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* Error: CARDS and keycloak_headermod_http_proxy.js cannot be bound to the same port. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_RED}***************************************************************************************${TERMINAL_NOCOLOR}"
}
function message_started_cards() {
if [ -z $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID ]
then
echo -e "${TERMINAL_GREEN}**************************$(print_length_of $BIND_PORT '*' 4)${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* $(print_length_of $BIND_PORT ' ' 3)*${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* Started CARDS at port ${BIND_PORT} *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* $(print_length_of $BIND_PORT ' ' 3)*${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}**************************$(print_length_of $BIND_PORT '*' 4)${TERMINAL_NOCOLOR}"
else
echo -e "${TERMINAL_GREEN}***************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* Started CARDS at port $(print_pad_right ${BIND_PORT} 21) *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* Use port ${HEADERMOD_PROXY_LISTEN_PORT} for SAML + local Sling login. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_GREEN}***************************************************${TERMINAL_NOCOLOR}"
fi
}
function message_connect_jdb() {
echo -e "${TERMINAL_YELLOW}******************************************************************${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* Please connect JDB to localhost:5005 to continue with startup. *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* jdb -attach 5005 *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}* *${TERMINAL_NOCOLOR}"
echo -e "${TERMINAL_YELLOW}******************************************************************${TERMINAL_NOCOLOR}"
}
function get_cards_version() {
CARDS_VERSION=$(cat pom.xml | grep --max-count=1 '<version>' | cut '-d>' -f2 | cut '-d<' -f1)
echo CARDS_VERSION $CARDS_VERSION
}
#Determine the port that CARDS is to bind to
BIND_PORT=$(ARGUMENT_KEY='-p' ARGUMENT_DEFAULT='8080' python3 Utilities/HostConfig/argparse_bash.py $@)
export CARDS_URL="http://localhost:${BIND_PORT}"
#Get any specified runModes
EXPR='{"operation": "includes", "key": "sling.run.modes", "val": "test"}' python3 \
Utilities/HostConfig/java_property_parser.py $@ && RUNMODE_TEST=true || RUNMODE_TEST=false
#Check if the psutil Python module is installed
python3 -c 'import psutil' 2>/dev/null && PSUTIL_INSTALLED=true || PSUTIL_INSTALLED=false
#If we are in WSL, psutil will not work, therefore act as if it is not installed
python3 -c 'import os; import sys; sys.exit(1 * ("Microsoft" not in os.uname().release))' && PSUTIL_INSTALLED=false
#If we are in macOS, psutil will not work, therefore act as if it is not installed
python3 -c 'import platform; import sys; sys.exit(1 * ("Darwin" != platform.system()))' && PSUTIL_INSTALLED=false
#If psutil is not installed, simply check if BIND_PORT is available now,
# and therefore will likely be available in the very near future
if [ $PSUTIL_INSTALLED = false ]
then
python3 Utilities/HostConfig/check_tcp_available.py --tcp_port $BIND_PORT || handle_tcp_bind_fail
fi
# Filter the parameters to allow a less verbose start command, like `-p` to specify the port, or using `VERSION` to refer to the current version.
declare -a ARGS=("$@")
# Unset has strange effect on arrays, it leaves holes that somehow don't count towards the length of the array, so we must manually keep track of the index of the last element.
declare -i ARGS_LENGTH=${#ARGS[@]}
# Storage engine: default is TAR storage, allow switching to Mongo
declare OAK_STORAGE="tar"
declare PERMISSIONS_EXPLICITLY_SET="false"
# Are we using the Cloud-IAM.com Keycloak demo instance?
declare CLOUD_IAM_DEMO="false"
# Is SAML authentication enabled?
declare SAML_IN_USE="false"
# Should any flags be passed to Java to enable debugging with JDB?
declare JAVA_DEBUGGING_FLAGS=""
get_cards_version
for ((i=0; i<${ARGS_LENGTH}; ++i));
do
if [[ ${ARGS[$i]} == '-p' || ${ARGS[$i]} == '--port' ]]
then
# The port was already extracted, skip over -p and the port number
unset ARGS[$i]
i=${i}+1
unset ARGS[$i]
elif [[ ${ARGS[$i]} == '--permissions' ]]
then
PERMISSIONS_EXPLICITLY_SET="true"
unset ARGS[$i]
i=${i}+1
PERMISSIONS=${ARGS[$i]}
unset ARGS[$i]
elif [[ ${ARGS[$i]} == '--clarity' ]]
then
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-clarity-integration/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--mongo' ]]
then
unset ARGS[$i]
OAK_STORAGE="mongo"
elif [[ ${ARGS[$i]} == '--dev' ]]
then
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards/${CARDS_VERSION}/slingosgifeature/composum
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--debug' ]]
then
unset ARGS[$i]
JAVA_DEBUGGING_FLAGS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
elif [[ ${ARGS[$i]} == '--demo' ]]
then
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-modules-demo-banner/${CARDS_VERSION}/slingosgifeature,mvn:io.uhndata.cards/cards-modules-upgrade-marker/${CARDS_VERSION}/slingosgifeature,mvn:io.uhndata.cards/cards-dataentry/${CARDS_VERSION}/slingosgifeature/forms_demo
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--test' ]]
then
RUNMODE_TEST=true
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-modules-test-forms/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--saml' ]]
then
if [[ ${PERMISSIONS_EXPLICITLY_SET} == 'false' ]]
then
PERMISSIONS="trusted"
fi
SAML_IN_USE="true"
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-saml-support/${CARDS_VERSION}/slingosgifeature/base
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=-C
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=io.dropwizard.metrics:metrics-core:ALL
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-fetch-requires-saml-login/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--keycloak_demo' ]]
then
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-keycloakdemo-saml-support/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--cloud-iam_demo' ]]
then
CLOUD_IAM_DEMO="true"
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-cloud-iam-demo-saml-support/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--uhn_ad_fs' ]]
then
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-uhn-saml-support/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
elif [[ ${ARGS[$i]} == '--slack_notifications' ]]
then
unset ARGS[$i]
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=mvn:io.uhndata.cards/cards-slack-notifications/${CARDS_VERSION}/slingosgifeature
ARGS_LENGTH=${ARGS_LENGTH}+1
else
ARGS[$i]=${ARGS[$i]@P}
ARGS[$i]=${ARGS[$i]//VERSION/${CARDS_VERSION}}
fi
done
PROJECT_SPECIFIED=false
if [ -z $PROJECT_VERSION ]
then
PROJECT_VERSION=$CARDS_VERSION
fi
for ((i=0; i<${ARGS_LENGTH}; ++i));
do
if [[ ${ARGS[$i]} == '-P' || ${ARGS[$i]} == '--project' ]]
then
ARGS[$i]='-f'
i=${i}+1
PROJECTS=${ARGS[$i]//,/ }
ARGS[$i]=''
for PROJECT in $PROJECTS
do
# Support both "cards4project" and just "project": make sure the PROJECT starts with "cards4"
PROJECT="cards4${PROJECT#cards4}"
ARGS[$i]=${ARGS[$i]},mvn:io.uhndata.cards/${PROJECT}/${PROJECT_VERSION}/slingosgifeature,$(CARDS_VERSION=${CARDS_VERSION} PROJECT_NAME=${PROJECT} PROJECT_VERSION=${PROJECT_VERSION} PERMISSIONS=${PERMISSIONS} python3 distribution/get_project_dependency_features.py distribution/sling-features.json)
TEMPDEPDIR=$(mktemp -d)
mvn --quiet --non-recursive dependency:copy -Dartifact=io.uhndata.cards:${PROJECT#cards4}-docker-packaging:${PROJECT_VERSION}:dependencies -DoutputDirectory=${TEMPDEPDIR} 2>&1 > /dev/null
if [[ -f ${TEMPDEPDIR}/${PROJECT#cards4}-docker-packaging-${PROJECT_VERSION}.dependencies ]]
then
ARGS[$i]=${ARGS[$i]%,},$(CARDS_VERSION=${CARDS_VERSION} PROJECT_NAME=${PROJECT} PROJECT_VERSION=${PROJECT_VERSION} PERMISSIONS=${PERMISSIONS} python3 distribution/get_project_dependency_features.py ${TEMPDEPDIR}/*.dependencies)
fi
rm -rf ${TEMPDEPDIR}
PROJECT_SPECIFIED=true
done
ARGS[$i]=${ARGS[$i]#,}
fi
done
if [ $PROJECT_SPECIFIED = false ]
then
ARGS[$ARGS_LENGTH]=-f
ARGS_LENGTH=${ARGS_LENGTH}+1
ARGS[$ARGS_LENGTH]=$(CARDS_VERSION=${CARDS_VERSION} PROJECT_NAME="" PROJECT_VERSION=${PROJECT_VERSION} PERMISSIONS=${PERMISSIONS} python3 distribution/get_project_dependency_features.py distribution/sling-features.json)
ARGS_LENGTH=${ARGS_LENGTH}+1
fi
SMTPS_ENABLED=false
echo "${ARGS[@]}" | grep -q "mvn:io.uhndata.cards/cards-email-notifications/" && SMTPS_ENABLED=true
if [ $SMTPS_ENABLED = true ]
then
if [ -z $SLING_COMMONS_CRYPTO_PASSWORD ]
then
handle_missing_sling_commons_crypto_warning
export SLING_COMMONS_CRYPTO_PASSWORD=password
fi
if [ ! -e ~/.mailcap ]
then
handle_missing_mailcap_fail
fi
diff -q ~/.mailcap distribution/mailcap || warn_different_mailcap
fi
if [ $SAML_IN_USE = true ]
then
if [ $CLOUD_IAM_DEMO = true ]
then
HEADERMOD_PROXY_LISTEN_PORT=8080
else
HEADERMOD_PROXY_LISTEN_PORT=9090
fi
if [ $HEADERMOD_PROXY_LISTEN_PORT = $BIND_PORT ]
then
message_saml_proxy_port_conflict_fail
exit -1
fi
fi
ERROR_LOG_LAST_MODIFIED_TIME_ORIGIN=$(get_error_log_last_modified)
#Start CARDS in the background
java ${JAVA_DEBUGGING_FLAGS} -Djdk.xml.entityExpansionLimit=0 -Dorg.osgi.service.http.port=${BIND_PORT} -jar distribution/target/dependency/org.apache.sling.feature.launcher.jar -u "file://$(realpath .mvnrepo),file://$(realpath "${HOME}/.m2/repository"),https://nexus.phenotips.org/nexus/content/groups/public,https://repo.maven.apache.org/maven2,https://repository.apache.org/content/groups/snapshots" -p .cards-data -c .cards-data/cache -f mvn:io.uhndata.cards/cards/${CARDS_VERSION}/slingosgifeature/core_${OAK_STORAGE} "${ARGS[@]}" &
CARDS_PID=$!
if [ ! -z "$JAVA_DEBUGGING_FLAGS" ]
then
message_connect_jdb
# As soon as we see CARDS writing to .cards-data/logs/error.log, we
# can conclude that JDB has attached to the Java process.
while (( $(echo "$(get_error_log_last_modified) <= $ERROR_LOG_LAST_MODIFIED_TIME_ORIGIN" | bc -l) ))
do
sleep 5
echo "Waiting for JDB attachment..."
done
fi
#Check to see if CARDS was able to bind to the TCP port
#This is the more robust test that works only if psutil is installed
if [ $PSUTIL_INSTALLED = true ]
then
for bind_test in `seq 0 $BIND_TESTS`
do
#Check if we have timed out
if [ $bind_test = $BIND_TESTS ]
then
kill $CARDS_PID
wait $CARDS_PID
handle_tcp_bind_fail
fi
sleep $BIND_TEST_SPACING
#Check if CARDS was able to bind
python3 Utilities/HostConfig/check_tcp_listen.py --tcp_port $BIND_PORT --pid $CARDS_PID && break
#If the CARDS Java process has terminated, stop this script altogether
check_cards_running || handle_cards_java_fail
done
fi
if [ $PSUTIL_INSTALLED = true ]
then
handle_tcp_bind_ok_optimal
else
handle_tcp_bind_ok_suboptimal
fi
#Wait for CARDS to be ready
while true
do
echo "Waiting for CARDS to start"
#If the CARDS Java process has terminated, stop this script altogether
check_cards_running || handle_cards_java_fail
curl --fail $CARDS_URL/system/sling/info.sessionInfo.json > /dev/null 2> /dev/null && break
sleep 5
done
#Check if we are in the test runMode
if [ $RUNMODE_TEST = true ]
then
#If a BIOPORTAL_APIKEY is present, attempt to install HANCESTRO
if [ ! -z $BIOPORTAL_APIKEY ]
then
#Check if HANCESTRO is already installed
if [ -z $ADMIN_PASSWORD ]
then
ADMIN_PASSWORD="admin"
fi
curl -u admin:$ADMIN_PASSWORD --fail $CARDS_URL/Vocabularies/HANCESTRO.json > /dev/null 2> /dev/null \
&& HANCESTRO_INSTALLED=true || HANCESTRO_INSTALLED=false
if [ $HANCESTRO_INSTALLED = false ]
then
python3 Utilities/Administration/install_vocabulary.py --bioportal_id HANCESTRO \
&& message_hancestro_install_ok || message_hancestro_install_fail
else
echo "HANCESTRO already installed"
fi
else
message_bioportal_apikey_missing
fi
fi
#Check if we are using the Cloud-IAM.com demo
if [ $CLOUD_IAM_DEMO = true ]
then
(cd Utilities/Administration/SAML/ && sha256sum -c cloud-iam_demo_samlKeystore.p12.sha256sum && message_sha256_cloud_iam_ok || message_sha256_cloud_iam_error)
KEYCLOAK_HEADERMOD_HTTP_PROXY_KEYCLOAK_ENDPOINT="https://lemur-15.cloud-iam.com/auth/realms/uhn-cards-test/protocol/saml"
fi
#Check if we are using SAML
if [ $SAML_IN_USE = true ]
then
# Start a keycloak_headermod_http_proxy.js in the background
if [ -z $KEYCLOAK_HEADERMOD_HTTP_PROXY_KEYCLOAK_ENDPOINT ]
then
nodejs Utilities/Development/keycloak_headermod_http_proxy.js \
--listen-port=$HEADERMOD_PROXY_LISTEN_PORT \
--cards-port=$BIND_PORT &
KEYCLOAK_HEADERMOD_HTTP_PROXY_PID=$!
else
nodejs Utilities/Development/keycloak_headermod_http_proxy.js \
--listen-port=$HEADERMOD_PROXY_LISTEN_PORT \
--cards-port=$BIND_PORT \
--keycloak-endpoint=$KEYCLOAK_HEADERMOD_HTTP_PROXY_KEYCLOAK_ENDPOINT &
KEYCLOAK_HEADERMOD_HTTP_PROXY_PID=$!
fi
fi
message_started_cards
#Stop this script if the CARDS process terminates in failure
wait $CARDS_PID
if [ ! -z $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID ]
then
kill $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID
wait $KEYCLOAK_HEADERMOD_HTTP_PROXY_PID
fi
handle_cards_java_fail