-
Notifications
You must be signed in to change notification settings - Fork 54
/
zebrunner.sh
executable file
·692 lines (573 loc) · 21.5 KB
/
zebrunner.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
#!/bin/bash
print_banner() {
echo "
███████╗███████╗██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗ ██████╗███████╗
╚══███╔╝██╔════╝██╔══██╗██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗ ██╔════╝██╔════╝
███╔╝ █████╗ ██████╔╝██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝ ██║ █████╗
███╔╝ ██╔══╝ ██╔══██╗██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗ ██║ ██╔══╝
███████╗███████╗██████╔╝██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║ ╚██████╗███████╗
╚══════╝╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═════╝╚══════╝
"
}
setup() {
print_banner
if [ "$1" == "-d" ]; then
set -x
fi
# load default interactive installer settings
# shellcheck disable=SC1091
source backup/settings.env.original
# load ./backup/settings.env if exist to declare ZBR* vars from previous run!
if [[ -f backup/settings.env ]]; then
source backup/settings.env
fi
export ZBR_INSTALLER=1
export ZBR_VERSION=2.5
set_global_settings
cp .env.original .env
replace .env "ZBR_PORT=80" "ZBR_PORT=${ZBR_PORT}"
cp nginx/conf.d/default.conf.original nginx/conf.d/default.conf
replace ./nginx/conf.d/default.conf "server_name localhost" "server_name '$ZBR_HOSTNAME'"
# declare ssl protocol for NGiNX default config
if [[ "$ZBR_PROTOCOL" == "https" ]]; then
replace ./nginx/conf.d/default.conf "listen 80" "listen 80 ssl"
# uncomment default ssl settings
replace ./nginx/conf.d/default.conf "# ssl_" " ssl_"
# configure valid sub-modules rules
replace ./nginx/conf.d/default.conf "http://jenkins-master:8080;" "https://jenkins-master:8443;"
replace ./nginx/conf.d/default.conf "upstream_sonar http://127.0.0.1:80;" "upstream_sonar https://127.0.0.1:80;"
replace ./nginx/conf.d/default.conf "upstream_mcloud http://127.0.0.1:80;" "upstream_mcloud https://127.0.0.1:80;"
replace ./nginx/conf.d/default.conf "upstream_stf http://stf-proxy:80;" "upstream_stf https://stf-proxy:80;"
fi
# Reporting is obligatory component now. But to be able to disable it we can register REPORTING_DISABLED=1 env variable before setup
if [[ $ZBR_REPORTING_ENABLED -eq 1 && -z $REPORTING_DISABLED ]]; then
# 411 There is ".disabled" present in minio-storage after setup all components
rm -f reporting/.disabled
rm -f reporting/minio-storage/.disabled
set_reporting_settings
reporting/zebrunner.sh setup
else
# explicitly disable reporting and minio as it was disabled by engineer via REPORTING_DISABLED env var
export ZBR_REPORTING_ENABLED=0
disableLayer "reporting"
disableLayer "reporting/minio-storage"
fi
enableLayer "sonarqube" "Use embedded SonarQube to organize static code analysis and guiding your team?" "$ZBR_SONARQUBE_ENABLED"
export ZBR_SONARQUBE_ENABLED=$?
# jenkins after sonar to detect and put valid SONAR_URL value
enableLayer "jenkins" "Use embedded Jenkins as recommended CI tool?" "$ZBR_JENKINS_ENABLED"
export ZBR_JENKINS_ENABLED=$?
enableLayer "selenoid" "Use embedded Web Selenium Hub for testing on chrome, firefox, opera and MicrosoftEdge browsers?" "$ZBR_SELENOID_ENABLED"
export ZBR_SELENOID_ENABLED=$?
enableLayer "mcloud" "Use embedded Mobile Device Farm and Selenium/Appium Hub for testing on Android, iOS, AppleTV etc devices?" "$ZBR_MCLOUD_ENABLED"
export ZBR_MCLOUD_ENABLED=$?
if [[ $ZBR_SONARQUBE_ENABLED -eq 1 ]]; then
sonarqube/zebrunner.sh setup
export ZBR_SONAR_URL=$ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/sonarqube
fi
if [[ $ZBR_JENKINS_ENABLED -eq 1 ]]; then
jenkins/zebrunner.sh setup
fi
if [[ $ZBR_MCLOUD_ENABLED -eq 1 && $ZBR_REPORTING_ENABLED -eq 0 ]] || [[ $ZBR_SELENOID_ENABLED -eq 1 && $ZBR_REPORTING_ENABLED -eq 0 ]]; then
set_aws_storage_settings
fi
if [[ $ZBR_MCLOUD_ENABLED -eq 1 ]]; then
mcloud/zebrunner.sh setup
fi
if [[ $ZBR_JENKINS_ENABLED -eq 1 && $ZBR_REPORTING_ENABLED -eq 1 ]]; then
# update reporting-jenkins integration vars
replace reporting/configuration/reporting-service/variables.env "JENKINS_ENABLED=false" "JENKINS_ENABLED=true"
replace reporting/configuration/reporting-service/variables.env "JENKINS_URL=" "JENKINS_URL=$ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/jenkins"
fi
# finish with NGiNX default tool selection
if [[ $ZBR_REPORTING_ENABLED -eq 1 ]]; then
replace ./nginx/conf.d/default.conf "default-proxy-server" "zebrunner-proxy:80"
replace ./nginx/conf.d/default.conf "default-proxy-host" "zebrunner-proxy"
elif [[ $ZBR_MCLOUD_ENABLED -eq 1 ]]; then
replace ./nginx/conf.d/default.conf "default-proxy-server" "stf-proxy:80"
replace ./nginx/conf.d/default.conf "default-proxy-host" "stf-proxy"
elif [[ $ZBR_JENKINS_ENABLED -eq 1 ]]; then
replace ./nginx/conf.d/default.conf 'set $upstream_default default-proxy-server;' ""
replace ./nginx/conf.d/default.conf "proxy_set_header Host default-proxy-host;" ""
replace ./nginx/conf.d/default.conf 'proxy_pass http://$upstream_default;' "rewrite / /jenkins;"
elif [[ $ZBR_SONARQUBE_ENABLED -eq 1 ]]; then
replace ./nginx/conf.d/default.conf 'set $upstream_default default-proxy-server;' ""
replace ./nginx/conf.d/default.conf "proxy_set_header Host default-proxy-host;" ""
replace ./nginx/conf.d/default.conf 'proxy_pass http://$upstream_default;' "rewrite / /sonarqube;"
else
replace ./nginx/conf.d/default.conf 'proxy_pass http://$upstream_default;' "root /usr/share/nginx/html;"
fi
# export all ZBR* variables to save user input
export_settings
echo
echo "Copy and save auto-generated crendentials. Detailes can be found also in NOTICE.txt"
echo
notice=NOTICE.txt
echo "NOTICES AND INFORMATION" > $notice
echo >> $notice
echo >> $notice
echo "ZEBRUNNER URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT" | tee -a $notice
echo | tee -a $notice
if [[ $ZBR_REPORTING_ENABLED -eq 1 ]]; then
echo "REPORTING SERVICE CREDENTIALS:" | tee -a $notice
echo "USER: admin/changeit" | tee -a $notice
echo "IAM POSTGRES: postgres/$ZBR_IAM_POSTGRES_PASSWORD" | tee -a $notice
echo "REPORTING POSTGRES: postgres/$ZBR_POSTGRES_PASSWORD" | tee -a $notice
echo "RABBITMQ: $ZBR_RABBITMQ_USER/$ZBR_RABBITMQ_PASSWORD" | tee -a $notice
echo "REDIS: $ZBR_REDIS_PASSWORD" | tee -a $notice
echo | tee -a $notice
if [[ ZBR_SMTP_ENABLED -eq 1 ]]; then
echo "REPORTING SMTP INTEGRATIONS:" | tee -a $notice
echo "SMTP HOST: $ZBR_SMTP_HOST:$ZBR_SMTP_PORT" | tee -a $notice
echo "EMAIL: $ZBR_SMTP_EMAIL" | tee -a $notice
echo "USER: $ZBR_SMTP_USER/$ZBR_SMTP_PASSWORD" | tee -a $notice
echo | tee -a $notice
fi
fi
if [[ $ZBR_JENKINS_ENABLED -eq 1 ]]; then
echo "JENKINS URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/jenkins" | tee -a $notice
echo "JENKINS USER: admin/changeit" | tee -a $notice
echo | tee -a $notice
fi
if [[ $ZBR_SONARQUBE_ENABLED -eq 1 ]]; then
echo "SONARQUBE URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/sonarqube" | tee -a $notice
echo "SONARQUBE USER: admin/admin" | tee -a $notice
echo | tee -a $notice
fi
if [[ $ZBR_SELENOID_ENABLED -eq 1 ]]; then
echo "SELENIUM HUB URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/selenoid/wd/hub" | tee -a $notice
echo | tee -a $notice
fi
if [[ $ZBR_MCLOUD_ENABLED -eq 1 ]]; then
echo "STF URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/stf" | tee -a $notice
echo "APPIUM HUB URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT/mcloud/wd/hub" | tee -a $notice
echo | tee -a $notice
fi
# append copyright and licensing info
echo >> $notice
echo "Copyright 2018-2021 ZEBRUNNER" >> $notice
echo >> $notice
echo "Licensed under the Apache License, Version 2.0 (the \"License\");" >> $notice
echo "you may not use this file except in compliance with the License." >> $notice
echo "You may obtain a copy of the License at" >> $notice
echo >> $notice
echo "http://www.apache.org/licenses/LICENSE-2.0" >> $notice
echo >> $notice
echo "Unless required by applicable law or agreed to in writing, software" >> $notice
echo "distributed under the License is distributed on an \"AS IS\" BASIS," >> $notice
echo "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." >> $notice
echo "See the License for the specific language governing permissions and" >> $notice
echo "limitations under the License." >> $notice
if [[ "$ZBR_PROTOCOL" == "https" ]]; then
echo_warning "Replace self-signed ssl.crt and ssl.key in ./nginx/ssl onto valid ones!"
fi
echo_warning "Your services needs to be started after setup."
confirm "" " Start now?" "y"
export start_services=$?
echo
echo
if [[ $ZBR_SELENOID_ENABLED -eq 1 ]]; then
selenoid/zebrunner.sh setup
fi
if [[ $start_services -eq 1 ]]; then
start
fi
}
shutdown() {
if [ ! -f backup/settings.env ]; then
echo_warning "Unable to erase as nothing is configured!"
echo_telegram
exit -1
fi
echo_warning "Shutdown will erase all settings and data for \"${BASEDIR}\"!"
confirm "" " Do you want to continue?" "n"
if [[ $? -eq 0 ]]; then
exit
fi
export SHUTDOWN_CONFIRMED=1
print_banner
jenkins/zebrunner.sh shutdown
reporting/zebrunner.sh shutdown
sonarqube/zebrunner.sh shutdown
mcloud/zebrunner.sh shutdown
selenoid/zebrunner.sh shutdown
docker compose down -v
rm -f NOTICE.txt
rm -f .env
rm -f nginx/conf.d/default.conf
rm -f backup/settings.env
rm -f reporting/database/reporting/sql/db-jenkins-integration.sql
rm -f reporting/database/reporting/sql/db-mcloud-integration.sql
rm -f reporting/database/reporting/sql/db-selenium-integration.sql
}
start() {
if [ ! -f .env ]; then
# need proceed with setup steps in advance!
setup
exit -1
fi
source backup/settings.env
if [[ -z ${ZBR_VERSION} ]]; then
ZBR_VERSION=1.0
fi
ACTUAL_VERSION=${ZBR_VERSION}
source .env
DESIRED_VERSION=${ZBR_VERSION}
if [[ "${ACTUAL_VERSION}" < "${DESIRED_VERSION}" ]]; then
echo_warning "You have to upgrade services in advance using: ./zebrunner.sh upgrade"
echo_telegram
exit -1
fi
print_banner
# create infra network only if not exist
docker network inspect infra >/dev/null 2>&1 || docker network create infra
#-------------- START EVERYTHING ------------------------------
selenoid/zebrunner.sh start
mcloud/zebrunner.sh start
jenkins/zebrunner.sh start
reporting/zebrunner.sh start
sonarqube/zebrunner.sh start
docker compose up -d
}
stop() {
if [ ! -f .env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
jenkins/zebrunner.sh stop
reporting/zebrunner.sh stop
sonarqube/zebrunner.sh stop
mcloud/zebrunner.sh stop
selenoid/zebrunner.sh stop
docker compose stop
}
restart() {
if [ ! -f .env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
down
start
}
down() {
if [ ! -f .env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
jenkins/zebrunner.sh down
reporting/zebrunner.sh down
sonarqube/zebrunner.sh down
mcloud/zebrunner.sh down
selenoid/zebrunner.sh down
docker compose down
}
backup() {
if [ ! -f .env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
confirm "" " Your services will be stopped. Do you want to do a backup now?" "n"
if [[ $? -eq 0 ]]; then
exit
fi
print_banner
stop
cp .env .env.bak
cp ./nginx/conf.d/default.conf ./nginx/conf.d/default.conf.bak
cp backup/settings.env backup/settings.env.bak
if [[ -f reporting/database/reporting/sql/db-jenkins-integration.sql ]]; then
cp reporting/database/reporting/sql/db-jenkins-integration.sql reporting/database/reporting/sql/db-jenkins-integration.sql.bak
fi
if [[ -f reporting/database/reporting/sql/db-mcloud-integration.sql ]]; then
cp reporting/database/reporting/sql/db-mcloud-integration.sql reporting/database/reporting/sql/db-mcloud-integration.sql.bak
fi
if [[ -f reporting/database/reporting/sql/db-selenium-integration.sql ]]; then
cp reporting/database/reporting/sql/db-selenium-integration.sql reporting/database/reporting/sql/db-selenium-integration.sql.bak
fi
jenkins/zebrunner.sh backup
reporting/zebrunner.sh backup
sonarqube/zebrunner.sh backup
mcloud/zebrunner.sh backup
selenoid/zebrunner.sh backup
echo_warning "Your services needs to be started after backup."
confirm "" " Start now?" "y"
if [[ $? -eq 1 ]]; then
start
fi
}
restore() {
if [ ! -f .env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
if [ ! -f backup/settings.env.bak ]; then
echo_warning "You have to backup something in advance using: ./zebrunner.sh backup"
echo_telegram
exit -1
fi
echo " Your services will be stopped and current data might be lost."
confirm "" " Do you want to do a restore to \"`date -r backup/settings.env.bak`\" state?" "n"
if [[ $? -eq 0 ]]; then
exit
fi
print_banner
stop
cp .env.bak .env
cp ./nginx/conf.d/default.conf.bak ./nginx/conf.d/default.conf
cp backup/settings.env.bak backup/settings.env
if [[ -f reporting/database/reporting/sql/db-jenkins-integration.sql.bak ]]; then
cp reporting/database/reporting/sql/db-jenkins-integration.sql.bak reporting/database/reporting/sql/db-jenkins-integration.sql
fi
if [[ -f reporting/database/reporting/sql/db-mcloud-integration.sql.bak ]]; then
cp reporting/database/reporting/sql/db-mcloud-integration.sql.bak reporting/database/reporting/sql/db-mcloud-integration.sql
fi
if [[ -f reporting/database/reporting/sql/db-selenium-integration.sql.bak ]]; then
cp reporting/database/reporting/sql/db-selenium-integration.sql.bak reporting/database/reporting/sql/db-selenium-integration.sql
fi
jenkins/zebrunner.sh restore
reporting/zebrunner.sh restore
sonarqube/zebrunner.sh restore
mcloud/zebrunner.sh restore
selenoid/zebrunner.sh restore
down
echo_warning "Your services needs to be started after restore."
confirm "" " Start now?" "y"
if [[ $? -eq 1 ]]; then
start
fi
}
upgrade() {
if [ ! -f backup/settings.env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
confirm "" " Do you want to do an upgrade?" "n"
if [[ $? -eq 0 ]]; then
exit
fi
patch/1.1.sh
p1_1=$?
if [[ ${p1_1} -eq 1 ]]; then
echo "ERROR! 1.1 patchset was not applied correctly!"
exit -1
fi
patch/1.2.sh
p1_2=$?
if [[ ${p1_2} -eq 1 ]]; then
echo "ERROR! 1.2 patchset was not applied correctly!"
exit -1
fi
patch/1.3.sh
p1_3=$?
if [[ ${p1_3} -eq 1 ]]; then
echo "ERROR! 1.3 patchset was not applied correctly!"
exit -1
fi
patch/1.4.sh
p1_4=$?
if [[ ${p1_4} -eq 1 ]]; then
echo "ERROR! 1.4 patchset was not applied correctly!"
exit -1
fi
patch/1.5.sh
p1_5=$?
if [[ ${p1_5} -eq 1 ]]; then
echo "ERROR! 1.5 patchset was not applied correctly!"
exit -1
fi
patch/1.6.sh
p1_6=$?
if [[ ${p1_6} -eq 1 ]]; then
echo "ERROR! 1.6 patchset was not applied correctly!"
exit -1
fi
patch/1.7.sh
p1_7=$?
if [[ ${p1_7} -eq 1 ]]; then
echo "ERROR! 1.7 patchset was not applied correctly!"
exit -1
fi
patch/1.8.sh
p1_8=$?
if [[ ${p1_8} -eq 1 ]]; then
echo "ERROR! 1.8 patchset was not applied correctly!"
exit -1
fi
patch/1.9.sh
p1_9=$?
if [[ ${p1_9} -eq 1 ]]; then
echo "ERROR! 1.9 patchset was not applied correctly!"
exit -1
fi
patch/2.0.sh
p2_0=$?
if [[ ${p2_0} -eq 1 ]]; then
echo "ERROR! 2.0 patchset was not applied correctly!"
exit -1
fi
patch/2.1.sh
p2_1=$?
if [[ ${p2_1} -eq 1 ]]; then
echo "ERROR! 2.1 patchset was not applied correctly!"
exit -1
fi
patch/2.3.sh
p2_3=$?
if [[ ${p2_3} -eq 1 ]]; then
echo "ERROR! 2.3 patchset was not applied correctly!"
exit -1
fi
patch/2.4.sh
p2_4=$?
if [[ ${p2_4} -eq 1 ]]; then
echo "ERROR! 2.4 patchset was not applied correctly!"
exit -1
fi
patch/2.5.sh
p2_5=$?
if [[ ${p2_5} -eq 1 ]]; then
echo "ERROR! 2.5 patchset was not applied correctly!"
exit -1
fi
# IMPORTANT! Increment latest verification to new version, i.e. p1_3, p1_4 etc to verify latest upgrade status
if [[ ${p2_5} -eq 2 ]]; then
echo "No need to restart service as nothing was upgraded."
exit -1
fi
echo_warning "Your services needs to restart to finish important updates."
confirm "" " Restart now?" "y"
if [[ $? -eq 1 ]]; then
down
start
fi
}
version() {
if [ ! -f .env ]; then
echo_warning "You have to setup services in advance using: ./zebrunner.sh setup"
echo_telegram
exit -1
fi
source backup/settings.env
echo "
zebrunner: ${ZBR_VERSION}
$(jenkins/zebrunner.sh version)
$(mcloud/zebrunner.sh version)
$(reporting/zebrunner.sh version)
$(selenoid/zebrunner.sh version)
$(sonarqube/zebrunner.sh version)"
}
enableLayer() {
local layer=$1
local message=$2
local isEnabled=$3
echo
confirm "$message" "Enable?" "$isEnabled"
if [[ $? -eq 1 ]]; then
# enable component/layer
if [[ -f $layer/.disabled ]]; then
rm "$layer"/.disabled
fi
return 1
else
disableLayer "$layer"
return 0
fi
}
disableLayer() {
# disbale component/layer
echo > "$1"/.disabled
return 0
}
set_global_settings() {
# Setup global settings: protocol, hostname and port
echo "Zebrunner General Settings"
local is_confirmed=0
if [[ -z $ZBR_HOSTNAME ]]; then
ZBR_HOSTNAME=`curl -s ifconfig.me`
fi
while [[ $is_confirmed -eq 0 ]]; do
read -r -p "Protocol [$ZBR_PROTOCOL]: " local_protocol
if [[ ! -z $local_protocol ]]; then
ZBR_PROTOCOL=$local_protocol
fi
read -r -p "Fully qualified domain name (ip) [$ZBR_HOSTNAME]: " local_hostname
if [[ ! -z $local_hostname ]]; then
ZBR_HOSTNAME=$local_hostname
fi
read -r -p "Port [$ZBR_PORT]: " local_port
if [[ ! -z $local_port ]]; then
ZBR_PORT=$local_port
fi
confirm "Zebrunner URL: $ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT" "Continue?" "y"
is_confirmed=$?
done
export ZBR_PROTOCOL=$ZBR_PROTOCOL
export ZBR_HOSTNAME=$ZBR_HOSTNAME
export ZBR_PORT=$ZBR_PORT
}
echo_help() {
echo "
Usage: ./zebrunner.sh [option]
Flags:
--help | -h Print help
Arguments:
setup [-d] Setup Zebrunner Community Edition ('-d' - debug mode)
start Start container
stop Stop and keep container
restart Restart container
down Stop and remove container
shutdown Stop and remove container, clear volumes
backup Backup container
restore Restore container
upgrade Upgrade to the latest version of Zebrunner Community Edition
version Version of components"
echo_telegram
exit 0
}
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${BASEDIR}" || exit
# shellcheck disable=SC1091
source patch/utility.sh
source reporting/patch/settings.sh
case "$1" in
setup)
setup "$2"
;;
start)
start
;;
stop)
stop
;;
restart)
restart
;;
down)
down
;;
shutdown)
shutdown
;;
backup)
backup
;;
restore)
restore
;;
upgrade)
upgrade
;;
version)
version
;;
*)
echo_help
exit 1
;;
esac