-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathhelper.sh
1358 lines (996 loc) · 44.1 KB
/
helper.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
#!/bin/bash
#information
FLUX_APPS_DIR='ZelApps'
FLUX_DIR='zelflux'
SERVICE_NAME='zelcash'
COIN_NAME='flux'
COIN_DAEMON='fluxd'
COIN_CLI='flux-cli'
COIN_PATH='/usr/local/bin'
CONFIG_DIR='.flux'
CONFIG_FILE='zelcash.conf'
BENCH_NAME='fluxbench'
BENCH_DAEMON='fluxbenchd'
BENCH_CLI='fluxbench-cli'
#end of required details
#color codes
RED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE="\\033[38;5;27m"
SEA="\\033[38;5;49m"
GREEN='\033[1;32m'
CYAN='\033[1;36m'
ORANGE='\e[38;5;202m'
NC='\033[0m'
FLUX_UPDATE="0"
#emoji codes
CHECK_MARK="${GREEN}\xE2\x9C\x94${NC}"
X_MARK="${RED}\xE2\x9C\x96${NC}"
PIN="${RED}\xF0\x9F\x93\x8C${NC}"
CLOCK="${GREEN}\xE2\x8C\x9B${NC}"
ARROW="${SEA}\xE2\x96\xB6${NC}"
BOOK="${RED}\xF0\x9F\x93\x8B${NC}"
HOT="${ORANGE}\xF0\x9F\x94\xA5${NC}"
WORNING="${RED}\xF0\x9F\x9A\xA8${NC}"
BOOTSTRAP_ZIP='https://fluxnodeservice.com/daemon_bootstrap.tar.gz'
BOOTSTRAP_ZIPFILE='daemon_bootstrap.tar.gz'
BOOTSTRAP_URL_MONGOD='https://fluxnodeservice.com/mongod_bootstrap.tar.gz'
BOOTSTRAP_ZIPFILE_MONGOD='mongod_bootstrap.tar.gz'
KDA_BOOTSTRAP_ZIPFILE='kda_bootstrap.tar.gz'
KDA_BOOTSTRAP_ZIP='https://fluxnodeservice.com/kda_bootstrap.tar.gz'
#dialog color
export NEWT_COLORS='
title=black,
'
# add to path
PATH=$PATH:"$COIN_PATH"
export PATH
call_type="$1"
type="$2"
echo -e "${BOOK}${YELLOW}Helper action: ${GREEN}$1${NC}"
function max(){
local m="0"
for n in "$@"
do
if egrep -o "^[0-9]+$" <<< "$n" &>/dev/null; then
[ "$n" -gt "$m" ] && m="$n"
fi
done
echo "$m"
}
function spinning_timer()
{
animation=( ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏ )
end=$((SECONDS+NUM))
while [ $SECONDS -lt $end ];
do
for i in "${animation[@]}";
do
echo -e ""
echo -ne "${RED}\r\033[1A\033[0K$i ${CYAN}${MSG1}${NC}"
sleep 0.1
done
done
echo -ne "${MSG2}"
}
function string_limit_check_mark_port()
{
if [[ -z "$2" ]]; then
string="$1"
string=${string::65}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::65+string_diff}
fi
echo -e "${PIN}${CYAN}$string[${CHECK_MARK}${CYAN}]${NC}"
}
function string_limit_check_mark()
{
if [[ -z "$2" ]]; then
string="$1"
string=${string::50}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::50+string_diff}
fi
echo -e "${ARROW} ${CYAN}$string[${CHECK_MARK}${CYAN}]${NC}"
}
function string_limit_x_mark()
{
if [[ -z "$2" ]]; then
string="$1"
string=${string::50}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::50+string_diff}
fi
echo -e "${ARROW} ${CYAN}$string[${X_MARK}${CYAN}]${NC}"
}
function local_version_check()
{
local_version=$(dpkg -l $1 | grep -w $1 | awk '{print $3}')
}
function remote_version_check(){
#variable null
remote_version=""
package_name=""
remote_version=$(curl -s -m 8 https://apt.runonflux.io/pool/main/f/"$1"/ | grep -o '[0-9].[0-9].[0-9]' | head -n1)
# if [[ "$remote_version" != "" ]]; then
# package_name=$(echo "$1_"$remote_version"_all.deb")
# fi
}
function install_package()
{
echo -e "${ARROW} ${CYAN}Install package for: ${GREEN}$1 $2${NC}"
sudo apt-get purge "$1" "$2" -y >/dev/null 2>&1 && sleep 1
sudo rm /etc/apt/sources.list.d/zelcash.list >/dev/null 2>&1 && sleep 1
sudo rm /etc/apt/sources.list.d/flux.list >/dev/null 2>&1 && sleep 1
echo -e "${ARROW} ${CYAN}Adding apt source...${NC}"
echo 'deb https://apt.runonflux.io/ '$(lsb_release -cs)' main' | sudo tee --append /etc/apt/sources.list.d/flux.list > /dev/null 2>&1
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B69CA27A986265D > /dev/null 2>&1
gpg --export 4B69CA27A986265D | sudo apt-key add - > /dev/null 2>&1
if ! gpg --list-keys Zel > /dev/null; then
gpg --keyserver hkp://keys.gnupg.net:80 --recv-keys 4B69CA27A986265D > /dev/null 2>&1
gpg --export 4B69CA27A986265D | sudo apt-key add - > /dev/null 2>&1
fi
sudo apt-get update >/dev/null 2>&1
sudo apt-get install "$1" -y > /dev/null 2>&1
sudo chmod 755 "$COIN_PATH/"* && sleep 2
}
start_fluxdaemon()
{
serive_check=$(sudo systemctl list-units --full -all | grep -o "$SERVICE_NAME.service" | head -n1)
if [[ "$serive_check" != "" ]]; then
echo -e "${ARROW} ${CYAN}Starting Flux daemon service...${NC}"
sudo systemctl start $SERVICE_NAME >/dev/null 2>&1
else
echo -e "${ARROW} ${CYAN}Starting Flux daemon process...${NC}"
"$COIN_DAEMON" >/dev/null 2>&1
fi
}
stop_fluxdaemon() {
echo -e "${ARROW} ${CYAN}Stopping Flux daemon...${NC}"
sudo systemctl stop $SERVICE_NAME >/dev/null 2>&1 && sleep 5
"$COIN_CLI" stop >/dev/null 2>&1 && sleep 5
sudo killall "$COIN_DAEMON" fluxd >/dev/null 2>&1
sudo killall -s SIGKILL $BENCH_NAME fluxbench >/dev/null 2>&1 && sleep 1
sleep 4
}
function reindex()
{
echo -e "${ARROW} ${CYAN}Reindexing...${NC}"
stop_fluxdaemon
"$COIN_DAEMON" -reindex
serive_check=$(sudo systemctl list-units --full -all | grep -o "$COIN_NAM.service" | head -n1)
if [[ "$serive_check" != "" ]]; then
sleep 60
stop_fluxdaemon
start_fluxdaemon
fi
}
function restart_fluxdaemon()
{
echo -e "${ARROW} ${CYAN}Restarting Flux daemon...${NC}"
serive_check=$(sudo systemctl list-units --full -all | grep -o "$SERVICE_NAME.service" | head -n1)
if [[ "$serive_check" != "" ]]; then
sudo systemctl restart $SERVICE_NAME >/dev/null 2>&1 && sleep 3
else
stop_fluxdaemon
start_fluxdaemon
fi
}
function fluxbench_update()
{
local_version=$(dpkg -l $BENCH_NAME | grep -w "$BENCH_NAME" | awk '{print $3}')
if [[ "$type" == "force" ]]; then
echo -e "${ARROW} ${CYAN}Force Flux benchmark updating...${NC}"
stop_fluxdaemon
install_package "$BENCH_NAME"
dpkg_version_after_install=$(dpkg -l $BENCH_NAME | grep -w "$BENCH_NAME" | awk '{print $3}')
echo -e "${ARROW} ${CYAN}Flux benchmark version before update: ${GREEN}$local_version${NC}"
echo -e "${ARROW} ${CYAN}Flux benchmark version after update: ${GREEN}$dpkg_version_after_install${NC}"
start_fluxdaemon
return
fi
remote_version_check "$BENCH_NAME"
#remote_version=$(curl -s -m 3 https://zelcore.io/zelflux/zelbenchinfo.php | jq -r .version)
if [[ "$call_type" != "update_all" ]]; then
if [[ "$remote_version" == "" ]]; then
echo -e "${ARROW} ${CYAN}Problem with version veryfication...Flux benchmark installation skipped...${NC}"
return
fi
if [[ "$remote_version" == "$local_version" ]]; then
echo -e "${ARROW} ${CYAN}You have the current version of Flux benchamrk ${GREEN}($remote_version)${NC}"
return
fi
fi
echo -e "${ARROW} ${CYAN}Updating Flux benchmark...${NC}"
echo -e "${ARROW} ${CYAN}Flux benchmark stopping...${NC}"
$BENCH_CLI stop >/dev/null 2>&1 && sleep 2
sudo killall -s SIGKILL $BENCH_DAEMON >/dev/null 2>&1 && sleep 1
sudo apt-get update >/dev/null 2>&1
sudo apt-get install $BENCH_NAME -y >/dev/null 2>&1
sudo chmod 755 "$COIN_PATH/"*
sleep 2
dpkg_version_after_install=$(dpkg -l $BENCH_NAME | grep -w "$BENCH_NAME" | awk '{print $3}')
echo -e "${ARROW} ${CYAN}Flux benchmark version before update: ${GREEN}$local_version${NC}"
if [[ "$dpkg_version_after_install" == "" ]]; then
install_package "$BENCH_NAME"
dpkg_version_after_install=$(dpkg -l $BENCH_NAME | grep -w "$BENCH_NAME" | awk '{print $3}')
if [[ "$dpkg_version_after_install" != "" ]]; then
echo -e "${ARROW} ${CYAN}Flux benchmark update successful ${CYAN}(${GREEN}$dpkg_version_after_install${CYAN})${NC}"
fi
start_fluxdaemon
echo -e "${ARROW} ${CYAN}Flux benchmark starting...${NC}"
else
if [[ "$remote_version" == "$dpkg_version_after_install" ]]; then
echo -e "${ARROW} ${CYAN}Flux benchmark update successful ${CYAN}(${GREEN}$dpkg_version_after_install${CYAN})${NC}"
start_fluxdaemon
echo -e "${ARROW} ${CYAN}Flux benchmark starting...${NC}"
else
if [[ "$local_version" == "$dpkg_version_after_install" ]]; then
install_package $BENCH_NAME
dpkg_version_after_install=$(dpkg -l $BENCH_NAME | grep -w "$BENCH_NAME" | awk '{print $3}')
if [[ "$dpkg_version_after_install" == "$remote_version" ]]; then
echo -e "${ARROW} ${CYAN}Flux benchmark update successful ${CYAN}(${GREEN}$dpkg_version_after_install${CYAN})${NC}"
fi
start_fluxdaemon
echo -e "${ARROW} ${CYAN}Flux benchmark starting...${NC}"
fi
fi
fi
}
function flux_update()
{
current_ver=$(jq -r '.version' /home/$USER/$FLUX_DIR/package.json)
required_ver=$(curl -s -m 5 https://raw.githubusercontent.com/zelcash/zelflux/master/package.json | jq -r '.version')
if [[ "$required_ver" != "" && "$call_type" != "update_all" ]]; then
if [ "$(printf '%s\n' "$required_ver" "$current_ver" | sort -V | head -n1)" = "$required_ver" ]; then
echo -e "${ARROW} ${CYAN}You have the current version of Flux ${GREEN}($required_ver)${NC}"
return
else
#echo -e "${HOT} ${CYAN}New version of Flux available ${SEA}$required_ver${NC}"
FLUX_UPDATE="1"
fi
fi
if [[ "$FLUX_UPDATE" == "1" ]]; then
cd /home/$USER/$FLUX_DIR && git pull > /dev/null 2>&1 && cd
current_ver=$(jq -r '.version' /home/$USER/$FLUX_DIR/package.json)
required_ver=$(curl -s -m 3 https://raw.githubusercontent.com/zelcash/zelflux/master/package.json | jq -r '.version')
if [[ "$required_ver" == "$current_ver" ]]; then
echo -e "${ARROW} ${CYAN}Flux updated successfully ${GREEN}($required_ver)${NC}"
else
echo -e "${ARROW} ${CYAN}Flux was not updated.${NC}"
echo -e "${ARROW} ${CYAN}Flux force update....${NC}"
rm /home/$USER/$FLUX_DIR/.git/HEAD.lock >/dev/null 2>&1
#cd /home/$USER/$FLUX_DIR && npm run hardupdatezelflux
cd /home/$USER/$FLUX_DIR && git reset --hard HEAD && git clean -f -d && git pull
current_ver=$(jq -r '.version' /home/$USER/$FLUX_DIR/package.json)
required_ver=$(curl -s -m 3 https://raw.githubusercontent.com/zelcash/zelflux/master/package.json | jq -r '.version')
if [[ "$required_ver" == "$current_ver" ]]; then
echo -e "${ARROW} ${CYAN}Flux updated successfully ${GREEN}($required_ver)${NC}"
fi
fi
else
echo -e "${ARROW} ${CYAN}Problem with version veryfication...Flux installation skipped...${NC}"
fi
}
function fluxdaemon_update()
{
local_version=$(dpkg -l $COIN_NAME | grep -w "$COIN_NAME" | awk '{print $3}')
if [[ "$type" == "force" ]]; then
echo -e "${ARROW} ${CYAN}Force Flux daemon updating...${NC}"
stop_fluxdaemon
install_package "$COIN_NAME" "flux"
dpkg_version_after_install=$(dpkg -l $COIN_NAME | grep -w "$COIN_NAME" | awk '{print $3}')
echo -e "${ARROW} ${CYAN}Flux daemon version before update: ${GREEN}$local_version${NC}"
echo -e "${ARROW} ${CYAN}Flux daemon version after update: ${GREEN}$dpkg_version_after_install${NC}"
start_fluxdaemon
return
fi
remote_version_check "$COIN_NAME"
#local_version=$($COIN_CLI getinfo | jq -r .version)
#remote_version=$(curl -s -m3 https://zelcore.io/zelflux/zelcashinfo.php | jq -r .version)
if [[ "$call_type" != "update_all" ]]; then
if [[ "$local_version" == "" || "$remote_version" == "" ]]; then
echo -e "${ARROW} ${CYAN}Problem with version veryfication...Flux daemon installation skipped...${NC}"
return
fi
if [[ "$local_version" == "$remote_version" ]]; then
echo -e "${ARROW} ${CYAN}You have the current version of Flux daemon ${GREEN}($remote_version)${NC}"
return
fi
fi
dpkg_version_before_install=$(dpkg -l $COIN_NAME | grep -w "$COIN_NAME" | awk '{print $3}')
stop_fluxdaemon
sudo apt-get update >/dev/null 2>&1
sudo apt-get install flux -y >/dev/null 2>&1
sudo chmod 755 "$COIN_PATH/"*
sleep 2
dpkg_version_after_install=$(dpkg -l $COIN_NAME | grep -w "$COIN_NAME" | awk '{print $3}')
echo -e "${ARROW} ${CYAN}Flux daemon version before update: ${GREEN}$local_version${NC}"
#echo -e "${ARROW} ${CYAN}Flux daemon version after update: ${GREEN}$dpkg_version_after_install${NC}"
if [[ "$dpkg_version_after_install" == "" ]]; then
install_package "$COIN_NAME" "flux"
dpkg_version_after_install=$(dpkg -l $COIN_NAME | grep -w "$COIN_NAME" | awk '{print $3}')
if [[ "$dpkg_version_after_install" != "" ]]; then
echo -e "${ARROW} ${CYAN}Flux daemon update successful ${CYAN}(${GREEN}$dpkg_version_after_install${CYAN})${NC}"
fi
start_fluxdaemon
else
if [[ "$local_version" != "$dpkg_version_after_install" ]]; then
echo -e "${ARROW} ${CYAN}Flux daemon update successful ${CYAN}(${GREEN}$dpkg_version_after_install${CYAN})${NC}"
start_fluxdaemon
fi
if [[ "local_version" == "$dpkg_version_after_install" ]]; then
install_package "$COIN_NAME"
dpkg_version_after_install=$(dpkg -l $COIN_NAME | grep -w "$COIN_NAME" | awk '{print $3}')
if [[ "$dpkg_version_after_install" == "$remote_version" ]]; then
echo -e "${ARROW} ${CYAN}Flux daemon update successful ${CYAN}(${GREEN}$dpkg_version_after_install${CYAN})${NC}"
fi
start_fluxdaemon
fi
fi
}
function check_update()
{
update_fluxbench="0"
update_fluxdaemon="0"
update_flux="0"
local_version_check "$COIN_NAME"
remote_version_check "$COIN_NAME"
if [[ "$local_version" == "" || "$remote_version" == "" ]]; then
echo -e "${RED}${ARROW} ${CYAN}Problem with version veryfication...Flux daemon installation skipped...${NC}"
else
if [[ "$local_version" != "$remote_version" ]]; then
echo -e "${RED}${HOT}${CYAN}New version of Flux daemon available ${SEA}$remote_version${NC}"
update_fluxdaemon="1"
else
echo -e "${ARROW} ${CYAN}You have the current version of Flux daemon ${GREEN}($remote_version)${NC}"
fi
fi
local_version_check "$BENCH_NAME"
remote_version_check "$BENCH_NAME"
if [[ "$local_version" == "" || "$remote_version" == "" ]]; then
echo -e "${RED}${ARROW} ${CYAN}Problem with version veryfication...Flux benchmark installation skipped...${NC}"
else
if [[ "$local_version" != "$remote_version" ]]; then
echo -e "${RED}${HOT}${CYAN}New version of Flux benchmark available ${SEA}$remote_version${NC}"
update_fluxbench="1"
else
echo -e "${ARROW} ${CYAN}You have the current version of Flux benchmark ${GREEN}($remote_version)${NC}"
fi
fi
local_version=$(jq -r '.version' /home/$USER/$FLUX_DIR/package.json)
remote_version=$(curl -s -m 5 https://raw.githubusercontent.com/zelcash/zelflux/master/package.json | jq -r '.version')
if [[ "$local_version" == "" || "$remote_version" == "" ]]; then
echo -e "${RED}${ARROW} ${CYAN}Problem with version veryfication...Flux installation skipped...${NC}"
else
if [[ "$local_version" != "$remote_version" ]]; then
echo -e "${RED}${HOT}${CYAN}New version of Flux available ${SEA}$remote_version${NC}"
update_flux="1"
FLUX_UPDATE="1"
else
echo -e "${ARROW} ${CYAN}You have the current version of Flux ${GREEN}($remote_version)${NC}"
fi
fi
if [[ "$update_fluxbench" == "1" || "$update_fluxdaemon" == "1" || "$update_flux" == "1" ]]; then
echo -e ""
fi
}
#tar_file_unpack file/file_path dir_to_compress
function tar_file_unpack()
{
echo -e "${ARROW} ${YELLOW}Unpacking bootstrap archive file...${NC}"
pv $1 | tar -zx -C $2
}
#tar_file_pack path_to_pack path_to_archive_file_to_save
function tar_file_pack()
{
echo -e "${ARROW} ${YELLOW}Creating bootstrap archive file...${NC}"
tar -c --use-compress-program=pigz -f $2 $1
#tar -czf --use-compress-program=pigz - $1 | (pv -p --timer --rate --bytes > $2) 2>&1
}
#check_tar file_name
function check_tar()
{
echo -e "${ARROW} ${YELLOW}Checking bootstrap file integration...${NC}"
if gzip -t "$1" &>/dev/null; then
echo -e "${ARROW} ${CYAN}Bootstrap file is valid.................[${CHECK_MARK}${CYAN}]${NC}"
else
echo -e "${ARROW} ${CYAN}Bootstrap file is corrupted.............[${X_MARK}${CYAN}]${NC}"
rm -rf $1
fi
}
function create_daemon_bootstrap()
{
sudo apt install zip >/dev/null 2>&1
if "$COIN_CLI" getinfo > /dev/null 2>&1; then
local_network_hight=$("$COIN_CLI" getinfo | jq -r .blocks)
echo -e "${ARROW} ${CYAN}Local Network Block Hight: ${GREEN}$local_network_hight${NC}"
network_height_01=$(curl -sk -m 5 https://explorer.zel.network/api/status?q=getInfo | jq '.info.blocks')
network_height_02=$(curl -sk -m 5 https://explorer2.zel.network/api/status?q=getInfo | jq '.info.blocks')
network_height_03=$(curl -sk -m 5 https://explorer.zel.zelcore.io/api/status?q=getInfo | jq '.info.blocks')
explorer_network_hight=$(max "$network_height_01" "$network_height_02" "$network_height_03")
echo -e "${ARROW} ${CYAN}Global Network Block Hight: ${GREEN}$explorer_network_hight${NC}"
if [[ "$explorer_network_hight" == "" || "$local_network_hight" == "" ]]; then
echo -e "${ARROW} ${CYAN}Flux network veryfication failed...${NC}"
return
fi
check_height=$((explorer_network_hight-local_network_hight))
if [[ "$check_height" -lt 0 ]]; then
check_height=$((check_height*(-1)))
fi
if [[ "$check_height" -lt 15 ]]; then
echo -e "${ARROW} ${CYAN}Local and Global network are synced, diff: ${GREEN}$check_height${NC}"
else
echo -e "${ARROW} ${CYAN}Local and Global network are not synced, try again later (diff: ${RED}$check_height${CYAN})${NC}"
return
fi
data=$(date -u)
unix=$(date +%s)
stop_fluxdaemon
check_zip=$(zip -L | head -n1)
if [[ "$check_zip" != "" ]]; then
echo -e "${ARROW} ${CYAN}Cleaning...${NC}"
rm -rf /home/$USER/$BOOTSTRAP_ZIPFILE >/dev/null 2>&1 && sleep 5
#echo -e "${ARROW} ${CYAN}Flux daemon bootstrap creating...${NC}"
cd /home/$USER/$CONFIG_DIR
tar_file_pack "blocks chainstate determ_zelnodes" "/home/$USER/$BOOTSTRAP_ZIPFILE"
#zip /home/$USER/$BOOTSTRAP_ZIPFILE -r blocks chainstate determ_zelnodes
cd
if [[ -f /home/$USER/$BOOTSTRAP_ZIPFILE ]]; then
echo -e "${ARROW} ${CYAN}Flux daemon bootstrap created successful ${GREEN}($local_network_hight)${NC}"
rm -rf /home/$USER/daemon_bootstrap.json >/dev/null 2>&1
sudo touch /home/$USER/daemon_bootstrap.json
sudo chown $USER:$USER /home/$USER/daemon_bootstrap.json
cat << EOF > /home/$USER/daemon_bootstrap.json
{
"block_height": "${explorer_network_hight}",
"time": "${data}",
"unix_timestamp": "${unix}"
}
EOF
else
echo -e "${ARROW} ${CYAN}Flux daemon bootstrap creating failed${NC}"
fi
fi
start_fluxdaemon
else
echo -e "${ARROW} ${CYAN}Flux network veryfication failed...Flux daemon not working...${NC}"
echo
fi
}
function create_mongod_bootstrap()
{
WANIP=$(wget --timeout=3 --tries=2 http://ipecho.net/plain -O - -q)
if [[ "$WANIP" == "" ]]; then
WANIP=$(curl -s -m 3 ifconfig.me)
if [[ "$WANIP" == "" ]]; then
echo -e "${ARROW} ${CYAN}Public IP address could not be found, action stopped .........[${X_MARK}${CYAN}]${NC}"
echo
exit
fi
fi
local_network_hight=$(curl -s -m 3 http://"$WANIP":16127/explorer/scannedheight | jq '.data.generalScannedHeight')
echo -e "${ARROW} ${CYAN}Mongod Network Block Hight: ${GREEN}$local_network_hight${NC}"
#explorer_network_hight=$(curl -s -m 3 https://explorer.zel.network/api/status?q=getInfo | jq '.info.blocks')
network_height_01=$(curl -sk -m 5 https://explorer.zel.network/api/status?q=getInfo | jq '.info.blocks')
network_height_02=$(curl -sk -m 5 https://explorer2.zel.network/api/status?q=getInfo | jq '.info.blocks')
network_height_03=$(curl -sk -m 5 https://explorer.zel.zelcore.io/api/status?q=getInfo | jq '.info.blocks')
explorer_network_hight=$(max "$network_height_01" "$network_height_02" "$network_height_03")
echo -e "${ARROW} ${CYAN}Global Network Block Hight: ${GREEN}$explorer_network_hight${NC}"
if [[ "$explorer_network_hight" == "" || "$local_network_hight" == "" ]]; then
echo -e "${ARROW} ${CYAN}Flux network veryfication failed...${NC}"
return
fi
check_height=$((explorer_network_hight-local_network_hight))
if [[ "$check_height" -lt 0 ]]; then
check_height=$((check_height*(-1)))
fi
if [[ "$check_height" -lt 15 ]]; then
echo -e "${ARROW} ${CYAN}Local and Global network are synced, diff: ${GREEN}$check_height${NC}"
else
echo -e "${ARROW} ${CYAN}Local and Global network are not synced, try again later (diff: ${RED}$check_height${CYAN})${NC}"
return
fi
data=$(date -u)
unix=$(date +%s)
echo -e "${ARROW} ${CYAN}Cleaning...${NC}"
sudo rm -rf /home/$USER/dump >/dev/null 2>&1 && sleep 2
sudo rm -rf /home/$USER/$BOOTSTRAP_ZIPFILE_MONGOD >/dev/null 2>&1 && sleep 2
echo -e "${ARROW} ${CYAN}Exporting Mongod datetable...${NC}"
mongodump --port 27017 --db zelcashdata --out /home/$USER/dump/ >/dev/null 2>&1
tar_file_pack "dump" "/home/$USER/$BOOTSTRAP_ZIPFILE_MONGOD"
#tar -cvzf /home/$USER/$BOOTSTRAP_ZIPFILE_MONGOD dump
sudo rm -rf /home/$USER/dump >/dev/null 2>&1 && sleep 2
if [[ -f /home/$USER/$BOOTSTRAP_ZIPFILE_MONGOD ]]; then
echo -e "${ARROW} ${CYAN}Mongod bootstrap created successful ${GREEN}($local_network_hight)${NC}"
rm -rf /home/$USER/mongodb_bootstrap.json >/dev/null 2>&1
sudo touch /home/$USER/mongodb_bootstrap.json
sudo chown $USER:$USER /home/$USER/mongodb_bootstrap.json
cat << EOF > /home/$USER/mongodb_bootstrap.json
{
"block_height": "${explorer_network_hight}",
"time": "${data}",
"unix_timestamp": "${unix}"
}
EOF
else
echo -e "${ARROW} ${CYAN}Mongod bootstrap creating failed${NC}"
fi
}
function clean_mongod() {
echo -e "${ARROW} ${CYAN}Stopping Flux...${NC}"
pm2 stop flux >/dev/null 2>&1 && sleep 2
echo -e "${ARROW} ${CYAN}Stopping MongoDB...${NC}"
sudo systemctl stop mongod >/dev/null 2>&1 && sleep 2
echo -e "${ARROW} ${CYAN}Removing MongoDB datatable...${NC}"
# sudo rm -r /var/lib/mongodb >/dev/null 2>&1 && sleep 2
install_mongod
pm2 start flux > /dev/null 2>&1
pm2 save > /dev/null 2>&1
NUM='60'
MSG1='Flux starting...'
MSG2="${CYAN}.....................[${CHECK_MARK}${CYAN}]${NC}"
spinning_timer
echo
#mongodb_bootstrap
}
function mongodb_bootstrap(){
WANIP=$(wget --timeout=3 --tries=2 http://ipecho.net/plain -O - -q)
if [[ "$WANIP" == "" ]]; then
WANIP=$(curl -s -m 3 ifconfig.me)
if [[ "$WANIP" == "" ]]; then
echo -e "${ARROW} ${CYAN}Public IP address could not be found, action stopped .........[${X_MARK}${CYAN}]${NC}"
echo
exit
fi
fi
BLOCKHIGHT=100
#DB_HIGHT=$(curl -s -m 3 https://fluxnodeservice.com/mongodb_bootstrap.json | jq -r '.block_height')
DB_HIGHT=$(curl -s -m 3 https://fluxnodeservice.com/mongodb_bootstrap.json | jq -r '.block_height')
echo -e "${ARROW} ${CYAN}Bootstrap block hight: ${GREEN}$DB_HIGHT${NC}"
if [[ "$BLOCKHIGHT" -gt "0" && "$BLOCKHIGHT" -lt "$DB_HIGHT" ]]; then
echo -e "${ARROW} ${CYAN}Downloading File: ${GREEN}$BOOTSTRAP_URL_MONGOD${NC}"
wget $BOOTSTRAP_URL_MONGOD -q --show-progress
echo -e "${ARROW} ${CYAN}Unpacking...${NC}"
#tar xvf $BOOTSTRAP_ZIPFILE_MONGOD -C /home/$USER > /dev/null 2>&1 && sleep 1
tar_file_unpack "/home/$USER/$BOOTSTRAP_ZIPFILE_MONGOD" "/home/$USER"
echo -e "${ARROW} ${CYAN}Importing mongodb datatable...${NC}"
mongorestore --port 27017 --db zelcashdata /home/$USER/dump/zelcashdata --drop
echo -e "${ARROW} ${CYAN}Cleaning...${NC}"
sudo rm -rf /home/$USER/dump > /dev/null 2>&1 && sleep 1
sudo rm -rf $BOOTSTRAP_ZIPFILE_MONGOD > /dev/null 2>&1 && sleep 1
pm2 start flux > /dev/null 2>&1
pm2 save > /dev/null 2>&1
NUM='120'
MSG1='Flux starting...'
MSG2="${CYAN}.....................[${CHECK_MARK}${CYAN}]${NC}"
spinning_timer
echo
BLOCKHIGHT_AFTER_BOOTSTRAP=$(curl -s -m 3 http://"$WANIP":16127/explorer/scannedheight | jq '.data.generalScannedHeight')
echo -e ${ARROW} ${CYAN}Node block hight after restored: ${GREEN}$BLOCKHIGHT_AFTER_BOOTSTRAP${NC}
if [[ "$BLOCKHIGHT" != "" ]]; then
if [[ "$BLOCKHIGHT" -gt "0" && "$BLOCKHIGHT" -lt "$DB_HIGHT" ]]; then
#echo -e "${ARROW} ${CYAN}Mongo bootstrap installed successful.${NC}"
string_limit_check_mark "Mongo bootstrap installed successful.................................."
echo -e ""
else
#echo -e "${ARROW} ${CYAN}Mongo bootstrap installation failed.${NC}"
string_limit_x_mark "Mongo bootstrap installation failed.................................."
echo -e ""
fi
else
echo -e "${ARROW} ${CYAN}Current Node block hight ${RED}$BLOCKHIGHT${CYAN} > Bootstrap block hight ${RED}$DB_HIGHT${CYAN}. Datatable is out of date.${NC}"
echo -e ""
fi
fi
}
function install_mongod() {
sudo rm /etc/apt/sources.list.d/mongodb*.list > /dev/null 2>&1
if [[ $(lsb_release -r) = *16.* ]]; then
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc 2> /dev/null | sudo apt-key add - > /dev/null 2>&1
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list > /dev/null 2>&1
elif [[ $(lsb_release -r) = *18.* || $(lsb_release -r) = *19.* ]]; then
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc 2> /dev/null | sudo apt-key add - > /dev/null 2>&1
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list > /dev/null 2>&1
elif [[ $(lsb_release -r) = *20.* ]]; then
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc 2> /dev/null | sudo apt-key add - > /dev/null 2>&1
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list > /dev/null 2>&1
elif [[ $(lsb_release -d) = *Debian* ]] && [[ $(lsb_release -d) = *9* ]]; then
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc 2> /dev/null | sudo apt-key add - > /dev/null 2>&1
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.4 main" 2> /dev/null | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list > /dev/null 2>&1
elif [[ $(lsb_release -d) = *Debian* ]] && [[ $(lsb_release -d) = *10* ]]; then
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc 2> /dev/null | sudo apt-key add - > /dev/null 2>&1
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" 2> /dev/null | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list > /dev/null 2>&1
else
echo -e "${WORNING}${CYAN}ERROR: OS version not supported"
echo -e "${WORNING}${CYAN}Installation stopped..."
echo
exit
fi
sleep 2
echo -e "${ARROW} ${YELLOW}Removing any instances of Mongodb...${NC}"
sudo apt remove mongod* -y > /dev/null 2>&1 && sleep 1
sudo apt purge mongod* -y > /dev/null 2>&1 && sleep 1
sudo apt autoremove -y > /dev/null 2>&1 && sleep 1
echo -e "${ARROW} ${YELLOW}Mongodb installing...${NC}"
sudo apt-get update -y > /dev/null 2>&1
sudo apt-get install mongodb-org -y > /dev/null 2>&1 && sleep 2
sudo systemctl enable mongod > /dev/null 2>&1
sudo systemctl start mongod > /dev/null 2>&1
if mongod --version > /dev/null 2>&1
then
#echo -e "${ARROW} ${CYAN}MongoDB version: ${GREEN}$(mongod --version | grep 'db version' | sed 's/db version.//')${CYAN} installed${NC}"
string_limit_check_mark "MongoDB $(mongod --version | grep 'db version' | sed 's/db version.//') installed................................." "MongoDB ${GREEN}$(mongod --version | grep 'db version' | sed 's/db version.//')${CYAN} installed................................."
echo
else
#echo -e "${ARROW} ${CYAN}MongoDB was not installed${NC}"
string_limit_x_mark "MongoDB was not installed................................."
echo
fi
}
function swapon_create()
{
MEM=$(grep MemTotal /proc/meminfo | awk '{print $2}')
gb=$(awk "BEGIN {print $MEM/1048576}")
GB=$(echo "$gb" | awk '{printf("%d\n",$1 + 0.5)}')
if [ "$GB" -lt 2 ]; then
(( swapsize=GB*2 ))
swap="$swapsize"G
#echo -e "${YELLOW}Swap set at $swap...${NC}"
elif [[ $GB -ge 2 ]] && [[ $GB -le 16 ]]; then
swap=4G
# echo -e "${YELLOW}Swap set at $swap...${NC}"
elif [[ $GB -gt 16 ]] && [[ $GB -lt 32 ]]; then
swap=2G
#echo -e "${YELLOW}Swap set at $swap...${NC}"
fi
if ! grep -q "swapfile" /etc/fstab; then
if whiptail --yesno "No swapfile detected would you like to create one?" 8 54; then
sudo fallocate -l "$swap" /swapfile > /dev/null 2>&1
sudo chmod 600 /swapfile > /dev/null 2>&1
sudo mkswap /swapfile > /dev/null 2>&1
sudo swapon /swapfile > /dev/null 2>&1
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab > /dev/null 2>&1
echo -e "${ARROW} ${YELLOW}Created ${SEA}${swap}${YELLOW} swapfile${NC}"
else
echo -e "${ARROW} ${YELLOW}Creating a swapfile skipped...${NC}"
fi
fi
}
function unlock_flux_resouce()
{
docker_check=$(docker ps | grep -Eo "^[0-9a-z]{8,}\b" | wc -l)
resource_check=$(df | egrep 'flux' | awk '{ print $1}' | wc -l)
mongod_check=$(mongoexport -d localzelapps -c zelappsinformation --jsonArray --pretty --quiet | jq -r .[].name | head -n1)
if [[ "$mongod_check" != "" && "$mongod_check" != "null" && "$1" == "clean_db" ]]; then
echo -e "${ARROW} ${YELLOW}Detected Flux MongoDB local apps collection ...${NC}" && sleep 1
echo -e "${ARROW} ${CYAN}Cleaning MongoDB Flux local apps collection...${NC}" && sleep 1
echo "db.zelappsinformation.drop()" | mongo localzelapps > /dev/null 2>&1
fi
if [[ $docker_check != 0 ]]; then
echo -e "${ARROW} ${YELLOW}Detected running docker container...${NC}" && sleep 1
echo -e "${ARROW} ${CYAN}Stopping containers...${NC}"
docker ps | grep -Eo "^[0-9a-z]{8,}\b" |
while read line; do
sudo docker stop $line && sleep 2
sudo docker rm $line && sleep 2
done
fi
if [[ $resource_check != 0 ]]; then
echo -e "${ARROW} ${YELLOW}Detected locked resource${NC}" && sleep 1
echo -e "${ARROW} ${CYAN}Unmounting locked Flux resource${NC}" && sleep 1
df | egrep 'flux' | awk '{ print $1}' |
while read line; do
sudo umount $line && sleep 1
done
fi
echo
}
function create_kda_bootstrap {
kda_bootstrap_daemon="0"
kadena_path=$1
kadena_docker_name=$2
kadena_path=${kadena_path:-kadena}
kadena_docker_name=${kadena_docker_name:-fluxkadenachainwebnode}
echo -e "${ARROW} ${CYAN}APPS LOCATION: ${GREEN}/home/$USER/$kadena_path/chainweb-db${NC}"
echo -e "${ARROW} ${CYAN}DOCKER APPS: ${GREEN}$kadena_docker_name${NC}"
echo -e ""
WANIP=$(wget --timeout=3 --tries=2 http://ipecho.net/plain -O - -q)
if [[ "$WANIP" == "" ]]; then
WANIP=$(curl -s -m 3 ifconfig.me)
if [[ "$WANIP" == "" ]]; then
echo -e "${ARROW} ${CYAN}Local IP address could not be found, action stopped .........[${X_MARK}${CYAN}]${NC}"
echo
exit
fi
fi
if [ ! -d /home/$USER/$kadena_path/chainweb-db ]; then
echo -e "${ARROW} ${CYAN}Kadena Node chain directory does not exist, operation stopped...${NC}"
echo
exit
fi
network_height_node_01=$(curl -sk -m 5 https://us-e1.chainweb.com/chainweb/0.0/mainnet01/cut | jq '.height')
network_height_node_02=$(curl -sk -m 5 https://us-e2.chainweb.com/chainweb/0.0/mainnet01/cut | jq '.height')
network_height_node_03=$(curl -sk -m 5 https://fr1.chainweb.com/chainweb/0.0/mainnet01/cut | jq '.height')