forked from RubinLab/epad-dist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_epad.sh
executable file
·329 lines (306 loc) · 9.73 KB
/
configure_epad.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
# based on https://github.com/jasperes/bash-yaml/blob/master/test/test.sh
add_backslash(){
#$1 is the parameter passed to this function
#echo "adding backslash"
var_tmp_txt=$(echo $1 | sed 's-/-\\/-g')
echo $var_tmp_txt
}
replace_in_files(){
for file in ./$3/*
do
if [[ -f $file ]]
then
sed -i -e "s/$1/$2/g" "$file"
else
for inner_file in $file/*
do
if [[ -f $inner_file ]]
then
sed -i -e "s/$1/$2/g" "$inner_file"
fi
done
if [ "$(uname)" == "Darwin" ]; then
rm $file/*-e
fi
fi
done
if [ "$(uname)" == "Darwin" ]; then
rm ./$3/*-e
fi
}
if [[ $# != 2 ]]
then
echo "Wrong number of parameters. $Configuration script needs a folder and a yml file to run. Ex: ./$configure_epad.sh ../epad_lite_dist ./epad.yml"
exit 1
fi
# read yml file and create environment variables
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
source ./yaml.sh
parse_yaml $2 > .env
create_variables $2
# do it before deleting
if [[ -z $couchdb_user || -z $couchdb_password ]]
then
echo "yml file doesn't have user and password information for couchdb, please add them to your yml and run again"
exit 1
fi
if [ -d "./$1" ]
then
echo "$1 folder already exists. Do you want to replace the $1 installation with the new files? This will cause $configurations to be resetted. "
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -rf ./$1
else
exit 1
fi
fi
mkdir $1
cp -R ./.originals/* ./$1/.
cp ./epaddb_nodata.sql ./$1/.
cat ./$1/docker-compose_start.ymlpart > ./$1/docker-compose.yml
# both cache and compression
if [[ ! -z $cache_size && ! -z $cache_inactivetime && ! -z $compression_minsize ]]
then
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/nginx_start_compress_cache_https.confpart > ./$1/nginx.conf
else
cat ./$1/nginx_start_compress_cache.confpart > ./$1/nginx.conf
fi
else
# cache only
if [[ ! -z $cache_size && ! -z $cache_inactivetime ]]
then
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/nginx_start_cache_https.confpart > ./$1/nginx.conf
else
cat ./$1/nginx_start_cache.confpart > ./$1/nginx.conf
fi
else
# compress only
if [[ ! -z $compression_minsize ]]
then
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/nginx_start_compress_https.confpart > ./$1/nginx.conf
else
cat ./$1/nginx_start_compress.confpart > ./$1/nginx.conf
fi
else
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/nginx_start_https.confpart > ./$1/nginx.conf
else
cat ./$1/nginx_start.confpart > ./$1/nginx.conf
fi
fi
fi
fi
if [ $epadjs_mode != 'external' ]
then
if [[ ! -z $epadjs_dockerfiledir ]]
then
if [[ $config == 'environment' ]]
then
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/docker-compose_epadjs_build_env_https.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_epadjs_build_env.ymlpart >> ./$1/docker-compose.yml
fi
else
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/docker-compose_epadjs_build_https.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_epadjs_build.ymlpart >> ./$1/docker-compose.yml
fi
fi
else
if [[ $config == 'environment' ]]
then
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/docker-compose_epadjs_env_https.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_epadjs_env.ymlpart >> ./$1/docker-compose.yml
fi
else
if [[ ! -z $https && $https == true && ! -z $certdir && ! -z $certfile && ! -z $certkeyfile ]]
then
cat ./$1/docker-compose_epadjs_https.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_epadjs.ymlpart >> ./$1/docker-compose.yml
fi
fi
fi
fi
if [ $keycloak_mode != 'external' ]
then
if [[ ! -z $keycloak_loc ]]
then
if [ $epadjs_port != '80' ]
then
cat ./$1/nginx_keycloak_port.confpart >> ./$1/nginx.conf
else
cat ./$1/nginx_keycloak.confpart >> ./$1/nginx.conf
fi
fi
if [[ ! -z $keycloak_dockerfiledir ]]
then
cat ./$1/docker-compose_keycloak_build.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_keycloak.ymlpart >> ./$1/docker-compose.yml
fi
fi
if [ $couchdb_mode != 'external' ]
then
if [[ ! -z $couchdb_loc ]]
then
cat ./$1/nginx_couchdb.confpart >> ./$1/nginx.conf
fi
if [[ ! -z $couchdb_user && ! -z $couchdb_password ]]
then
cat ./$1/docker-compose_couchdb.ymlpart >> ./$1/docker-compose.yml
else
# duplicate check, leaving just in case
echo "yml file doesn't have user and password information for couchdb, please add them to your yml and run again"
exit 1
fi
fi
if [ $mariadb_mode != 'external' ]
then
if [[ ! -z $mariadb_loc ]]
then
cat ./$1/nginx_mariadb.confpart >> ./$1/nginx.conf
fi
if [[ ! -z $mariadb_dockerfiledir ]]
then
cat ./$1/docker-compose_mariadb_build.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_mariadb.ymlpart >> ./$1/docker-compose.yml
fi
fi
if [ $dicomweb_mode != 'external' ]
then
if [[ ! -z $dicomweb_loc ]]
then
cat ./$1/nginx_dicomweb.confpart >> ./$1/nginx.conf
fi
if [[ ! -z $dicomweb_dockerfiledir ]]
then
if [[ $config == 'environment' ]]
then
cat ./$1/docker-compose_dicomweb_build_env.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_dicomweb_build.ymlpart >> ./$1/docker-compose.yml
fi
else
if [[ $config == 'environment' ]]
then
cat ./$1/docker-compose_dicomweb_env.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_dicomweb.ymlpart >> ./$1/docker-compose.yml
fi
fi
fi
if [ $epadlite_mode != 'external' ]
then
if [[ ! -z $epadlite_loc ]]
then
if [[ ! -z $cache_size && ! -z $cache_inactivetime ]]
then
cat ./$1/nginx_epadlite_cache.confpart >> ./$1/nginx.conf
else
cat ./$1/nginx_epadlite.confpart >> ./$1/nginx.conf
fi
fi
if [[ ! -z $epadlite_dockerfiledir ]]
then
if [[ $config == 'environment' ]]
then
cat ./$1/docker-compose_epadlite_build_env.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_epadlite_build.ymlpart >> ./$1/docker-compose.yml
fi
else
if [[ $config == 'environment' ]]
then
cat ./$1/docker-compose_epadlite_env.ymlpart >> ./$1/docker-compose.yml
else
cat ./$1/docker-compose_epadlite.ymlpart >> ./$1/docker-compose.yml
fi
fi
fi
cat ./$1/docker-compose_end.ymlpart >> ./$1/docker-compose.yml
cat ./$1/nginx_end.confpart >> ./$1/nginx.conf
rm ./$1/*.ymlpart
rm ./$1/*.confpart
if [[ $config == 'environment' ]]
then
rm ./$1/production_*.js*
fi
if [[ $epadjs_port != '80' && $epadjs_port != '443' ]]
then
replace_in_files "{host}" "{host}:{epadjs_port}" $1
fi
# update for externals
if [ $keycloak_mode == 'external' ]
then
replace_in_files "{host}\/{keycloak_loc}" "{keycloak_uri}" $1
fi
if [ $couchdb_mode == 'external' ]
then
echo "External couchdb is not supported for now"
fi
if [ $mariadb_mode == 'external' ]
then
echo "External mariadb is not supported for now"
fi
if [ $dicomweb_mode == 'external' ]
then
replace_in_files "{host}\/{dicomweb_loc}" "{dicomweb_uri}" $1
replace_in_files "epad_dicomweb:8090\/{dicomweb_loc}" "{dicomweb_uri}" $1
fi
if [ $epadlite_mode == 'external' ]
then
echo "External api is not supported for now"
fi
if [[ ! -z $epadlite_branch && $epadlite_mode == 'build' ]]
then
epadlite_branch=$( add_backslash $epadlite_branch)
replace_in_files "git clone" "git clone -b $epadlite_branch" "$1/epadlite"
fi
if [[ ! -z $dicomweb_branch && $dicomweb_mode == 'build' ]]
then
dicomweb_branch=$( add_backslash $dicomweb_branch)
replace_in_files "git clone" "git clone -b $dicomweb_branch" "$1/dicomweb-server"
fi
if [[ ! -z $epadjs_branch && $epadjs_mode == 'build' ]]
then
epadjs_branch=$( add_backslash $epadjs_branch)
replace_in_files "git clone" "git clone -b $epadjs_branch" "$1/epadjs"
fi
# image change to ibm
if [[ $couchdb_image == ibmcom/couchdb3* ]]
then
replace_in_files "apache\/couchdb:" "" $1
fi
while read -r line
do
IFS='=' # delimeter
read -ra ENV <<< "$line"
replace_in_files "{${ENV[0]}}" ${ENV[1]} $1
done < .env
IFS=' '
# support https in hostname
replace_in_files "http:\/\/https:\/\/" "https:\/\/" $1
# support empty values
replace_in_files "{epadjs_baseurl}" "" $1
replace_in_files "{epadjs_authmode}" "" $1
mv ./$1/nginx.conf ./$1/epadjs/.
cp ./$1/epaddb_nodata.sql ./$1/mariadb/.