-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmanage.sh
executable file
·7152 lines (5925 loc) · 213 KB
/
manage.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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env bash
### Configuration ### begin ###
PREV_VERSION="0.9.3"
VERSION="0.9.4"
SED_E="sed -E"
USE_PRODUCT="genesis"
if [ "$USE_PRODUCT" = "apla" ]; then
PRODUCT_BRAND_NAME="Apla"
else
PRODUCT_BRAND_NAME="Genesis"
fi
GOLANG_VER="1.11.5"
NODEJS_SETUP_SCRIPT_URL="https://deb.nodesource.com/setup_10.x"
BACKEND_BRANCH="1.2.7"
if [ "$USE_PRODUCT" = "apla" ]; then
BACKEND_GO_URL="github.com/AplaProject/go-apla"
else
BACKEND_GO_URL="github.com/AplaProject/go-apla"
fi
MAX_BLOCK_GENERATION_TIME=4000
GAP_BETWEEN_BLOCKS=8
MAX_NUM_OF_NODES=5
if [ "$USE_PRODUCT" = "apla" ]; then
FAST_INSTALL_DATA_URL="https://github.com/blitzstern5/quick-start-data/raw/master/apla/0.9.4/apla-qs-0.9.4-fast-install-data-20190403060559-1-nodes.tar.gz"
else
FAST_INSTALL_DATA_URL="https://github.com/blitzstern5/quick-start-data/raw/master/genesis/0.9.4/genesis-qs-0.9.4-fast-install-data-20190403052958-1-nodes.tar.gz"
fi
FAST_INSTALL_DATA_BASENAME="$(basename "$FAST_INSTALL_DATA_URL")"
INITIAL_APPS_URLS[0]="https://github.com/AplaProject/apps/releases/download/v1.4.0/init_qs.json"
INITIAL_APPS_IMPORT_TIMEOUT_SECS[0]=70
INITIAL_APPS_IMPORT_MAX_TRIES[0]=70
APPS_URLS[0]="https://github.com/GenesisKernel/apps/releases/download/v1.4.0/system.json"
APPS_IMPORT_TIMEOUT_SECS[0]=280
APPS_IMPORT_MAX_TRIES[0]=280
APPS_URLS[1]="https://github.com/GenesisKernel/apps/releases/download/v1.4.0/conditions.json"
APPS_IMPORT_TIMEOUT_SECS[1]=100
APPS_IMPORT_MAX_TRIES[1]=100
APPS_URLS[2]="https://github.com/GenesisKernel/apps/releases/download/v1.4.0/basic.json"
APPS_IMPORT_TIMEOUT_SECS[2]=250
APPS_IMPORT_MAX_TRIES[2]=250
APPS_URLS[3]="https://github.com/GenesisKernel/apps/releases/download/v1.4.0/lang_res.json"
APPS_IMPORT_TIMEOUT_SECS[3]=705
APPS_IMPORT_MAX_TRIES[3]=705
ES_APPS_URLS[0]="https://raw.githubusercontent.com/AplaProject/apps/develop/ecosystem_apps/crediting.json"
ES_APPS_IMPORT_TIMEOUT_SECS[0]=406
ES_APPS_IMPORT_MAX_TRIES[0]=406
ES_APPS_URLS[1]="https://raw.githubusercontent.com/AplaProject/apps/develop/ecosystem_apps/land_registry.json"
ES_APPS_IMPORT_TIMEOUT_SECS[1]=407
ES_APPS_IMPORT_MAX_TRIES[1]=407
ES_APPS_URLS[2]="https://raw.githubusercontent.com/AplaProject/apps/develop/ecosystem_apps/token_sale.json"
ES_APPS_IMPORT_TIMEOUT_SECS[2]=408
ES_APPS_IMPORT_MAX_TRIES[2]=408
DEMO_APPS_URL="https://github.com/GenesisKernel/apps/releases/download/v1.3.0/system.json"
DEV_BE_GO_URL="github.com/AplaProject/go-apla"
DEV_BE_BRANCH="master"
DEV_BE_CREATE_GO_URL_VENDOR_SYMLINK="yes"
DEV_BE_GO_URL_VENDOR_SRC="github.com/blitzstern5"
DEV_BE_GO_URL_VENDOR_DST="github.com/GenesisKernel"
if [ "$USE_PRODUCT" = "apla" ]; then
FRONTEND_REPO_URL="https://github.com/AplaProject/apla-front"
else
FRONTEND_REPO_URL="https://github.com/GenesisKernel/genesis-front"
fi
FRONTEND_BRANCH="v0.11.1"
SCRIPTS_REPO_URL="https://github.com/blitzstern5/genesis-scripts"
SCRIPTS_BRANCH="v0.2.5"
DB_USER="postgres"
if [ "$USE_PRODUCT" = "apla" ]; then
DB_NAME_PREFIX="apla"
DB_HOST="apla-db"
DB_PASSWORD="apla"
CENT_URL="http://apla-cf:8000"
BLEX_REPO_URL="https://github.com/AplaProject/blockexplorer"
BLEX_DB_NAME_PREFIX="apla_blex_"
BLEX_REDIS_URL="redis://apla-rq:6379/0"
BE_API_URL_PREFIX="http://apla-bf"
else
DB_NAME_PREFIX="genesis"
DB_HOST="genesis-db"
DB_PASSWORD="genesis"
CENT_URL="http://genesis-cf:8000"
BLEX_REPO_URL="https://github.com/GenesisKernel/blockexplorer"
BLEX_DB_NAME_PREFIX="genesis_blex_"
BLEX_REDIS_URL="redis://genesis-rq:6379/0"
BE_API_URL_PREFIX="http://genesis-bf"
fi
BLEX_BRANCH="v0.3.3"
BLEX_DB_HOST="$DB_HOST"
BLEX_DB_USER="$DB_USER"
BLEX_DB_PASSWORD="$DB_PASSWORD"
BE_ROOT="/genesis-back"
BE_ROOT_LOG_DIR="/var/log/go-genesis"
BE_ROOT_DATA_DIR="$BE_ROOT/data"
BE_BIN_DIR="$BE_ROOT/bin"
BE_BIN_BASENAME="go-apla"
BE_BIN_PATH="$BE_BIN_DIR/$BE_BIN_BASENAME"
FE_SRC_DIR="/genesis-front"
SCRIPTS_DIR="/genesis-scripts"
APPS_DIR="/genesis-apps"
DB_PORT=15432
CF_PORT=18100
BLEX_PORT=18200
WEB_PORT_SHIFT=8300
CLIENT_PORT_SHIFT=17300
CONT_DB_PORT=5432
CONT_CF_PORT=8000
CONT_BLEX_PORT=8000
CONT_WEB_PORT_SHIFT=80
CONT_CLIENT_PORT_SHIFT=7000
REDIS_HOST_PORT=16379
REDIS_CONT_PORT=6379
DOWNLOADS_DIR='$HOME/Downloads' # !!! USE SINGLE QUOTES HERE !!!
APPLICATIONS_DIR='$HOME/Applications' # !!! USE SINGLE QUOTES HERE !!!
DOCKER_APP_NAME="Docker"
DOCKER_DMG_DL_URL="https://download.docker.com/mac/stable/Docker.dmg"
DOCKER_DMG_BASENAME="$(basename "$(echo "$DOCKER_DMG_DL_URL" | $SED_E -n 's/^(.*\.dmg)(\?[^?]*)?$/\1/gp')")"
DOCKER_MAC_APP_DIR_SIZE_M=1248 # to update run 'du -sm /Applications/Docker.app'
DOCKER_MAC_APP_DIR="/Applications/Docker.app"
DOCKER_MAC_APP_BIN="/Applications/Docker.app/Contents/MacOS/Docker"
if [ "$USE_PRODUCT" = "apla" ]; then
CLIENT_MAC_PROCESS_NAME="Apla"
CLIENT_LINUX_PROCESS_NAME="apla-front"
CLIENT_APP_NAME="Apla"
CLIENT_DMG_DL_URL="https://github.com/AplaProject/apla-front/releases/download/v0.11.1/Apla-0.11.1.dmg"
CLIENT_MAC_APP_DIR_SIZE_M=246 # to update run 'du -sm /Applications/Genesis.app'
CLIENT_MAC_APP_DIR="/Applications/Apla.app"
CLIENT_MAC_APP_BIN="/Applications/Apla.app/Contents/MacOS/Apla"
CLIENT_APPIMAGE_DL_URL="https://github.com/AplaProject/apla-front/releases/download/v0.11.1/apla-front-0.11.1-x86_64.AppImage"
else
CLIENT_MAC_PROCESS_NAME="Genesis"
CLIENT_LINUX_PROCESS_NAME="genesis-front"
CLIENT_APP_NAME="Genesis"
CLIENT_DMG_DL_URL="https://github.com/GenesisKernel/genesis-front/releases/download/v0.11.1/Genesis-0.11.1.dmg"
CLIENT_MAC_APP_DIR_SIZE_M=246 # to update run 'du -sm /Applications/Genesis.app'
CLIENT_MAC_APP_DIR="/Applications/Genesis.app"
CLIENT_MAC_APP_BIN="/Applications/Genesis.app/Contents/MacOS/Genesis"
CLIENT_APPIMAGE_DL_URL="https://github.com/GenesisKernel/genesis-front/releases/download/v0.11.1/genesis-front-0.11.1-x86_64.AppImage"
fi
CLIENT_DMG_BASENAME="$(basename "$(echo "$CLIENT_DMG_DL_URL" | $SED_E -n 's/^(.*\.dmg)(\?[^?]*)?$/\1/gp')")"
CLIENT_APPIMAGE_BASENAME="$(basename "$(echo "$CLIENT_APPIMAGE_DL_URL" | $SED_E -n 's/^(.*\.AppImage)(\?[^?]*)?$/\1/gp')")"
if [ "$USE_PRODUCT" = "apla" ]; then
BF_CONT_NAME="apla-bf"
BF_CONT_IMAGE="str16071985/apla-bf:$VERSION"
BF_CONT_PREV_IMAGE="str16071985/apla-bf:$PREV_VERSION"
BF_CONT_BUILD_DIR="apla-bf"
else
BF_CONT_NAME="genesis-bf"
BF_CONT_IMAGE="str16071985/genesis-bf:$VERSION"
BF_CONT_PREV_IMAGE="str16071985/genesis-bf:$PREV_VERSION"
BF_CONT_BUILD_DIR="genesis-bf"
fi
TRY_LOCAL_BF_CONT_NAME_ON_RUN="yes"
if [ "$USE_PRODUCT" = "apla" ]; then
DB_CONT_NAME="apla-db"
DB_CONT_IMAGE="str16071985/apla-db:$VERSION"
DB_CONT_PREV_IMAGE="str16071985/apla-db:$PREV_VERSION"
DB_CONT_BUILD_DIR="apla-db"
else
DB_CONT_NAME="genesis-db"
DB_CONT_IMAGE="str16071985/genesis-db:$VERSION"
DB_CONT_PREV_IMAGE="str16071985/genesis-db:$PREV_VERSION"
DB_CONT_BUILD_DIR="genesis-db"
fi
TRY_LOCAL_DB_CONT_NAME_ON_RUN="yes"
if [ "$USE_PRODUCT" = "apla" ]; then
CF_CONT_NAME="apla-cf"
CF_CONT_IMAGE="str16071985/apla-cf:$VERSION"
CF_CONT_PREV_IMAGE="str16071985/apla-cf:$PREV_VERSION"
CF_CONT_BUILD_DIR="apla-cf"
else
CF_CONT_NAME="genesis-cf"
CF_CONT_IMAGE="str16071985/genesis-cf:$VERSION"
CF_CONT_PREV_IMAGE="str16071985/genesis-cf:$PREV_VERSION"
CF_CONT_BUILD_DIR="genesis-cf"
fi
TRY_LOCAL_CF_CONT_NAME_ON_RUN="yes"
if [ "$USE_PRODUCT" = "apla" ]; then
BLEX_CONT_NAME="apla-blex"
BLEX_CONT_IMAGE="str16071985/apla-blex:$VERSION"
BLEX_CONT_PREV_IMAGE="str16071985/apla-blex:$PREV_VERSION"
BLEX_CONT_BUILD_DIR="apla-blex"
else
BLEX_CONT_NAME="genesis-blex"
BLEX_CONT_IMAGE="str16071985/genesis-blex:$VERSION"
BLEX_CONT_PREV_IMAGE="str16071985/genesis-blex:$PREV_VERSION"
BLEX_CONT_BUILD_DIR="genesis-blex"
fi
TRY_LOCAL_BLEX_CONT_NAME_ON_RUN="yes"
if [ "$USE_PRODUCT" = "apla" ]; then
BE_CONT_NAME="apla-be"
BE_CONT_IMAGE="str16071985/apla-be:$VERSION"
BE_CONT_PREV_IMAGE="str16071985/apla-be:$PREV_VERSION"
BE_CONT_BUILD_DIR="apla-be"
else
BE_CONT_NAME="genesis-be"
BE_CONT_IMAGE="str16071985/genesis-be:$VERSION"
BE_CONT_PREV_IMAGE="str16071985/genesis-be:$PREV_VERSION"
BE_CONT_BUILD_DIR="genesis-be"
fi
TRY_LOCAL_BE_CONT_NAME_ON_RUN="yes"
if [ "$USE_PRODUCT" = "apla" ]; then
FE_CONT_NAME="apla-fe"
FE_CONT_IMAGE="str16071985/apla-fe:$VERSION"
FE_CONT_PREV_IMAGE="str16071985/apla-fe:$PREV_VERSION"
FE_CONT_BUILD_DIR="apla-fe"
else
FE_CONT_NAME="genesis-fe"
FE_CONT_IMAGE="str16071985/genesis-fe:$VERSION"
FE_CONT_PREV_IMAGE="str16071985/genesis-fe:$PREV_VERSION"
FE_CONT_BUILD_DIR="genesis-fe"
fi
TRY_LOCAL_FE_CONT_NAME_ON_RUN="yes"
if [ "$USE_PRODUCT" = "apla" ]; then
RQ_CONT_NAME="apla-rq"
RQ_CONT_IMAGE="str16071985/apla-rq:$VERSION"
RQ_CONT_PREV_IMAGE="str16071985/apla-rq:$PREV_VERSION"
RQ_CONT_BUILD_DIR="apla-rq"
else
RQ_CONT_NAME="genesis-rq"
RQ_CONT_IMAGE="str16071985/genesis-rq:$VERSION"
RQ_CONT_PREV_IMAGE="str16071985/genesis-rq:$PREV_VERSION"
RQ_CONT_BUILD_DIR="genesis-rq"
fi
TRY_LOCAL_RQ_CONT_NAME_ON_RUN="yes"
FORCE_COPY_IMPORT_DEMO_APPS_SCRIPTS="no"
FORCE_COPY_UPDATE_SYS_PARAMS_SCRIPTS="no"
FORCE_COPY_UPDATE_KEYS_SCRIPTS="no"
FORCE_REQUIREMENTS_INSTALL="no"
FORCE_COPY_MBS_SCRIPT="no"
FORCE_COPY_MBLEX_SCRIPT="no"
EMPTY_ENV_VARS="yes"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DOTENV_PATH="$SCRIPT_DIR/.env"
### Configuration #### end ####
### .env ### begin ###
[ -e "$DOTENV_PATH" ] && . "$DOTENV_PATH"
### .env #### end ####
### OS ### begin ###
get_os_type() {
case "$OSTYPE" in
linux*) echo "linux" ;;
darwin*) echo "mac" ;;
win*) echo "windows" ;;
cygwin*) echo "cygwin" ;;
bsd*) echo "bsd" ;;
solaris*) echo "solaris" ;;
*) echo "unknown" ;;
esac
}
get_linux_dist() {
local arch; arch=$(uname -m)
local kernel; kernel=$(uname -r)
local dist
if [ -n "$(command -v lsb_release)" ]; then
dist=$(lsb_release -is)
elif [ -f "/etc/os-release" ]; then
dist=$(grep PRETTY_NAME /etc/os-release | sed 's/PRETTY_NAME=//g' | tr -d '="')
elif [ -f "/etc/debian_version" ]; then
dist="Debian $(cat /etc/debian_version)"
elif [ -f "/etc/redhat-release" ]; then
dist=$(cat /etc/redhat-release)
else
dist="$(uname -s) $(uname -r)"
fi
if [ "$(cat /etc/issue | head -1 | awk {'print $2'})" = "Mint" ]; then
echo "mint"
else
[ -n "$dist" ] && echo "$dist"
fi
}
is_root() {
[ "$EUID" -eq 0 ] && return 0 || return 1
}
check_run_as_root() {
local os_type; os_type="$(get_os_type)"
case $os_type in
linux)
is_root;
if [ $? -ne 0 ]; then
echo "Please run with sudo or as root"
exit 20
fi
;;
mac)
is_root;
if [ $? -eq 0 ]; then
echo "Please run as regular user (don't use sudo)"
exit 21
fi
;;
*)
echo "Sorry, but $os_type is not supported yet"
exit 23
;;
esac
}
run_as_orig_user() {
local cmd
is_root;
if [ $? -eq 0 ]; then
local who_user; who_user="$(who -m | awk '{print $1}')"
local orig_user
if [ -n "$SUDO_USER" ]; then
orig_user="$SUDO_USER"
elif [ -n "$who_user" ]; then
orig_user="$who_user"
else
orig_user=""
fi
if [ -n "$orig_user" ]; then
cmd="su - $orig_user -c '$@'"
else
cmd="su - -c '$@'"
fi
else
cmd="$@"
fi
eval "$cmd"
}
get_orig_user_homedir() {
run_as_orig_user 'echo $HOME'
}
check_min_req() {
local cmd; local cmds;
local os_type; os_type="$(get_os_type)"
case $os_type in
linux|mac)
cmds="lsof curl sed awk grep cat"
for cmd in $cmds; do
[ -z "$(command -v $cmd)" ] \
&& echo "Command '$cmd' not found" && return 1
done
;;
*)
echo "Sorry, but $os_type is not supported yet"
return 10
;;
esac
}
check_requirements() {
check_curl_avail
check_docker_avail
}
check_proc() {
[ -z "$1" ] && echo "Process name isn't set" && return 2
[ -z "$(pgrep "$1")" ] \
&& echo "No process '$1'" && return 2
echo "ok" && return 0
}
check_num_of_procs() {
local proc_name num_of
[ -z "$1" ] && echo "Process name isn't set" && return 2
[ -z "$(pgrep "$1")" ] \
&& echo "No process '$1'" && return 2
echo "ok" && return 0
}
wait_proc() {
local proc_name; proc_name="$1"
local timeout_secs; [ -z "$2" ] && timeout_secs=15 || timeout_secs="$2"
local end_time; end_time=$(( $(date +%s) + timeout_secs ))
echo "Waiting ($timeout_secs seconds) for process '$proc_name' ..."
local cnt; cnt=1
local stop; stop=0;
local result; result=0;
while [ $stop -eq 0 ]; do
[ $cnt -gt 1 ] && sleep 1
echo -n " try $cnt: "
check_proc "$proc_name"; result=$?
case $result in
0|1) stop=1 ;;
2) [ $(date +%s) -lt $end_time ] || stop=1 ;;
esac
cnt=$(expr $cnt + 1)
done
return $result
}
### OS #### end ####
### Disk, FS ### begin ###
get_mac_fs_type_by_path() {
local path; path="$1"
local dev; local mp
eval $(df "$path"| tail -n +2 | awk '{print "dev=\""$1"\"; mp=\""$9"\";"}')
mount | grep "$dev on $mp" | $SED_E -n 's/^[^\(]+\(([^,]+).*$/\1/p'
}
### Disk, FS #### end ####
### Host ports ### begin ###
get_host_port_proc() {
lsof -i :$1 | grep LISTEN | awk '{print $1}'
}
check_host_ports() {
local num; num=$1;
([ -z "$num" ] || [ $num -lt 1 ]) \
&& echo "The number of clients/backends is not set" \
&& return 1
local wps; wps=$2; [ -z "$wps" ] && wps=$WEB_PORT_SHIFT
local cps; cps=$3; [ -z "$cps" ] && cps=$CLIENT_PORT_SHIFT
local d_port; d_port=$4; [ -z "$d_port" ] && d_port=$DB_PORT
local cfp; cfp=$CF_PORT # FIXME: Change to argument
local blexp; blexp=$BLEX_PORT # FIXME: Change to argument
local redisp; redisp=$REDIS_HOST_PORT # FIXME: Change to argument
local result; result=0
echo -n "Checking database port $d_port: "
if [ -n "$(get_host_port_proc $d_port)" ]; then
echo "BUSY"
result=2
else
echo "FREE"
fi
echo -n "Checking centrifugo port $cfp: "
if [ -n "$(get_host_port_proc $cfp)" ]; then
echo "BUSY"
result=5
else
echo "FREE"
fi
echo -n "Checking redis port $redisp: "
if [ -n "$(get_host_port_proc $redisp)" ]; then
echo "BUSY"
result=2
else
echo "FREE"
fi
echo -n "Checking block explorer port $blexp: "
if [ -n "$(get_host_port_proc $blexp)" ]; then
echo "BUSY"
result=5
else
echo "FREE"
fi
local i w_port c_port run_cmd
for i in $(seq 1 $num); do
w_port=$(expr $i + $wps)
c_port=$(expr $i + $cps)
echo -n "Checking web port $w_port: "
if [ -n "$(get_host_port_proc $w_port)" ]; then
echo "BUSY"
result=3
else
echo "FREE"
fi
echo -n "Checking client port $c_port: "
if [ -n "$(get_host_port_proc $c_port)" ]; then
echo "BUSY"
result=4
else
echo "FREE"
fi
done
return $result
}
### Host ports #### end #####
### Download/install ### begin ###
update_global_home_var() {
local home; home="$(get_orig_user_homedir)"
HOME="$home"
}
update_global_downloads_and_apps_dir_vars() {
local home; home="$(get_orig_user_homedir)"
local home_esc; home_esc="$(echo "$home" | $SED_E 's/\//\\\//g')"
DOWNLOADS_DIR="$(echo "$DOWNLOADS_DIR" | $SED_E "s/\\\$HOME/$home_esc/g")"
APPLICATIONS_DIR="$(echo "$APPLICATIONS_DIR" | $SED_E "s/\\\$HOME/$home_esc/g")"
}
create_downloads_dir() {
[ -d "$DOWNLOADS_DIR" ] && return 0
run_as_orig_user "mkdir -p '$DOWNLOADS_DIR'"
}
create_apps_dir() {
[ -d "$APPLICATIONS_DIR" ] && return 0
run_as_orig_user "mkdir -p '$APPLICATIONS_DIR'"
}
get_app_dir_size_m() {
[ -d "$1" ] && du -sm "$1" | awk '{print $1}' || echo 0
}
download_and_check_dmg() {
check_curl_avail
local dmg_url; dmg_url="$1"
local dmg_basename; dmg_basename="$2"
local result
(
update_global_downloads_and_apps_dir_vars
local dmg_path; dmg_path="$DOWNLOADS_DIR/$dmg_basename"
echo "1 dmg_path: $dmg_path"
[ -f "$dmg_path" ] \
&& mv "$dmg_path" "$dmg_path.bak.$(date "+%Y%m%d%H%M%S")"
create_downloads_dir \
&& echo "Downloading $app_name ..." \
&& curl -L -o "$dmg_path" "$dmg_url"
); result=$?
case $result in
77)
echo
echo "To fix this error you need to update CA certificate file."
echo "Please read ISSUES.md 'curl: (77) SSL: can't load CA certificate file' section"
echo "See also https://curl.haxx.se/docs/sslcerts.html for details."
echo "See also https://curl.haxx.se/docs/caextract.html for download URLs."
echo
return $result
;;
0) echo "$dmg_path" ;;
*) return $result ;;
esac
}
download_and_install_dmg() {
check_curl_avail
local app_bin; app_bin="$1"
local app_dir; app_dir="$2"
local dmg_url; dmg_url="$3"
local dmg_basename; dmg_basename="$4"
local app_name; app_name="$5"
local exp_size_m; exp_size_m=$6
local timeout_secs; timeout_secs="380"
local result; result=0
if [ ! -f "$app_bin" ]; then
(
update_global_downloads_and_apps_dir_vars
local dmg_path; dmg_path="$DOWNLOADS_DIR/$dmg_basename"
if [ ! -f "$dmg_path" ]; then
create_downloads_dir \
&& echo "Downloading $app_name ..." \
&& curl -L -o "$dmg_path" "$dmg_url" && open "$dmg_path"
else
open "$dmg_path"
fi
); result=$?
case $result in
77)
echo
echo "To fix this error you need to update CA certificate file."
echo "Please read ISSUES.md 'curl: (77) SSL: can't load CA certificate file' section"
echo "See also https://curl.haxx.se/docs/sslcerts.html for details."
echo "See also https://curl.haxx.se/docs/caextract.html for download URLs."
echo
return $result
;;
0) : ;;
*) return $result ;;
esac
local end_time; end_time=$(( $(date +%s) + timeout_secs ))
local stop; stop=0
local cnt; cnt=0
while [ $stop -eq 0 ]; do
echo "Please move $app_name to Applications"
[ -f "$app_bin" ] && stop=1
[ $(date +%s) -lt $end_time ] || stop=2
[ $cnt -ge 0 ] && sleep 1
done
case $stop in
2) echo "Waiting time for $app_name is out" && return 11
esac
echo "$app_name is copying to Applications. Please wait (timeout: $timeout_secs seconds) ..."
end_time=$(( $(date +%s) + timeout_secs ))
stop=0
while [ $stop -eq 0 ]; do
[ $(get_app_dir_size_m "$app_dir") -ge $exp_size_m ] \
&& stop=1
read -n 1 -s -t 1 answ
if [ $? -eq 0 ] && [ "${answ%\\n}" = "s" ]; then
echo "You did input: '$answ'"
stop=2
fi
[ $(date +%s) -lt $end_time ] || stop=3
echo "Wait until the copying is complete or press 's' key to skip this waiting"
done
case $stop in
1)
echo "$app_name installed"
result=0
;;
2)
echo "$app_name probably installed (you skipped waiting)"
result=21
;;
3)
echo "$app_name probably installed (there was a timeout)"
result=22
;;
esac
fi
return $result
}
download_fast_install_data() {
check_curl_avail
local data_url; data_url="$1"
local data_path; data_path="$2"
local result
echo "Downloading fast install data from '$data_url' to '$data_path' ..."
curl -L -o "$data_path" "$data_url"
result=$?
case $result in
77)
echo
echo "To fix this error you need to update CA certificate file."
echo "Please read ISSUES.md 'curl: (77) SSL: can't load CA certificate file' section"
echo "See also https://curl.haxx.se/docs/sslcerts.html for details."
echo "See also https://curl.haxx.se/docs/caextract.html for download URLs."
echo
return $result
;;
0) echo "$data_path" ;;
*) return $result ;;
esac
}
### Download/install #### end ####
### Docker ### begin ###
install_mac_docker_directly() {
download_and_install_dmg "$DOCKER_MAC_APP_BIN" "$DOCKER_MAC_APP_DIR" "$DOCKER_DMG_DL_URL" "$DOCKER_DMG_BASENAME" "$DOCKER_APP_NAME" $DOCKER_MAC_APP_DIR_SIZE_M
}
install_linux_docker() {
[ -n "$(command -v docker)" ] && return 0
local dist; dist="$1"
case "$dist" in
[Ff][Ee][Dd][Oo][Rr][Aa])
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
dnf -y install docker-ce lsof
systemctl start docker && systemctl enable docker
;;
[Cc][Ee][Nn][Tt][Oo][Ss])
;;
[Dd][Ee][Bb][Ii][Aa][Nn])
apt-get update -y --fix-missing
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
apt-get update -y
apt-get install docker-ce lsof -y
systemctl start docker && systemctl enable docker
;;
[Uu][Bb][Uu][Nn][Tt][Uu])
apt-get update -y --fix-missing
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update -y
apt-get install docker-ce lsof -y
systemctl start docker && systemctl enable docker
;;
[Mm][Ii][Nn][Tt])
apt-get update -y --fix-missing
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
apt-add-repository \
'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
apt-get update -y
apt-get install docker.io lsof -y
systemctl start docker && systemctl enable docker
;;
esac
}
install_docker() {
local os_type; os_type="$(get_os_type)"
case $os_type in
mac)
install_mac_docker_directly
;;
linux)
install_linux_docker
;;
*)
echo "Sorry, but $os_type is not supported yet"
return 10
;;
esac
}
uninstall_mac_docker() {
if [ "${USER}" != "root" ]; then
echo "Please run this command with sudo or as root"
return 2
fi
if [ -e "$DOCKER_MAC_APP_BIN" ]; then
$DOCKER_MAC_APP_BIN --uninstall
fi
if [ -n "$(command -v docker-machine)" ]; then
while true; do
read -p "Remove all $DOCKER_APP_NAME Machine VMs? (Y/N): " yn
case $yn in
[Yy]* ) docker-machine rm -f $(docker-machine ls -q); break ;;
[Nn]* ) break ;;
* ) echo "Please answer yes or no."; exit 1;;
esac
done
fi
echo "Removing $DOCKER_APP_NAME from Applications..."
[ -e "$DOCKER_MAC_APP_DIR" ] \
&& rm -rf "$DOCKER_MAC_APP_DIR"
echo "Removing $DOCKER_APP_NAME binaries..."
[ -e /usr/local/bin/docker ] \
&& rm -f /usr/local/bin/docker
[ -e /usr/local/bin/docker-machine ] \
&& rm -f /usr/local/bin/docker-machine
find /usr/local/bin -name 'docker-machine-driver*' -delete
[ -e /usr/local/bin/docker-compose ] \
&& rm -f /usr/local/bin/docker-compose
echo "Removing boot2docker.iso"
[ -e /usr/local/share/boot2docker ] \
&& rm -rf /usr/local/share/boot2docker
echo "Forget packages"
pkgutil --forget io.docker.pkg.docker
pkgutil --forget io.docker.pkg.dockercompose
pkgutil --forget io.docker.pkg.dockermachine
pkgutil --forget io.boot2dockeriso.pkg.boot2dockeriso
local pids; pids="$(pgrep docker)"
[ -n "$pids" ] && echo "Terminating docker processes ..." \
&& kill $pids
echo "$DOCKER_APP_NAME completely removed"
}
uninstall_docker() {
local os_type; os_type="$(get_os_type)"
case $os_type in
mac)
uninstall_mac_docker
;;
*)
echo "Sorry, but $os_type is not supported yet"
return 10
;;
esac
}
check_docker_ready_status() {
[ -z "$(command -v docker)" ] && return 100
docker ps -a 1>&2>/dev/null
}
wait_docker_ready_status() {
local timeout_secs; [ -z "$1" ] && timeout_secs=15 || timeout_secs=$1
local end_time; end_time=$(( $(date +%s) + timeout_secs ))
echo "Waiting ($timeout_secs seconds) for docker daemon ready status ..."
local cnt; cnt=1
local stop; stop=0;
local result; result=0;
while [ $stop -eq 0 ]; do
[ $cnt -gt 1 ] && sleep 1
echo -n " try $cnt: "
check_docker_ready_status; result=$?
case $result in
0) stop=1; echo "ok" ;;
*) [ $(date +%s) -lt $end_time ] || stop=1 ;;
esac
cnt=$(expr $cnt + 1)
done
return $result
}
check_mac_docker_proc() {
local docker_vmnet_pid pid exists
docker_vmnet_pid="$(pgrep com.docker.vmnet)"
exists=1
for pid in $(pgrep "docker"); do
[ "$pid" == "$docker_vmnet_pid" ] && continue
exists=0
done
case $exists in
1) echo "no docker process" ;;
0) echo "ok" ;;
esac
return $exists
}
wait_mac_docker_proc() {
local timeout_secs; [ -z "$1" ] && timeout_secs=15 || timeout_secs="$1"
local end_time; end_time=$(( $(date +%s) + timeout_secs ))
echo "Waiting ($timeout_secs seconds) for docker process ..."
local cnt; cnt=1
local stop; stop=0;
local result; result=0;
while [ $stop -eq 0 ]; do
[ $cnt -gt 1 ] && sleep 1
echo -n " try $cnt: "
check_mac_docker_proc; result=$?
case $result in
0) stop=1 ;;
1) [ $(date +%s) -lt $end_time ] || stop=1 ;;
esac
cnt=$(expr $cnt + 1)
done
return $result
}
start_mac_docker() {
install_mac_docker_directly
[ $? -ne 0 ] \
&& echo "Can't download docker" && return 1
if ! check_mac_docker_proc > /dev/null; then
echo "Docker process is absent. Starting ..."
open "$DOCKER_MAC_APP_DIR"
fi
wait_mac_docker_proc 120
[ $? -ne 0 ] \
&& echo "No docker process. Please reinstall docker." \
&& echo "You can use $(basename "$0") uninstall-docker to uninstall docker" \
&& return 10
wait_docker_ready_status 120
[ $? -ne 0 ] \
&& echo "Docker daemon isn't ready. Please reinstall docker." \
&& echo "You can use $(basename "$0") uninstall-docker to uninstall docker" \
&& return 11
echo "Docker ready"
return 0
}
start_linux_docker() {
install_linux_docker "$(get_linux_dist)"
[ -n "$(command -v docker)" ] && return 0
}
start_docker() {
local os_type; os_type="$(get_os_type)"
case $os_type in
linux)
start_linux_docker
;;
mac)
start_mac_docker
;;
*)
echo "Sorry, but $os_type is not supported yet"
exit 30
;;
esac
}
check_docker_avail() {
[ -n "$(command -v docker)" ] && return 0
local os_type; os_type="$(get_os_type)"
case $os_type in
linux)
start_linux_docker
;;
mac)
start_mac_docker
;;
*)
echo "Sorry, but $os_type is not supported yet"
exit 30
;;
esac
}
### Docker #### end ####
### Client ### begin ###
check_curl_avail() {
[ -n "$(command -v curl)" ] && return 0
local os_type; os_type="$(get_os_type)"
case $os_type in
linux|mac)
echo "Please install curl first"
exit 31
;;
*)
echo "Sorry, but $os_type is not supported yet"
exit 30
;;
esac
}