-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepad_manage.sh
More file actions
executable file
·368 lines (312 loc) · 12.8 KB
/
epad_manage.sh
File metadata and controls
executable file
·368 lines (312 loc) · 12.8 KB
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
#!/bin/bash
# $1 expected install, start, stop, update
# $2 expected a version master,latest,v0.1, v0.2
var_path=$(pwd)
#echo "epad will be installed in : $var_path"
# sytem configuration variables
var_version="master"
var_epadDistLocation="epad-dist"
var_epadLiteDistLocation="epad_lite_dist"
var_response=""
var_host="localhost"
var_mode="lite" # or thick
var_config="environment" # or nothing
var_container_mode="image" # or build
var_couchdb_location="couchdblocation"
var_mariadb_location="mariadblocation"
var_branch="master" # used for epad_lite and epad_js containers
# user name and passwords for containers
var_keycloak_user="admin"
var_keycloak_pass="admin"
var_keycloak_useremail="admin@gmail.com"
var_maria_user="admin"
var_maria_pass="admin"
var_maria_rootpass="admin"
# keycloak eport settings
# ! keep /tmp/ in case you want to edit the file name epad_realm.josn
var_keycloak_export="/tmp/epad_realm.json"
var_realmName="ePad"
var_provider="singleFile"
#echo "\$1:$1"
#read -p 'maria pass ? : ' var_response
#echo $var_maria_rootpass
# functions
copy_epad_dist (){
var_response="n"
if [[ -d "$var_path/$var_epadDistLocation" ]]; then
read -p "epad-dist exist already exist do you want to owerwrite ? (y/n) (defult value is n): " var_response
else
cd $var_path
git clone -b script https://github.com/RubinLab/epad-dist.git
fi
if [[ "$var_response" -eq "y" ]]; then
echo "copying epad-dist repo from git"
rm -rf "$var_path/$var_epadDistLocation"
cd $var_path
git clone -b script https://github.com/RubinLab/epad-dist.git
fi
}
create_epad_lite_dist(){
var_response="n"
if [ -d "$var_path/$var_epadLiteDistLocation" ]; then
read -p "epad_lite_dist folder exist already do you want to owerwrite ? (y/n) (defult value is n): " var_response
else
cd "$var_path/$var_epadDistLocation"
./configure_epad.sh ../$var_epadLiteDistLocation ./epad.yml
fi
if [ $var_response == "y" ]; then
echo "creating $var_epadLiteDistLocation folder"
rm -rf "$var_path/$var_epadLiteDistLocation"
cd "$var_path/$var_epadDistLocation"
./configure_epad.sh ../$var_epadLiteDistLocation ./epad.yml
fi
}
stop_containers_all (){
#export_keycloak
#echo $!
#result=""
#while [[ -z $result ]]; do
# result=$(cat exportkeycloak.log | grep "Export finished successfully")
#done
#echo $result
cd "$var_path/$var_epadLiteDistLocation"
docker-compose stop
}
start_containers_all (){
cd "$var_path/$var_epadLiteDistLocation"
docker-compose start
linecount=0
counter=0
var_waiting="starting epad"
while [[ "$linecount" -ne "4" ]]; do
counter=$((counter+1))
linecount=$(docker ps -a | grep healthy | wc -l)
if [[ $counter -ge 0 ]]; then
var_waiting="$var_waiting."
echo -en "$var_waiting\r"
sleep 1
fi
if [[ "$counter" -eq "10" ]]; then
echo -en 'starting epad \r'
counter=0
var_waiting="starting epad"
fi
done
echo "epad is ready to browse : $var_host"
}
start_containers_viaCompose_all (){
cd "$var_path/$var_epadLiteDistLocation"
ls
docker-compose up -d
linecount=0
counter=0
var_waiting="starting epad"
while [[ "$linecount" -ne "4" ]]; do
counter=$((counter+1))
linecount=$(docker ps -a | grep healthy | wc -l)
if [[ $counter -ge 0 ]]; then
var_waiting="$var_waiting."
echo -en "$var_waiting\r"
sleep 1
fi
if [[ "$counter" -eq "10" ]]; then
echo -en ' \r'
counter=0
var_waiting="starting epad"
fi
done
echo "epad is ready to browse: $var_host"
}
collect_system_configuration(){
var_response=""
read -p "hostname (default value : localhost) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_host=$var_response
echo "host name : $var_host"
fi
read -p "mode (default value : $var_mode) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_mode=$var_response
echo "mode : $var_mode"
fi
read -p "confiduration (default value : $var_config) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_config=$var_response
echo "config : $var_config"
fi
read -p "maria db location (default value : $var_mariadb_location) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_mariadb_location=$var_response
echo "mariadb_location : $var_mariadb_location"
fi
read -p "couch db location (default value : $var_couchdb_location) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_couchdb_location=$var_response
echo "couchdb location : $var_couchdb_location"
fi
}
collect_user_credentials (){
var_response=""
read -p "keycloak user name (default value : $var_keycloak_user) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_keycloak_user=$var_response
echo "var_keycloak_user : $var_keycloak_user"
fi
read -sp "keycloak user password (default value : $var_keycloak_pass) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_keycloak_pass=$var_response
echo "var_keycloak_pass : $var_keycloak_pass"
fi
printf '\n'
read -p "keycloak user email (default value : $var_keycloak_useremail) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_keycloak_useremail=$var_response
echo "var_keycloak_useremail : $var_keycloak_useremail"
fi
read -p "maria db user name (default value : $var_maria_user) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_maria_user=$var_response
echo "var_maria_user : $var_maria_user"
fi
read -sp "maria db user password (default value : $var_maria_pass) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_maria_pass=$var_response
echo "var_maria_pass : $var_maria_pass"
fi
printf '\n'
echo $var_response
read -sp "maria db root password (default value : $var_maria_rootpass) :" var_response
if [[ -n "$var_response" ]]
then
echo "response = $var_response"
var_maria_rootpass=$var_response
echo "var_maria_rootpass : $var_maria_rootpass"
fi
printf '\n'
}
edit_epad_yml (){
sed -i -e "s/host:.*/host: $var_host/g" "$var_epadDistLocation/epad.yml"
#sed -i -e "s/mode:.*/mode: $var_mode/g" "$var_epadDistLocation/epad.yml"
awk -v var_awk="mode: $var_mode" '/mode.*/{c++; if (c==1) { sub("mode.*",var_awk) } }1' "$var_path/$var_epadDistLocation/epad.yml" > "$var_path/$var_epadDistLocation/tempEpad.yml" && mv "$var_path/$var_epadDistLocation/tempEpad.yml" "$var_path/$var_epadDistLocation/epad.yml"
sed -i -e "s/config:.*/config: $var_config/g" "$var_epadDistLocation/epad.yml"
#sed -i -e "s/user:.*/user: $var_keycloak_user/g" "$var_epadDistLocation/epad.yml"
awk -v var_awk="user: $var_keycloak_user" '/user.*/{c++; if (c==1) { sub("user.*",var_awk) } }1' "$var_path/$var_epadDistLocation/epad.yml" > "$var_path/$var_epadDistLocation/tempEpad.yml" && mv "$var_path/$var_epadDistLocation/tempEpad.yml" "$var_path/$var_epadDistLocation/epad.yml"
sed -i -e "s/password:.*/password: $var_keycloak_pass/g" "$var_epadDistLocation/epad.yml"
sed -i -e "s/email:.*/email: $var_keycloak_useremail/g" "$var_epadDistLocation/epad.yml"
#sed -i -e "s/user:.*/user: $var_maria_user/g" "$var_epadDistLocation/epad.yml"
sed -i -e "s/pass:.*/pass: $var_maria_pass/g" "$var_epadDistLocation/epad.yml"
sed -i -e "s/rootpass:.*/rootpass: $var_maria_rootpass/g" "$var_epadDistLocation/epad.yml"
awk -v var_awk="user: $var_maria_user" '/user.*/{c++; if (c==2) { sub("user.*",var_awk) } }1' "$var_path/$var_epadDistLocation/epad.yml" > "$var_path/$var_epadDistLocation/tempEpad.yml" && mv "$var_path/$var_epadDistLocation/tempEpad.yml" "$var_path/$var_epadDistLocation/epad.yml"
}
import_keycloak(){
echo "importing keycloak users...."
docker exec -i epad_keycloak /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=import \
-Dkeycloak.migration.provider=$var_provider \
-Dkeycloak.migration.realmName=$var_realmName \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=$var_keycloak_export > importkeycloak.log &
echo $! > "$var_path/pid.txt"
echo $!
result=""
while [[ -z $result ]]; do
result=$(cat $var_path/exportkeycloak.log | grep "Export finished successfully")
done
echo $result
}
export_keycloak(){
echo "eporting keycloak users....\n"
docker exec -i epad_keycloak /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=$var_provider \
-Dkeycloak.migration.realmName=$var_realmName \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=$var_keycloak_export > exportkeycloak.log &
echo $! > "$var_path/pid.txt"
echo $!
result=""
while [[ -z $result ]]; do
result=$(cat $var_path/exportkeycloak.log | grep "Export finished successfully")
done
echo $result
}
show_instructions(){
echo "you need to provide arguments "
echo "script example usage :"
echo "epad_manage.sh install"
echo "epad_manage.sh start"
echo "epad_manage.sh stop"
echo "epad_manage.sh update v0.1"
echo "epad_manage.sh update epad verison"
echo "epad_manage.sh update epad user"
}
# main
if [ "$#" -gt 0 ]; then
if [[ $1 = "install" ]]; then
echo "epad will be installed in : $var_path"
if [[ -d "$var_path/tmp" ]]; then
echo "tmp dir exist already"
else
mkdir "$var_path/tmp"
chmod 777 "$var_path/tmp"
fi
#stop_containers_all
copy_epad_dist
collect_system_configuration
collect_user_credentials
edit_epad_yml
create_epad_lite_dist
start_containers_viaCompose_all
var_check=0
#while [[ "$var_check" -eq "0" ]]
#do
# if [ -d "$var_path/$var_epadLiteDistLocation" ]; then
# start_containers_viaCompose_all
# var_check=1
# fi
#done
fi
if [[ $1 = "start" ]]; then
start_containers_all
fi
if [[ $1 = "stop" ]]; then
stop_containers_all
fi
if [[ $1 = "update" ]]; then
if [[ $2 = "epad" ]]; then
echo "update epad"
export_keycloak
stop_containers_all
cd "$var_path/$var_epadLiteDistLocation"
docker-compose build --no-cache
start_containers_viaCompose_all
import_keycloak
elif [[ $2 = "user" ]]; then
echo "update user"
else
show_instructions
fi
fi
else
show_instructions
fi