forked from RunOnFlux/fluxnode-multitool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_pro.sh
More file actions
2875 lines (2310 loc) · 100 KB
/
install_pro.sh
File metadata and controls
2875 lines (2310 loc) · 100 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
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
# Bootstrap settings
#BOOTSTRAP_ZIP='https://runonflux.zelcore.workers.dev/apps/fluxshare/getfile/flux_explorer_bootstrap.tar.gz'
BOOTSTRAP_ZIPFILE='flux_explorer_bootstrap.tar.gz'
BOOTSTRAP_URL_MONGOD='https://fluxnodeservice.com/mongod_bootstrap.tar.gz'
BOOTSTRAP_ZIPFILE_MONGOD='mongod_bootstrap.tar.gz'
#wallet information
COIN_NAME='flux'
CONFIG_DIR='.flux'
CONFIG_FILE='flux.conf'
kadena_possible="0"
BENCH_NAME='fluxbench'
BENCH_CLI='fluxbench-cli'
BENCH_DIR_LOG='.fluxbenchmark'
COIN_DAEMON='fluxd'
COIN_CLI='flux-cli'
COIN_PATH='/usr/local/bin'
USERNAME="$(whoami)"
FLUX_DIR='zelflux'
#Install variable
IMPORT_ZELCONF="0"
IMPORT_ZELID="0"
CORRUPTED="0"
BOOTSTRAP_SKIP="0"
WATCHDOG_INSTALL="0"
SKIP_OLD_CHAIN="0"
Server_offline=0
#Zelflux ports
ZELFRONTPORT=16126
LOCPORT=16127
ZELNODEPORT=16128
#MDBPORT=27017
RPCPORT=16124
PORT=16125
#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'
NC='\033[0m'
#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}"
#dialog color
export NEWT_COLORS='
title=black,
'
function string_limit_check_mark() {
if [[ -z "$2" ]]; then
string="$1"
string=${string::40}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::40+string_diff}
fi
echo -e "${ARROW} ${CYAN}$string[${CHECK_MARK}${CYAN}]${NC}"
}
function bootstrap_server(){
rand_by_domain=("5" "6" "7" "8" "9" "10" "11")
richable=()
richable_eu=()
richable_us=()
richable_as=()
i=0
len=${#rand_by_domain[@]}
echo -e "${ARROW} ${CYAN}Checking servers availability... ${NC}"
while [ $i -lt $len ];
do
bootstrap_check=$(curl -sSL -m 10 http://cdn-${rand_by_domain[$i]}.runonflux.io/apps/fluxshare/getfile/flux_explorer_bootstrap.json 2>/dev/null | jq -r '.block_height' 2>/dev/null)
if [[ "$bootstrap_check" != "" ]]; then
if [[ "${rand_by_domain[$i]}" -ge "8" && "${rand_by_domain[$i]}" -le "11" ]]; then
richable_eu+=( ${rand_by_domain[$i]} )
fi
if [[ "${rand_by_domain[$i]}" -gt "4" && "${rand_by_domain[$i]}" -le "7" ]]; then
richable_us+=( ${rand_by_domain[$i]} )
fi
#if [[ "${rand_by_domain[$i]}" -gt "10" ]]; then
# richable_as+=( ${rand_by_domain[$i]} )
# fi
richable+=( ${rand_by_domain[$i]} )
fi
i=$(($i+1))
done
server_found="1"
if [[ "$continent" == "EU" ]]; then
len_eu=${#richable_eu[@]}
if [[ "$len_eu" -gt "0" ]]; then
richable=( ${richable_eu[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_eu" == "0" ]]; then
continent="EU"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
len_us=${#richable_us[@]}
if [[ "$len_us" -gt "0" ]]; then
richable=( ${richable_us[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_us" == "0" ]]; then
continent="US"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
server_found="0"
fi
fi
elif [[ "$continent" == "US" ]]; then
len_us=${#richable_us[@]}
if [[ "$len_us" -gt "0" ]]; then
richable=( ${richable_us[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_us" == "0" ]]; then
continent="US"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
len_as=${#richable_as[@]}
if [[ "$len_as" -gt "0" ]]; then
richable=( ${richable_as[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_as" == "0" ]]; then
continent="AS"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
len_eu=${#richable_eu[@]}
if [[ "$len_eu" -gt "0" ]]; then
richable=( ${richable_eu[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_eu" == "0" ]]; then
continent="EU"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
server_found="0"
fi
fi
fi
elif [[ "$continent" == "AS" ]]; then
len_as=${#richable_as[@]}
if [[ "$len_as" -gt "0" ]]; then
richable=( ${richable_as[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_as" == "0" ]]; then
continent="AS"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
len_us=${#richable_us[@]}
if [[ "$len_us" -gt "0" ]]; then
richable=( ${richable_us[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_us" == "0" ]]; then
continent="US"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
len_eu=${#richable_eu[@]}
if [[ "$len_eu" -gt "0" ]]; then
richable=( ${richable_eu[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len_eu" == "0" ]]; then
continent="EU"
echo -e "${WORNING} ${CYAN}All Bootstrap in $continent are offline, checking other location...${NC}" && sleep 1
server_found="0"
fi
fi
fi
else
len=${#richable[@]}
if [[ "$len" -gt "0" ]]; then
richable=( ${richable[*]} )
echo -e "${ARROW} ${CYAN}Reachable servers: ${richable[*]}${NC}"
fi
if [[ "$len" == "0" ]]; then
Server_offline=1
return 1
fi
fi
if [[ "$server_found" == "0" ]]; then
len=${#richable[@]}
if [[ "$len" == "0" ]]; then
Server_offline=1
return 1
fi
fi
Server_offline=0
}
function bootstrap_geolocation(){
IP=$WANIP
ip_output=$(curl -s -m 10 http://ip-api.com/json/$1?fields=status,country,timezone | jq .)
ip_status=$( jq -r .status <<< "$ip_output")
if [[ "$ip_status" == "success" ]]; then
country=$(jq -r .country <<< "$ip_output")
org=$(jq -r .org <<< "$ip_output")
continent=$(jq -r .timezone <<< "$ip_output")
else
country="UKNOW"
continent="UKNOW"
fi
continent=$(cut -f1 -d"/" <<< "$continent" )
if [[ "$continent" =~ "Europe" ]]; then
continent="EU"
elif [[ "$continent" =~ "America" ]]; then
continent="US"
elif [[ "$continent" =~ "Asia" ]]; then
continent="AS"
else
continent="ALL"
fi
echo -e ""
echo -e "${ARROW} ${YELLOW}Selecting bootstrap server....${NC}"
echo -e "${ARROW} ${CYAN}Node Location: $country, Continent: $continent ${NC}"
echo -e "${ARROW} ${CYAN}Searching in $continent....${NC}"
}
function config_veryfity(){
if [[ -f /home/$USER/.flux/flux.conf ]]; then
echo -e "${ARROW} ${YELLOW}Checking config file...${NC}"
insightexplorer=$(cat /home/$USER/.flux/flux.conf | grep 'insightexplorer=1' | wc -l)
if [[ "$insightexplorer" == "1" ]]; then
echo -e "${ARROW} ${CYAN}Insightexplorer enabled.............[${CHECK_MARK}${CYAN}]${NC}"
else
echo -e "${ARROW} ${CYAN}Insightexplorer enabled.............[${X_MARK}${CYAN}]${NC}"
echo -e "${ARROW} ${CYAN}Removing wallet.dat...${NC}"
echo -e "${ARROW} ${CYAN}Use old chain will be skipped...${NC}"
sudo rm -rf /home/$USER/$CONFIG_DIR/wallet.dat && sleep 1
SKIP_OLD_CHAIN="1"
fi
fi
}
function selfhosting() {
echo -e "${ARROW} ${YELLOW}Creating cron service for ip rotate...${NC}"
echo -e "${ARROW} ${CYAN}Adding IP for device...${NC}" && sleep 1
device_name=$(ip addr | grep 'BROADCAST,MULTICAST,UP,LOWER_UP' | head -n1 | awk '{print $2}' | sed 's/://' | sed 's/@/ /' | awk '{print $1}')
if [[ "$device_name" != "" && "$WANIP" != "" ]]; then
sudo ip addr add $WANIP dev $device_name:0 > /dev/null 2>&1
else
echo -e "${WORNING} ${CYAN}Problem detected operation aborted! ${NC}" && sleep 1
echo -e ""
return 1
fi
echo -e "${ARROW} ${CYAN}Creating ip check script...${NC}" && sleep 1
sudo rm /home/$USER/ip_check.sh > /dev/null 2>&1
sudo touch /home/$USER/ip_check.sh
sudo chown $USER:$USER /home/$USER/ip_check.sh
cat <<'EOF' > /home/$USER/ip_check.sh
#!/bin/bash
function get_ip(){
WANIP=$(curl --silent -m 10 https://api4.my-ip.io/ip | tr -dc '[:alnum:].')
if [[ "$WANIP" == "" || "$WANIP" = *html* ]]; then
WANIP=$(curl --silent -m 10 https://checkip.amazonaws.com | tr -dc '[:alnum:].')
fi
if [[ "$WANIP" == "" || "$WANIP" = *html* ]]; then
WANIP=$(curl --silent -m 10 https://api.ipify.org | tr -dc '[:alnum:].')
fi
}
if [[ $1 == "restart" ]]; then
# give 3min to connect with internet
sleep 180
get_ip
device_name=$(ip addr | grep 'BROADCAST,MULTICAST,UP,LOWER_UP' | head -n1 | awk '{print $2}' | sed 's/://' | sed 's/@/ /' | awk '{print $1}')
if [[ "$device_name" != "" && "$WANIP" != "" ]]; then
date_timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "New IP detected, IP: $WANIP was added at $date_timestamp" >> /home/$USER/ip_history.log
sudo ip addr add $WANIP dev $device_name:0 && sleep 2
fi
fi
if [[ $1 == "ip_check" ]]; then
get_ip
device_name=$(ip addr | grep 'BROADCAST,MULTICAST,UP,LOWER_UP' | head -n1 | awk '{print $2}' | sed 's/://' | sed 's/@/ /' | awk '{print $1}')
api_port=$(grep -w apiport /home/$USER/zelflux/config/userconfig.js | grep -o '[[:digit:]]*')
if [[ "$api_port" == "" ]]; then
api_port="16127"
fi
confirmed_ip=$(curl -SsL -m 10 http://localhost:$api_port/flux/info | jq -r .data.node.status.ip | sed -r 's/:.+//')
if [[ "$WANIP" != "" && "$confirmed_ip" != "" ]]; then
if [[ "$WANIP" != "$confirmed_ip" ]]; then
date_timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "New IP detected, IP: $WANIP was added at $date_timestamp" >> /home/$USER/ip_history.log
sudo ip addr add $WANIP dev $device_name:0 && sleep 2
fi
fi
fi
EOF
sudo chmod +x /home/$USER/ip_check.sh
echo -e "${ARROW} ${CYAN}Adding cron jobs...${NC}" && sleep 1
#crontab_check=$(sudo cat /var/spool/cron/crontabs/$USER | grep -o ip_check | wc -l)
sudo [ -f /var/spool/cron/crontabs/$USER ] && crontab_check=$(sudo cat /var/spool/cron/crontabs/$USER | grep -o ip_check | wc -l) || crontab_check=0
if [[ "$crontab_check" == "0" ]]; then
(crontab -l -u "$USER" 2>/dev/null; echo "@reboot /home/$USER/ip_check.sh restart") | crontab -
(crontab -l -u "$USER" 2>/dev/null; echo "*/15 * * * * /home/$USER/ip_check.sh ip_check") | crontab -
echo -e "${ARROW} ${CYAN}Script installed! ${NC}"
else
echo -e "${ARROW} ${CYAN}Cron jobs already added! ${NC}"
echo -e "${ARROW} ${CYAN}Script installed! ${NC}"
fi
echo -e ""
}
function max(){
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 string_limit_x_mark() {
if [[ -z "$2" ]]; then
string="$1"
string=${string::40}
else
string=$1
string_color=$2
string_leght=${#string}
string_leght_color=${#string_color}
string_diff=$((string_leght_color-string_leght))
string=${string_color::40+string_diff}
fi
echo -e "${ARROW} ${CYAN}$string[${X_MARK}${CYAN}]${NC}"
}
function integration_check() {
FILE_ARRAY=( 'fluxbench-cli' 'fluxbenchd' 'flux-cli' 'fluxd' 'flux-fetch-params.sh' 'flux-tx' )
ELEMENTS=${#FILE_ARRAY[@]}
for (( i=0;i<$ELEMENTS;i++)); do
string="${FILE_ARRAY[${i}]}................................."
string=${string::40}
if [ -f "$COIN_PATH/${FILE_ARRAY[${i}]}" ]; then
echo -e "${ARROW}${CYAN} $string[${CHECK_MARK}${CYAN}]${NC}"
else
echo -e "${ARROW}${CYAN} $string[${X_MARK}${CYAN}]${NC}"
CORRUPTED="1"
fi
done
if [[ "$CORRUPTED" == "1" ]]; then
echo -e "${WORNING} ${CYAN}Flux daemon package corrupted...${NC}"
echo -e "${WORNING} ${CYAN}Will exit out so try and run the script again...${NC}"
echo
exit
fi
echo -e ""
}
function tier(){
if [[ -f /home/$USER/$CONFIG_DIR/$CONFIG_FILE ]]; then
index_from_file=$(grep -w zelnodeindex /home/$USER/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeindex=//')
tx_from_file=$(grep -w zelnodeoutpoint /home/$USER/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeoutpoint=//')
stak_info=$(curl -s -m 5 https://explorer.runonflux.io/api/tx/$tx_from_file | jq -r ".vout[$index_from_file] | .value,.n,.scriptPubKey.addresses[0],.spentTxId" | paste - - - - | awk '{printf "%0.f %d %s %s\n",$1,$2,$3,$4}' | grep 'null' | egrep -o '10000|25000|100000|1000|12500|40000')
if [[ "$stak_info" == "" ]]; then
stak_info=$(curl -s -m 5 https://explorer.zelcash.online/api/tx/$tx_from_file | jq -r ".vout[$index_from_file] | .value,.n,.scriptPubKey.addresses[0],.spentTxId" | paste - - - - | awk '{printf "%0.f %d %s %s\n",$1,$2,$3,$4}' | grep 'null' | egrep -o '10000|25000|100000|1000|12500|40000')
fi
if [[ $stak_info == ?(-)+([0-9]) ]]; then
case $stak_info in
"25000") kadena_possible=1 ;;
"100000") kadena_possible=1 ;;
"12500") kadena_possible=1 ;;
"40000") kadena_possible=1 ;;
esac
else
kadena_possible=0
fi
fi
}
function config_file() {
if [[ -f /home/$USER/install_conf.json ]]; then
import_settings=$(cat /home/$USER/install_conf.json | jq -r '.import_settings')
#ssh_port=$(cat /home/$USER/install_conf.json | jq -r '.ssh_port')
#firewall_disable=$(cat /home/$USER/install_conf.json | jq -r '.firewall_disable')
bootstrap_url=$(cat /home/$USER/install_conf.json | jq -r '.bootstrap_url')
bootstrap_zip_del=$(cat /home/$USER/install_conf.json | jq -r '.bootstrap_zip_del')
#swapon=$(cat /home/$USER/install_conf.json | jq -r '.swapon')
#mongo_bootstrap=$(cat /home/$USER/install_conf.json | jq -r '.mongo_bootstrap')
#watchdog=$(cat /home/$USER/install_conf.json | jq -r '.watchdog')
use_old_chain=$(cat /home/$USER/install_conf.json | jq -r '.use_old_chain')
prvkey=$(cat /home/$USER/install_conf.json | jq -r '.prvkey')
outpoint=$(cat /home/$USER/install_conf.json | jq -r '.outpoint')
index=$(cat /home/$USER/install_conf.json | jq -r '.index')
ZELID=$(cat /home/$USER/install_conf.json | jq -r '.zelid')
KDA_A=$(cat /home/$USER/install_conf.json | jq -r '.kda_address')
fix_action=$(cat /home/$USER/install_conf.json | jq -r '.action')
flux_update=$(cat /home/$USER/install_conf.json | jq -r '.zelflux_update')
daemon_update=$(cat /home/$USER/install_conf.json | jq -r '.zelcash_update')
bench_update=$(cat /home/$USER/install_conf.json | jq -r '.zelbench_update')
node_label=$(cat /home/$USER/install_conf.json | jq -r '.node_label')
eps_limit=$(cat /home/$USER/install_conf.json | jq -r '.eps_limit')
discord=$(cat /home/$USER/install_conf.json | jq -r '.discord')
ping=$(cat /home/$USER/install_conf.json | jq -r '.ping')
telegram_alert=$(cat /home/$USER/install_conf.json | jq -r '.telegram_alert')
telegram_bot_token=$(cat /home/$USER/install_conf.json | jq -r '.telegram_bot_token')
telegram_chat_id=$(cat /home/$USER/install_conf.json | jq -r '.telegram_chat_id')
echo
echo -e "${ARROW} ${YELLOW}Install config:"
if [[ "$prvkey" != "" && "$outpoint" != "" && "$index" != "" ]];then
echo -e "${PIN}${CYAN} Import settings from install_conf.json...........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
if [[ "$import_settings" == "1" ]]; then
echo -e "${PIN}${CYAN} Import settings from Flux........................................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
fi
if [[ "$use_old_chain" == "1" ]]; then
echo -e "${PIN}${CYAN} Diuring re-installation old chain will be use....................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
if [[ "$bootstrap_url" == "0" ]]; then
echo -e "${PIN}${CYAN} Use Flux daemon bootstrap from source build in scripts...........[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Use Flux daemon bootstrap from own source........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
if [[ "$bootstrap_zip_del" == "1" ]]; then
echo -e "${PIN}${CYAN} Remove Flux daemon bootstrap archive file........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Leave Flux daemon bootstrap archive file.........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
fi
#if [[ "$swapon" == "1" ]]; then
#echo -e "${PIN}${CYAN} Create a file that will be used for swap.........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
#fi
#if [[ "$mongo_bootstrap" == "1" ]]; then
#echo -e "${PIN}${CYAN} Use Bootstrap for MongoDB........................................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
#fi
if [[ "$discord" != "" || "$telegram_alert" == '1' ]]; then
echo -e "${PIN}${CYAN} Enable watchdog notification.....................................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Disable watchdog notification....................................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
fi
}
function round() {
printf "%.${2}f" "${1}"
}
function check_benchmarks() {
var_benchmark=$($BENCH_CLI getbenchmarks | jq ".$1")
limit=$2
if [[ $(echo "$limit>$var_benchmark" | bc) == "1" ]]
then
var_round=$(round "$var_benchmark" 2)
echo -e "${X_MARK} ${CYAN}$3 $var_round $4${NC}"
fi
}
function import_date() {
if [[ -f /home/$USER/$CONFIG_DIR/$CONFIG_FILE || -f /home/$USER/.zelcash/zelcash.conf ]]; then
if [[ -z "$import_settings" ]]; then
if whiptail --yesno "Would you like to import data from Flux config files Y/N?" 8 60; then
OLD_CONFIG=0
if [[ -d /home/$USER/.zelcash ]]; then
CONFIG_DIR='.zelcash'
CONFIG_FILE='zelcash.conf'
OLD_CONFIG=1
fi
IMPORT_ZELCONF="1"
echo
echo -e "${ARROW} ${YELLOW}Imported settings:${NC}"
zelnodeprivkey=$(grep -w zelnodeprivkey ~/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeprivkey=//')
echo -e "${PIN}${CYAN} Identity Key = ${GREEN}$zelnodeprivkey${NC}" && sleep 1
zelnodeoutpoint=$(grep -w zelnodeoutpoint ~/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeoutpoint=//')
echo -e "${PIN}${CYAN} Collateral TX ID = ${GREEN}$zelnodeoutpoint${NC}" && sleep 1
zelnodeindex=$(grep -w zelnodeindex ~/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeindex=//')
echo -e "${PIN}${CYAN} Output Index = ${GREEN}$zelnodeindex${NC}" && sleep 1
if [[ "$OLD_CONFIG" == "1" ]]; then
CONFIG_DIR='.flux'
CONFIG_FILE='flux.conf'
fi
if [[ -f ~/$FLUX_DIR/config/userconfig.js ]]; then
ZELID=$(grep -w zelid ~/$FLUX_DIR/config/userconfig.js | sed -e 's/.*zelid: .//' | sed -e 's/.\{2\}$//')
if [[ "$ZELID" != "" ]]; then
echo -e "${PIN}${CYAN} Zel ID = ${GREEN}$ZELID${NC}" && sleep 1
IMPORT_ZELID="1"
fi
KDA_A=$(grep -w kadena ~/$FLUX_DIR/config/userconfig.js | sed -e 's/.*kadena: .//' | sed -e 's/.\{2\}$//')
if [[ "$KDA_A" != "" ]]; then
echo -e "${PIN}${CYAN} KDA address = ${GREEN}$KDA_A${NC}" && sleep 1
fi
echo -e ""
echo -e "${ARROW} ${YELLOW}Imported watchdog settings:${NC}"
node_label=$(grep -w label /home/$USER/watchdog/config.js | sed -e 's/.*label: .//' | sed -e 's/.\{2\}$//')
if [[ "$node_label" != "" && "$node_label" != "0" ]]; then
echo -e "${PIN}${CYAN} Label = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Label = ${RED}Disabled${NC}" && sleep 1
fi
eps_limit=$(grep -w tier_eps_min /home/$USER/watchdog/config.js | sed -e 's/.*tier_eps_min: .//' | sed -e 's/.\{2\}$//')
echo -e "${PIN}${CYAN} Tier_eps_min = ${GREEN}$eps_limit${NC}" && sleep 1
discord=$(grep -w web_hook_url /home/$USER/watchdog/config.js | sed -e 's/.*web_hook_url: .//' | sed -e 's/.\{2\}$//')
if [[ "$discord" != "" && "$discord" != "0" ]]; then
echo -e "${PIN}${CYAN} Discord alert = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Discord alert = ${RED}Disabled${NC}" && sleep 1
fi
ping=$(grep -w ping /home/$USER/watchdog/config.js | sed -e 's/.*ping: .//' | sed -e 's/.\{2\}$//')
if [[ "$ping" != "" && "$ping" != "0" ]]; then
if [[ "$discord" != "" && "$discord" != "0" ]]; then
echo -e "${PIN}${CYAN} Discord ping = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Discord ping = ${RED}Disabled${NC}" && sleep 1
fi
fi
telegram_alert=$(grep -w telegram_alert /home/$USER/watchdog/config.js | sed -e 's/.*telegram_alert: .//' | sed -e 's/.\{2\}$//')
if [[ "$telegram_alert" != "" && "$telegram_alert" != "0" ]]; then
echo -e "${PIN}${CYAN} Telegram alert = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Telegram alert = ${RED}Disabled${NC}" && sleep 1
fi
telegram_bot_token=$(grep -w telegram_bot_token /home/$USER/watchdog/config.js | sed -e 's/.*telegram_bot_token: .//' | sed -e 's/.\{2\}$//')
if [[ "$telegram_alert" == "1" ]]; then
echo -e "${PIN}${CYAN} Telegram bot token = ${GREEN}$telegram_alert${NC}" && sleep 1
fi
telegram_chat_id=$(grep -w telegram_chat_id /home/$USER/watchdog/config.js | sed -e 's/.*telegram_chat_id: .//' | sed -e 's/.\{1\}$//')
if [[ "$telegram_alert" == "1" ]]; then
echo -e "${PIN}${CYAN} Telegram chat id = ${GREEN}$telegram_chat_id${NC}" && sleep 1
fi
fi
fi
else
if [[ "$import_settings" == "1" ]]; then
OLD_CONFIG=0
if [[ -d /home/$USER/.zelcash ]]; then
CONFIG_DIR='.zelcash'
CONFIG_FILE='zelcash.conf'
OLD_CONFIG=1
fi
IMPORT_ZELCONF="1"
echo
echo -e "${ARROW} ${YELLOW}Imported settings:${NC}"
zelnodeprivkey=$(grep -w zelnodeprivkey ~/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeprivkey=//')
echo -e "${PIN}${CYAN} Identity Key = ${GREEN}$zelnodeprivkey${NC}" && sleep 1
zelnodeoutpoint=$(grep -w zelnodeoutpoint ~/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeoutpoint=//')
echo -e "${PIN}${CYAN} Output TX ID = ${GREEN}$zelnodeoutpoint${NC}" && sleep 1
zelnodeindex=$(grep -w zelnodeindex ~/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeindex=//')
echo -e "${PIN}${CYAN} Output Index = ${GREEN}$zelnodeindex${NC}" && sleep 1
if [[ "$OLD_CONFIG" == "1" ]]; then
CONFIG_DIR='.flux'
CONFIG_FILE='flux.conf'
fi
if [[ -f ~/$FLUX_DIR/config/userconfig.js ]]; then
ZELID=$(grep -w zelid ~/$FLUX_DIR/config/userconfig.js | sed -e 's/.*zelid: .//' | sed -e 's/.\{2\}$//')
if [[ "$ZELID" != "" ]]; then
echo -e "${PIN}${CYAN} Zel ID = ${GREEN}$ZELID${NC}" && sleep 1
IMPORT_ZELID="1"
fi
KDA_A=$(grep -w kadena ~/$FLUX_DIR/config/userconfig.js | sed -e 's/.*kadena: .//' | sed -e 's/.\{2\}$//')
if [[ "$KDA_A" != "" ]]; then
echo -e "${PIN}${CYAN} KDA address = ${GREEN}$KDA_A${NC}" && sleep 1
fi
fi
echo -e ""
echo -e "${ARROW} ${YELLOW}Imported watchdog settings:${NC}"
node_label=$(grep -w label /home/$USER/watchdog/config.js | sed -e 's/.*label: .//' | sed -e 's/.\{2\}$//')
if [[ "$node_label" != "" && "$node_label" != "0" ]]; then
echo -e "${PIN}${CYAN} Label = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Label = ${RED}Disabled${NC}" && sleep 1
fi
eps_limit=$(grep -w tier_eps_min /home/$USER/watchdog/config.js | sed -e 's/.*tier_eps_min: .//' | sed -e 's/.\{2\}$//')
echo -e "${PIN}${CYAN} Tier_eps_min = ${GREEN}$eps_limit${NC}" && sleep 1
discord=$(grep -w web_hook_url /home/$USER/watchdog/config.js | sed -e 's/.*web_hook_url: .//' | sed -e 's/.\{2\}$//')
if [[ "$discord" != "" && "$discord" != "0" ]]; then
echo -e "${PIN}${CYAN} Discord alert = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Discord alert = ${RED}Disabled${NC}" && sleep 1
fi
ping=$(grep -w ping /home/$USER/watchdog/config.js | sed -e 's/.*ping: .//' | sed -e 's/.\{2\}$//')
if [[ "$ping" != "" && "$ping" != "0" ]]; then
if [[ "$discord" != "" && "$discord" != "0" ]]; then
echo -e "${PIN}${CYAN} Discord ping = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Discord ping = ${RED}Disabled${NC}" && sleep 1
fi
fi
telegram_alert=$(grep -w telegram_alert /home/$USER/watchdog/config.js | sed -e 's/.*telegram_alert: .//' | sed -e 's/.\{2\}$//')
if [[ "$telegram_alert" != "" && "$telegram_alert" != "0" ]]; then
echo -e "${PIN}${CYAN} Telegram alert = ${GREEN}Enabled${NC}" && sleep 1
else
echo -e "${PIN}${CYAN} Telegram alert = ${RED}Disabled${NC}" && sleep 1
fi
telegram_bot_token=$(grep -w telegram_bot_token /home/$USER/watchdog/config.js | sed -e 's/.*telegram_bot_token: .//' | sed -e 's/.\{2\}$//')
if [[ "$telegram_alert" == "1" ]]; then
echo -e "${PIN}${CYAN} Telegram bot token = ${GREEN}$telegram_alert${NC}" && sleep 1
fi
telegram_chat_id=$(grep -w telegram_chat_id /home/$USER/watchdog/config.js | sed -e 's/.*telegram_chat_id: .//' | sed -e 's/.\{1\}$//')
if [[ "$telegram_alert" == "1" ]]; then
echo -e "${PIN}${CYAN} Telegram chat id = ${GREEN}$telegram_chat_id${NC}" && sleep 1
fi
fi
fi
fi
sleep 1
echo
}
function tar_file_unpack()
{
echo -e "${ARROW} ${YELLOW}Unpacking bootstrap archive file...${NC}"
pv $1 | tar -zx -C $2
}
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 install_watchdog() {
echo -e "${ARROW} ${YELLOW}Install watchdog for FluxNode${NC}"
if pm2 -v > /dev/null 2>&1
then
WATCHDOG_INSTALL="1"
echo -e "${ARROW} ${YELLOW}Downloading...${NC}"
cd && git clone https://github.com/RunOnFlux/fluxnode-watchdog.git watchdog > /dev/null 2>&1
echo -e "${ARROW} ${YELLOW}Installing git hooks....${NC}"
wget https://raw.githubusercontent.com/RunOnFlux/fluxnode-multitool/master/post-merge > /dev/null 2>&1
mv post-merge /home/$USER/watchdog/.git/hooks/post-merge
sudo chmod +x /home/$USER/watchdog/.git/hooks/post-merge
echo -e "${ARROW} ${YELLOW}Installing watchdog module....${NC}"
cd watchdog && npm install > /dev/null 2>&1
echo -e "${ARROW} ${CYAN}Creating config file....${NC}"
fix_action='1'
if [[ "$import_settings" == "0" && -f /home/$USER/install_conf.json ]]; then
sudo touch /home/$USER/watchdog/config.js
sudo chown $USER:$USER /home/$USER/watchdog/config.js
cat << EOF > /home/$USER/watchdog/config.js
module.exports = {
label: '${node_label}',
tier_eps_min: '${eps_limit}',
zelflux_update: '${flux_update}',
zelcash_update: '${daemon_update}',
zelbench_update: '${bench_update}',
action: '${fix_action}',
ping: '${ping}',
web_hook_url: '${discord}',
telegram_alert: '${telegram_alert}',
telegram_bot_token: '${telegram_bot_token}',
telegram_chat_id: '${telegram_chat_id}'
}
EOF
if [[ -f /home/$USER/watchdog/watchdog.js ]]; then
current_ver=$(jq -r '.version' /home/$USER/watchdog/package.json)
string_limit_check_mark "Watchdog v$current_ver installed................................." "Watchdog ${GREEN}v$current_ver${CYAN} installed................................."
#echo -e "${ARROW} ${YELLOW}Starting watchdog...${NC}"
pm2 start /home/$USER/watchdog/watchdog.js --name watchdog --watch /home/$USER/watchdog --ignore-watch '"./**/*.git" "./**/*node_modules" "./**/*watchdog_error.log" "./**/*config.js"' --watch-delay 20 > /dev/null 2>&1
pm2 save > /dev/null 2>&1
else
string_limit_x_mark "Watchdog was not installed................................."
fi
return 1
fi
if [[ "$IMPORT_ZELCONF" == "1" ]]; then
sudo touch /home/$USER/watchdog/config.js
sudo chown $USER:$USER /home/$USER/watchdog/config.js
cat << EOF > /home/$USER/watchdog/config.js
module.exports = {
label: '${node_label}',
tier_eps_min: '${eps_limit}',
zelflux_update: '${flux_update}',
zelcash_update: '${daemon_update}',
zelbench_update: '${bench_update}',
action: '${fix_action}',
ping: '${ping}',
web_hook_url: '${discord}',
telegram_alert: '${telegram_alert}',
telegram_bot_token: '${telegram_bot_token}',
telegram_chat_id: '${telegram_chat_id}'
}
EOF
if [[ -f /home/$USER/watchdog/watchdog.js ]]; then
current_ver=$(jq -r '.version' /home/$USER/watchdog/package.json)
string_limit_check_mark "Watchdog v$current_ver installed................................." "Watchdog ${GREEN}v$current_ver${CYAN} installed................................."
echo -e "${ARROW} ${YELLOW}Starting watchdog...${NC}"
pm2 start /home/$USER/watchdog/watchdog.js --name watchdog --watch /home/$USER/watchdog --ignore-watch '"./**/*.git" "./**/*node_modules" "./**/*watchdog_error.log" "./**/*config.js"' --watch-delay 20 > /dev/null 2>&1
pm2 save > /dev/null 2>&1
else
string_limit_x_mark "Watchdog was not installed................................."
fi
return 1
fi
if whiptail --yesno "Would you like enable autoupdate?" 8 60; then
flux_update='1'
daemon_update='1'
bench_update='1'
else
flux_update='0'
daemon_update='0'
bench_update='0'
fi
discord='0'
if whiptail --yesno "Would you like enable alert notification?" 8 60; then
sleep 1
whiptail --msgbox "Info: to select/deselect item use 'space' ...to switch to OK/Cancel use 'tab' " 10 60
sleep 1
CHOICES=$(whiptail --title "Choose options: " --separate-output --checklist "Choose options: " 10 45 5 \
"1" "Discord notification " ON \
"2" "Telegram notification " OFF 3>&1 1>&2 2>&3 )
if [ -z "$CHOICES" ]; then
echo -e "${ARROW} ${CYAN}No option was selected...Alert notification disabled! ${NC}"
sleep 1
discord="0"
ping="0"
telegram_alert="0"
telegram_bot_token="0"
telegram_chat_id="0"
node_label="0"
else
for CHOICE in $CHOICES; do
case "$CHOICE" in
"1")
discord=$(whiptail --inputbox "Enter your discord server webhook url" 8 65 3>&1 1>&2 2>&3)
sleep 1
if whiptail --yesno "Would you like enable nick ping on discord?" 8 60; then
while true
do
ping=$(whiptail --inputbox "Enter your discord user id" 8 60 3>&1 1>&2 2>&3)
if [[ $ping == ?(-)+([0-9]) ]]; then
string_limit_check_mark "UserID is valid..........................................."
break
else
string_limit_x_mark "UserID is not valid try again............................."
sleep 1
fi
done
sleep 1
else
ping=0;
sleep 1
fi
;;
"2")
telegram_alert="1"
while true
do
telegram_bot_token=$(whiptail --inputbox "Enter telegram bot token from BotFather" 8 65 3>&1 1>&2 2>&3)
if [[ $(grep ':' <<< "$telegram_bot_token") != "" ]]; then
string_limit_check_mark "Bot token is valid..........................................."
break
else
string_limit_x_mark "Bot token is not valid try again............................."
sleep 1
fi
done
sleep 1
while true
do
telegram_chat_id=$(whiptail --inputbox "Enter your chat id from GetIDs Bot" 8 60 3>&1 1>&2 2>&3)
if [[ $telegram_chat_id == ?(-)+([0-9]) ]]; then
string_limit_check_mark "Chat ID is valid..........................................."
break
else
string_limit_x_mark "Chat ID is not valid try again............................."
sleep 1
fi
done
sleep 1
;;
esac
done
fi
while true
do
node_label=$(whiptail --inputbox "Enter name of your node (alias)" 8 65 3>&1 1>&2 2>&3)
if [[ "$node_label" != "" && "$node_label" != "0" ]]; then
string_limit_check_mark "Node name is valid..........................................."
break
else
string_limit_x_mark "Node name is not valid try again............................."
sleep 1
fi
done
else
discord="0"
ping="0"
telegram_alert="0"
telegram_bot_token="0"
telegram_chat_id="0"
node_label="0"
sleep 1
fi
if [[ "$discord" == 0 ]]; then
ping="0";
fi
if [[ "$telegram_alert" == 0 ]]; then
telegram_bot_token="0";
telegram_chat_id="0";
fi
if [[ -f /home/$USER/$CONFIG_DIR/$CONFIG_FILE ]]; then
index_from_file=$(grep -w zelnodeindex /home/$USER/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeindex=//')
tx_from_file=$(grep -w zelnodeoutpoint /home/$USER/$CONFIG_DIR/$CONFIG_FILE | sed -e 's/zelnodeoutpoint=//')
stak_info=$(curl -s -m 5 https://explorer.runonflux.io/api/tx/$tx_from_file | jq -r ".vout[$index_from_file] | .value,.n,.scriptPubKey.addresses[0],.spentTxId" | paste - - - - | awk '{printf "%0.f %d %s %s\n",$1,$2,$3,$4}' | grep 'null' | egrep -o '10000|25000|100000|1000|12500|40000')
if [[ "$stak_info" == "" ]]; then
stak_info=$(curl -s -m 5 https://explorer.zelcash.online/api/tx/$tx_from_file | jq -r ".vout[$index_from_file] | .value,.n,.scriptPubKey.addresses[0],.spentTxId" | paste - - - - | awk '{printf "%0.f %d %s %s\n",$1,$2,$3,$4}' | grep 'null' | egrep -o '10000|25000|100000|1000|12500|40000')
fi
fi
if [[ $stak_info == ?(-)+([0-9]) ]]; then
case $stak_info in
"10000") eps_limit=90 ;;
"25000") eps_limit=180 ;;
"100000") eps_limit=300 ;;
"1000") eps_limit=90 ;;
"12500") eps_limit=180 ;;
"40000") eps_limit=300 ;;
esac
else