-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·416 lines (354 loc) · 13.6 KB
/
install.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
#!/bin/bash
#POSIX
usage() {
echo "Usage:"
echo " $0 [DATABASE ARGS] [RESOURCE] [options] [RESOURCE ARGS...]"
echo " $0 -h|--help"
echo ""
echo "Database Args:"
echo " -h, --host HOST database host [default: \$IRCT_DB_HOST]"
echo " -u, --user USER database user [default: \$IRCT_DB_CONNECTION_USER]"
echo " -p, --password PASSWORD database password [default: \$IRCT_DB_PASSWORD]"
echo ""
echo "Resources:"
echo " -r, --resource TYPE resource to install"
echo ""
echo "Available Resource TYPE:"
echo " i2b2transmart-NAME"
echo " i2b2-wildfly-NAME"
echo " scidb-NAME"
echo " i2b2.org"
echo " dataconverters"
echo " monitor"
echo " capitalization"
echo " aws"
echo ""
echo ""
echo "Options:"
echo " --delete true|false delete resource"
echo " --confirm true|false confirm resource is installed [default: false]"
echo ""
echo "Resource Args:"
echo " i2b2transmart-NAME:"
echo " --resource-url URL [required] i2b2transmart URL"
echo " --auth0-id CLIENT_ID [required] Auth0 Client Id"
echo " --auth0-domain DOMAIN [required] Auth0 Domain"
echo ""
echo " i2b2-wildfly-NAME:"
echo " --simple true|false count only install [default: false]"
echo " --resource-url URL i2b2-wildfly URL [default: http://i2b2-wildfly:9090/i2b2/services/] "
echo " --resource-user USER i2b2 user [default: demo]"
echo " --resource-pass PASSWORD i2b2 password [default: demouser]"
echo " --resource-domain DOMAIN i2b2 domain [default: i2b2demo]"
echo ""
echo " scidb-NAME:"
echo " --resource-url URL [required] SciDB host"
echo " --resource-user USER [required] SciDB user"
echo " --resource-pass PASSWORD [required] SciDB password"
echo " --afl-enabled true|false use SciDB's Array Functional Language [default: false]"
echo ""
echo " aws:"
echo " --bucket NAME [required] AWS S3 bucket"
echo ""
echo "Unavailable Resources:"
echo " hail"
echo " gnome"
echo " exac"
echo " umls"
echo ""
if [ "$1" ]; then
echo ""
echo $1
fi
exit 1;
}
die() {
printf '%s\n' "$1" >&2
exit 1
}
param() {
case $1 in
$3|$4)
if [ "$2" ]; then
echo "$2"
else
die "ERROR: "${4}" requires a non-empty option argument."
fi
;;
esac
}
host=${IRCT_DB_HOST}
user=${IRCT_DB_CONNECTION_USER}
pass=${IRCT_DB_PASSWORD}
db=irct
simple=false
bucket=
confirm=false
delete=false
resource=
resourceurl=
resourceuser=
resourcepass=
resourcedomain=
auth0id=
auth0domain=
scidbafl=false
while :; do
case $1 in
-h|-\?|--help)
usage # Display a usage synopsis.
exit $?
;;
-h|--host)
host=$(param $1 $2 "-h" "--host")
;;
-u|--user)
user=$(param $1 $2 "-u" "--user")
;;
-p|--password)
pass=$(param $1 $2 "-p" "--password")
;;
-d|--database)
db=$(param $1 $2 "-d" "--database")
;;
-r|--resource)
resource=$(param $1 $2 "-r" "--resource")
;;
--confirm)
confirm=$(param $1 $2 "--confirm" "--confirm")
;;
--delete)
delete=$(param $1 $2 "--delete" "--delete")
;;
--resource-url)
resourceurl=$(param $1 $2 "--resource-url" "--resource-url")
;;
--simple)
simple=$(param $1 $2 "--simple" "--simple")
;;
--resource-user)
resourceuser=$(param $1 $2 "--resource-user" "--resource-user")
;;
--resource-domain)
resourcedomain=$(param $1 $2 "--resource-domain" "--resource-domain")
;;
--resource-pass)
resourcepass=$(param $1 $2 "--resource-pass" "--resource-pass")
;;
--bucket)
bucket=$(param $1 $2 "--bucket" "--bucket")
;;
--auth0-id)
auth0id=$(param $1 $2 "--auth0-id" "--auth0-id")
;;
--auth0-domain)
auth0domain=$(param $1 $2 "--auth0-domain" "--auth0-domain")
;;
--afl-enabled)
scidbafl=$(param $1 $2 "--afl-enabled" "--afl-enabled")
;;
--) # End of all options.
shift
break
;;
-?*)
die "ERROR: Unknown option: $1"
;;
*) # Default case: No more options, so break out of the loop.
break
;;
esac
if [ "$2" ]; then
shift
fi
shift
done
if [ -z "${host}" ] || [ -z "${user}" ] || [ -z "${pass}" ] || [ -z "${db}" ] || [ -z "${resource}" ]; then
usage "ERROR: required: --host, --user, --password, --database, --resource"
fi
# confirm connection to database
echo "check IRCT DB connection"
{
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SHOW SESSION STATUS LIKE 'Com_show_status';"
} || {
exit $?
}
if [ "${confirm}" == "true" ]; then
echo "confirm *only* IRCT DB populated"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SELECT * FROM Resource"
exit $?
fi
if [ "${delete}" == "true" ]; then
echo "--delete not yet implemented"
exit $?
fi
{
# I2B2TranSMARTResource
if [[ "${resource}" =~ ^i2b2transmart\-(.+)$ ]]; then
specificName="${BASH_REMATCH[1]}";
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM Resource WHERE name = '${specificName}'"`
if [ ${count} -gt 0 ]; then
echo "i2b2tranSMART Resource ${specificName} already exists"
else
if [ -z "${resourceurl}" ] || [ -z "${auth0id}" ] || [ -z "${auth0domain}" ]; then
usage "ERROR: [required] --resource-url i2b2tranSMART URL --auth0-id CLIENT_ID --auth0-domain DOMAIN"
fi
echo "add i2b2tranSMART Resource to IRCT DB"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SET @resourceName='${specificName}'; \
SET @auth0ClientId='${auth0id}'; \
SET @auth0Domain='${auth0domain}'; \
SET @transmartURL='${resourceurl}'; \
SET @resourceURL='${resourceurl}/transmart/proxy?url=http://localhost:9090/i2b2/services/'; \
source ./resource/i2b2transmart/create.sql;"
echo "confirm IRCT DB populated"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SELECT * FROM Resource"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SELECT * FROM resource_parameters WHERE name = 'resourceURL';"
fi
fi
# end I2B2Transmart
# Monitoring
if [ "${resource}" == "monitor" ]; then
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM EventConverterImplementation WHERE name LIKE 'Monitoring%';"`
if [ ${count} -gt 0 ]; then
echo "Monitor configuration already exists"
else
mysql --host=${host} --user=${user} --password=${pass} ${db} < ./event/Monitoring.sql
echo "confirm Monitor added"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SELECT * FROM EventConverterImplementation WHERE name LIKE 'Monitoring%';"
fi
fi
# end Monitor
# data converters
if [ "${resource}" == "dataconverters" ]; then
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e \
"SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); \
SELECT COUNT(*) FROM DataConverterImplementation;"`
if [ ${count} -gt 0 ]; then
echo "Data Converters already exist"
else
mysql --host=${host} --user=${user} --password=${pass} ${db} < ./config/ResultDataConverters.sql
echo "confirm Data Converters added"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SELECT * FROM DataConverterImplementation;"
fi
fi
# end data converters
# SciDB Resource
if [[ "${resource}" =~ scidb\-(.+)$ ]]; then
specificName="${BASH_REMATCH[1]}";
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM Resource WHERE name = '${resource}'"`
if [ ${count} -gt 0 ]; then
echo "SciDB ${resource} already exists"
else
if [ -z "${resourceurl}" ] || [ -z "${resourceuser}" ] || [ -z "${resourcepass}" ]; then
usage "ERROR: [required] --resource-url sciDB URL --resource-user sciDB user --resource-pass sciDB password"
fi
resourcetype="scidb"
if [ "${scidbafl}" == "true" ]; then
resourcetype="scidbafl"
fi
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SET @resourceName='${resource}'; \
SET @resourceURL='${resourceurl}'; \
SET @userName='${resourceuser}'; \
SET @password='${resourcepass}'; \
source ./resource/${resourcetype}/create.sql;"
echo "confirm IRCT DB populated"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SELECT * FROM Resource"
fi
fi
# end SciDB Resource
# i2b2.org Resource
if [ "${resource}" == "i2b2.org" ]; then
# i2b2.org resource
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM Resource WHERE name = 'i2b2-i2b2-org'"`
if [ ${count} -gt 0 ]; then
echo "i2b2.org resource already exists"
else
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"source ./resource/i2b2passthrough/create.sql;"
echo "confirm IRCT DB populated"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SELECT * FROM Resource"
fi
fi
# end i2b2.org Resource
# i2b2 local Resource
if [[ "${resource}" =~ ^i2b2\-wildfly\-(.+)$ ]]; then
specificName="${BASH_REMATCH[1]}";
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM Resource WHERE name = '${resource}'"`
if [ ${count} -gt 0 ]; then
echo "i2b2 wildfly ${specificName} resource already exists"
else
resourcetype="i2b2"
if [ "${simple}" == "true" ]; then
resourcetype="i2b2_count_only"
echo "add i2b2-wildfly ${specificName} resource (counts only) to IRCT DB"
else
echo "add i2b2-wildfly ${specificName} resource to IRCT DB"
fi
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SET @resourceName ='${resource}'; \
SET @resourceURL='${resourceurl}'; \
SET @domain='${resourcedomain}'; \
SET @userName='${resourceuser}'; \
SET @password='${resourcepass}'; \
source ./resource/${resourcetype}/create.sql;"
echo "confirm IRCT DB populated"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e "SELECT * FROM Resource"
fi
fi
# end i2b2 local resource
# Capitalization
if [ "${resource}" == "capitalization" ]; then
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM EventConverterImplementation WHERE name LIKE 'Capitalization%';"`
if [ ${count} -gt 0 ]; then
echo "Capitalization configuration already exists"
else
mysql --host=${host} --user=${user} --password=${pass} ${db} < /scratch/irct/sql/event/Capitalization.sql
echo "confirm Capitalization added"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SELECT * FROM EventConverterImplementation WHERE name LIKE 'Capitalization%';"
fi
fi
# end Capitalization
# UMLS Synonyms
# NOTE: Incomplete. Requires handling parameters: connection string, username, password
if [ "${resource}" == "umls" ]; then
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM EventConverterImplementation WHERE name LIKE 'UMLS%';"`
if [ ${count} -gt 0 ]; then
echo "UMLS Synonyms configuration already exists"
else
mysql --host=${host} --user=${user} --password=${pass} ${db} < /scratch/irct/sql/event/UMLSSynonym.sql
echo "confirm UMLS Synonyms added"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SELECT * FROM EventConverterImplementation WHERE name LIKE 'UMLS%';"
fi
fi
# end UMLS Synonyms
# AWS S3 bucket
# NOTE: @resourceName and @resultDataFolder are configurable but we just use the defaults
# installing AWS S3 will *not* work if you choose to change the Result Data Folder in IRCT application - Andre
if [ "${resource}" == "aws" ]; then
# Added extra character. bash can act weird with -n on empty strings
if [ "x${bucket}" == "x" ]; then
usage "ERROR: [required] --bucket NAME"
fi
count=`mysql --host=${host} --user=${user} --password=${pass} ${db} -ss -e "SELECT COUNT(*) FROM event_parameters WHERE name='Bucket Name';"`
if [ ${count} -gt 0 ]; then
echo "AWS S3 Bucket configuration already exists"
else
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SET @S3BucketName='${bucket}'; \
source ./event/AWS-S3.sql;"
echo "confirm S3 Bucket added"
mysql --host=${host} --user=${user} --password=${pass} ${db} -e \
"SELECT * FROM event_parameters WHERE name='Bucket Name';"
fi
fi
# end AWS S3 bucket
} || {
exit $?
}