forked from XK4MiLX/zelnode
-
Notifications
You must be signed in to change notification settings - Fork 29
/
multitoolbox_testnet.sh
1331 lines (1042 loc) · 43.2 KB
/
multitoolbox_testnet.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
if ! [[ -z $1 ]]; then
if [[ $BRANCH_ALREADY_REFERENCED != '1' ]]; then
export ROOT_BRANCH="$1"
export BRANCH_ALREADY_REFERENCED='1'
bash -i <(curl -s https://raw.githubusercontent.com/RunOnFlux/fluxnode-multitool/$ROOT_BRANCH/multitoolbox_testnet.sh) $ROOT_BRANCH
unset ROOT_BRANCH
unset BRANCH_ALREADY_REFERENCED
exit
fi
else
export ROOT_BRANCH='master'
fi
source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/RunOnFlux/fluxnode-multitool/$ROOT_BRANCH/flux_common.sh)"
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='http://202.61.207.10:16127/apps/fluxshare/getfile/kda_bootstrap.tar.gz?token=a705701758411b28ea20325ef9654e31e3d8f5f03a24b4e4e662e601a1250859'
if [[ -d /home/$USER/.zelcash ]]; then
CONFIG_DIR='.zelcash'
CONFIG_FILE='zelcash.conf'
else
CONFIG_DIR='.flux'
CONFIG_FILE='flux.conf'
fi
FLUX_DIR='zelflux'
FLUX_APPS_DIR='ZelApps'
COIN_NAME='zelcash'
dversion="v6.1"
PM2_INSTALL="0"
zelflux_setting_import="0"
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')
zel_id=$(cat /home/$USER/install_conf.json | jq -r '.zelid')
kda_address=$(cat /home/$USER/install_conf.json | jq -r '.kda_address')
echo -e "${ARROW} ${YELLOW}Install config summary:"
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 exist config files..........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
fi
if [[ "$ssh_port" != "" ]]; then
string_limit_check_mark_port "SSH port: $ssh_port ...................................................................." "SSH port: ${GREEN}$ssh_port ${CYAN}...................................................................."
sleep 1
fi
if [[ "$firewall_disable" == "1" ]]; then
echo -e "${PIN}${CYAN}Firewall disabled diuring installation...........................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
echo -e "${PIN}${CYAN}Firewall enabled diuring installation............................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
if [[ "$use_old_chain" == "1" ]]; then
echo -e "${PIN}${CYAN}During re-installation old chain will be use....................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
if [[ "$bootstrap_url" == "" ]]; then
echo -e "${PIN}${CYAN}Use Flux Bootstrap from source build in scripts..................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
echo -e "${PIN}${CYAN}Use Flux Bootstrap from own source...............................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
if [[ "$bootstrap_zip_del" == "1" ]]; then
echo -e "${PIN}${CYAN}Remove Flux Bootstrap archive file...............................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
else
echo -e "${PIN}${CYAN}Leave Flux 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 [[ "$watchdog" == "1" ]]; then
echo -e "${PIN}${CYAN}Install watchdog.................................................[${CHECK_MARK}${CYAN}]${NC}" && sleep 1
fi
fi
}
function install_flux() {
echo -e "${GREEN}Module: Re-install FluxOS${NC}"
echo -e "${YELLOW}================================================================${NC}"
if [[ "$USER" == "root" || "$USER" == "ubuntu" ]]; then
echo -e "${CYAN}You are currently logged in as ${GREEN}$USER${NC}"
echo -e "${CYAN}Please switch to the user account.${NC}"
echo -e "${YELLOW}================================================================${NC}"
echo -e "${NC}"
exit
fi
if pm2 -v > /dev/null 2>&1; then
pm2 del zelflux > /dev/null 2>&1
pm2 del flux > /dev/null 2>&1
pm2 save > /dev/null 2>&1
fi
docker_check=$(docker container ls -a | egrep 'zelcash|flux' | 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" ]]; 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}Removing containers...${NC}"
sudo aa-remove-unknown && sudo service docker restart > /dev/null 2>&1 && sleep 2
sleep 5
#docker ps | grep -Eo "^[0-9a-z]{8,}\b" |
docker container ls -a | egrep 'zelcash|flux' | grep -Eo "^[0-9a-z]{8,}\b" |
while read line; do
sudo docker stop $line > /dev/null 2>&1 && sleep 2
sudo docker rm $line > /dev/null 2>&1 && 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 -l $line && sleep 1
done
fi
if [ -f /home/$USER/$FLUX_DIR/config/userconfig.js ]; then
echo -e "${ARROW} ${CYAN}Importing setting...${NC}"
zel_id=$(grep -w zelid /home/$USER/$FLUX_DIR/config/userconfig.js | sed -e 's/.*zelid: .//' | sed -e 's/.\{2\}$//')
WANIP=$(grep -w ipaddress /home/$USER/$FLUX_DIR/config/userconfig.js | sed -e 's/.*ipaddress: .//' | sed -e 's/.\{2\}$//')
echo -e "${PIN}${CYAN}Zel ID = ${GREEN}$zel_id${NC}" && sleep 1
KDA_A=$(grep -w kadena /home/$USER/$FLUX_DIR/config/userconfig.js | sed -e 's/.*kadena: .//' | sed -e 's/.\{2\}$//')
if [[ "$KDA_A" != "" ]]; then
echo -e "${PIN}${CYAN}Kadena address = ${GREEN}$KDA_A${NC}" && sleep 1
fi
echo -e "${PIN}${CYAN}IP = ${GREEN}$WANIP${NC}" && sleep 1
echo
echo -e "${ARROW} ${CYAN}Removing any instances of Flux....${NC}"
sudo rm -rf $FLUX_DIR > /dev/null 2>&1 && sleep 2
#sudo rm -rf zelflux > /dev/null 2>&1 && sleep 2
zelflux_setting_import="1"
fi
if [ -d /home/$USER/$FLUX_DIR ]; then
echo -e "${ARROW} ${CYAN}Removing any instances of Flux....${NC}"
#sudo rm -rf zelflux > /dev/null 2>&1 && sleep 2
sudo rm -rf $FLUX_DIR > /dev/null 2>&1 && sleep 2
fi
echo -e "${ARROW} ${CYAN}Flux downloading...${NC}"
git clone https://github.com/RunOnFlux/flux.git zelflux > /dev/null 2>&1 && sleep 2
cd zelflux
echo -e "${ARROW} ${YELLOW}Changing to test branch...${NC}"
git checkout testnet > /dev/null 2>&1
#git clone --single-branch --branch development https://github.com/RunOnFlux/flux.git zelflux > /dev/null 2>&1 && sleep 2
if [ -d /home/$USER/$FLUX_DIR ]
then
if [[ -f /home/$USER/$FLUX_DIR/package.json ]]; then
current_ver=$(jq -r '.version' /home/$USER/$FLUX_DIR/package.json)
else
string_limit_x_mark "Flux was not downloaded, run script again..........................................."
echo
exit
fi
string_limit_check_mark "Flux v$current_ver downloaded..........................................." "Flux ${GREEN}v$current_ver${CYAN} downloaded..........................................."
else
string_limit_x_mark "Flux was not downloaded, run script again..........................................."
echo
exit
fi
if [[ "$zelflux_setting_import" == "0" ]]; then
ip_confirm
while true
do
zel_id="$(whiptail --title "MULTITOOLBOX" --inputbox "Enter your ZEL ID from ZelCore (Apps -> Zel ID (CLICK QR CODE)) " 8 72 3>&1 1>&2 2>&3)"
if [ $(printf "%s" "$zel_id" | wc -c) -eq "34" ] || [ $(printf "%s" "$zel_id" | wc -c) -eq "33" ] || [ $(grep -Eo "^0x[a-fA-F0-9]{40}$" <<< "$zel_id") ]; then
string_limit_check_mark "Zel ID is valid..........................................."
break
else
string_limit_x_mark "Zel ID is not valid try again..........................................."
sleep 2
fi
done
touch ~/$FLUX_DIR/config/userconfig.js
cat << EOF > ~/$FLUX_DIR/config/userconfig.js
module.exports = {
initial: {
ipaddress: '${WANIP}',
zelid: '${zel_id}',
testnet: true
}
}
EOF
else
if [[ "$KDA_A" != "" ]]; then
touch ~/$FLUX_DIR/config/userconfig.js
cat << EOF > ~/$FLUX_DIR/config/userconfig.js
module.exports = {
initial: {
ipaddress: '${WANIP}',
zelid: '${zel_id}',
kadena: '${KDA_A}',
testnet: true,
}
}
EOF
else
touch ~/$FLUX_DIR/config/userconfig.js
cat << EOF > ~/$FLUX_DIR/config/userconfig.js
module.exports = {
initial: {
ipaddress: '${WANIP}',
zelid: '${zel_id}',
testnet: true
}
}
EOF
fi
fi
if [[ -f /home/$USER/$FLUX_DIR/config/userconfig.js ]]; then
string_limit_check_mark "Flux configuration successfull..........................................."
else
string_limit_x_mark "Flux installation failed, missing config file..........................................."
echo
exit
fi
if pm2 -v > /dev/null 2>&1; then
rm restart_zelflux.sh > /dev/null 2>&1
pm2 del flux > /dev/null 2>&1
pm2 del zelflux > /dev/null 2>&1
pm2 save > /dev/null 2>&1
echo -e "${ARROW} ${CYAN}Starting Flux....${NC}"
echo -e "${ARROW} ${CYAN}Flux loading will take 2-3min....${NC}"
echo
pm2 start /home/$USER/$FLUX_DIR/start.sh --restart-delay=60000 --max-restarts=40 --name flux --time > /dev/null 2>&1
pm2 save > /dev/null 2>&1
pm2 list
else
pm2_install()
if [[ "$PM2_INSTALL" == "1" ]]; then
echo -e "${ARROW} ${CYAN}Starting Flux....${NC}"
echo -e "${ARROW} ${CYAN}Flux loading will take 2-3min....${NC}"
echo
pm2 list
fi
fi
}
function create_config() {
if [[ "$USER" == "root" || "$USER" == "ubuntu" || "$USER" == "admin" ]]; then
echo -e "${CYAN}You are currently logged in as ${GREEN}$USER${NC}"
echo -e "${CYAN}Please switch to the user account.${NC}"
echo -e "${YELLOW}================================================================${NC}"
echo -e "${NC}"
exit
fi
echo -e "${GREEN}Module: Create FluxNode installation config file${NC}"
echo -e "${YELLOW}================================================================${NC}"
if jq --version > /dev/null 2>&1; then
sleep 0.2
else
echo -e "${ARROW} ${YELLOW}Installing JQ....${NC}"
sudo apt install jq -y > /dev/null 2>&1
if jq --version > /dev/null 2>&1
then
#echo -e "${ARROW} ${CYAN}Nodejs version: ${GREEN}$(node -v)${CYAN} installed${NC}"
string_limit_check_mark "JQ $(jq --version) installed................................." "JQ ${GREEN}$(jq --version)${CYAN} installed................................."
echo
else
#echo -e "${ARROW} ${CYAN}Nodejs was not installed${NC}"
string_limit_x_mark "JQ was not installed................................."
echo
exit
fi
fi
skip_zelcash_config='0'
skip_bootstrap='0'
if [[ -d /home/$USER/$CONFIG_DIR ]]; then
if whiptail --yesno "Would you like import old settings from daemon and Flux?" 8 65; then
import_settings='1'
skip_zelcash_config='1'
sleep 1
else
import_settings='0'
sleep 1
fi
if whiptail --yesno "Would you like use exist Flux chain?" 8 65; then
use_old_chain='1'
skip_bootstrap='1'
sleep 1
else
use_old_chain='0'
sleep 1
fi
fi
if [[ "$skip_zelcash_config" == "1" ]]; then
prvkey=""
outpoint=""
index=""
zelid=""
kda_address=""
else
prvkey=$(whiptail --inputbox "Enter your FluxNode Identity Key from Zelcore" 8 65 3>&1 1>&2 2>&3)
sleep 1
outpoint=$(whiptail --inputbox "Enter your FluxNode Collateral Output TX ID from Zelcore" 8 72 3>&1 1>&2 2>&3)
sleep 1
index=$(whiptail --inputbox "Enter your FluxNode Output Index from Zelcore" 8 65 3>&1 1>&2 2>&3)
sleep 1
zel_id=$(whiptail --inputbox "Enter your ZEL ID from ZelCore (Apps -> Zel ID (CLICK QR CODE)) " 8 72 3>&1 1>&2 2>&3)
sleep 1
KDA_A=$(whiptail --inputbox "Please enter your Kadena address from Zelcore" 8 85 3>&1 1>&2 2>&3)
sleep 1
KDA_C=$(whiptail --inputbox "Please enter your kadena chainid (0-19)" 8 85 3>&1 1>&2 2>&3)
if [[ "$KDA_A" == "" ]]; then
kda_address=""
else
kda_address="kadena:$KDA_A?chainid=$KDA_C"
fi
fi
ssh_port=$(whiptail --inputbox "Enter port you are using for SSH (default 22)" 8 65 3>&1 1>&2 2>&3)
sleep 1
pettern='^[0-9]+$'
if [[ $ssh_port =~ $pettern ]] ; then
sleep 1
else
echo -e "${ARROW} ${CYAN}SSH port must be integer.................................[${X_MARK}${CYAN}]${NC}"
echo
exit
fi
if whiptail --yesno "Would you like disable firewall diuring installation?" 8 65; then
firewall_disable='1'
sleep 1
else
firewall_disable='0'
sleep 1
fi
if [[ "$skip_bootstrap" == "0" ]]; then
if whiptail --yesno "Would you like use Flux bootstrap from script source?" 8 65; then
bootstrap_url="$BOOTSTRAP_ZIP"
sleep 1
else
bootstrap_url=$(whiptail --inputbox "Enter your Flux bootstrap URL" 8 65 3>&1 1>&2 2>&3)
sleep 1
fi
if whiptail --yesno "Would you like keep bootstrap archive file localy?" 8 65; then
bootstrap_zip_del='0'
sleep 1
else
bootstrap_zip_del='1'
sleep 1
fi
fi
if whiptail --yesno "Would you like create swapfile?" 8 65; then
swapon='1'
sleep 1
else
swapon='0'
sleep 1
fi
if whiptail --yesno "Would you like use mongod bootstrap file?" 8 65; then
mongo_bootstrap='1'
sleep 1
else
mongo_bootstrap='0'
sleep 1
fi
if whiptail --yesno "Would you like install FluxNode watchdog?" 8 65; then
watchdog='1'
sleep 1
else
watchdog='0'
sleep 1
fi
rm /home/$USER/install_conf.json > /dev/null 2>&1
sudo touch /home/$USER/install_conf.json
sudo chown $USER:$USER /home/$USER/install_conf.json
cat << EOF > /home/$USER/install_conf.json
{
"import_settings": "${import_settings}",
"prvkey": "${prvkey}",
"outpoint": "${outpoint}",
"index": "${index}",
"zelid": "${zel_id}",
"kda_address": "${kda_address}",
"ssh_port": "${ssh_port}",
"firewall_disable": "${firewall_disable}",
"bootstrap_url": "${bootstrap_url}",
"bootstrap_zip_del": "${bootstrap_zip_del}",
"swapon": "${swapon}",
"mongo_bootstrap": "${mongo_bootstrap}",
"use_old_chain": "${use_old_chain}",
"watchdog": "${watchdog}"
}
EOF
config_file
echo
}
function install_watchdog() {
if [[ "$USER" == "root" || "$USER" == "ubuntu" || "$USER" == "admin" ]]; then
echo -e "${CYAN}You are currently logged in as ${GREEN}$USER${NC}"
echo -e "${CYAN}Please switch to the user account.${NC}"
echo -e "${YELLOW}================================================================${NC}"
echo -e "${NC}"
exit
fi
echo -e "${GREEN}Module: Install watchdog for FluxNode${NC}"
echo -e "${YELLOW}================================================================${NC}"
if ! pm2 -v > /dev/null 2>&1
then
pm2_install
if [[ "$PM2_INSTALL" == "0" ]]; then
exit
fi
echo -e ""
fi
echo -e "${ARROW} ${CYAN}Cleaning...${NC}"
pm2 del watchdog > /dev/null 2>&1
pm2 save > /dev/null 2>&1
sudo rm -rf /home/$USER/watchdog > /dev/null 2>&1
echo -e "${ARROW} ${CYAN}Downloading...${NC}"
cd && git clone https://github.com/RunOnFlux/fluxnode-watchdog.git watchdog > /dev/null 2>&1
echo -e "${ARROW} ${CYAN}Installing git hooks....${NC}"
wget https://raw.githubusercontent.com/RunOnFlux/fluxnode-multitool/$ROOT_BRANCH/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} ${CYAN}Installing watchdog module....${NC}"
cd watchdog && npm install > /dev/null 2>&1
echo -e "${ARROW} ${CYAN}Creating config file....${NC}"
#if whiptail --yesno "Would you like enable FluxOS auto update?" 8 60; then
flux_update='1'
#sleep 1
#else
##flux_update='0'
#sleep 1
#fi
#if whiptail --yesno "Would you like enable Flux daemon auto update?" 8 60; then
daemon_update='1'
##sleep 1
#else
#daemon_update='0'
##sleep 1
#fi
#if whiptail --yesno "Would you like enable Flux benchmark auto update?" 8 60; then
bench_update='1'
#sleep 1
#else
##bench_update='0'
##sleep 1
#fi
#if whiptail --yesno "Would you like enable fix action (restart daemon, benchmark, mongodb)?" 8 75; then
fix_action='1'
#sleep 1
#else
#fix_action='0'
##sleep 1
#fi
telegram_alert=0;
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
sleep 1
else
node_label=0;
discord=0;
ping=0;
telegram_alert=0;
telegram_bot_token=0;
telegram_chat_id=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')
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')
fi
fi
if [[ $stak_info == ?(-)+([0-9]) ]]; then
case $stak_info in
"10000") eps_limit=90 ;;
"25000") eps_limit=180 ;;
"100000") eps_limit=300 ;;
esac
else
eps_limit=0;
fi
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
echo -e "${ARROW} ${CYAN}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
if [[ -f /home/$USER/watchdog/watchdog.js ]]
then
current_ver=$(jq -r '.version' /home/$USER/watchdog/package.json)
#echo -e "${ARROW} ${CYAN}Watchdog ${GREEN}v$current_ver${CYAN} installed successful.${NC}"
string_limit_check_mark "Watchdog v$current_ver installed..........................................." "Watchdog ${GREEN}v$current_ver${CYAN} installed..........................................."
else
#echo -e "${ARROW} ${CYAN}Watchdog installion failed.${NC}"
string_limit_x_mark "Watchdog was not installed..........................................."
fi
echo
}
function flux_daemon_bootstrap() {
echo -e "${GREEN}Module: Restore Flux blockchain from bootstrap${NC}"
echo -e "${YELLOW}================================================================${NC}"
if [[ "$USER" == "root" || "$USER" == "ubuntu" || "$USER" == "admin" ]]; then
echo -e "${CYAN}You are currently logged in as ${GREEN}$USER${NC}"
echo -e "${CYAN}Please switch to the user account.${NC}"
echo -e "${YELLOW}================================================================${NC}"
echo -e "${NC}"
exit
fi
cd
echo -e "${NC}"
pm2 stop watchdog > /dev/null 2>&1 && sleep 2
echo -e "${ARROW} ${CYAN}Stopping Flux daemon service${NC}"
sudo systemctl stop $COIN_NAME > /dev/null 2>&1 && sleep 2
sudo fuser -k 16125/tcp > /dev/null 2>&1 && sleep 1
if [[ -e /home/$USER/$CONFIG_DIR/blocks ]] && [[ -e /home/$USER/$CONFIG_DIR/chainstate ]]; then
echo -e "${ARROW} ${CYAN}Cleaning...${NC}"
rm -rf /home/$USER/$CONFIG_DIR/blocks /home/$USER/$CONFIG_DIR/chainstate /home/$USER/$CONFIG_DIR/determ_zelnodes
fi
BOOTSTRAP_ZIPFILE="${BOOTSTRAP_ZIP##*/}"
if [ -f "/home/$USER/$BOOTSTRAP_ZIPFILE" ]; then
echo -e "${ARROW} ${YELLOW}Local bootstrap file detected...${NC}"
if [[ "$BOOTSTRAP_ZIPFILE" == *".zip"* ]]; then
echo -e "${ARROW} ${YELLOW}Checking if zip file is corrupted...${NC}"
if unzip -t $BOOTSTRAP_ZIPFILE | grep 'No errors' > /dev/null 2>&1
then
echo -e "${ARROW} ${CYAN}Bootstrap zip file is valid.............[${CHECK_MARK}${CYAN}]${NC}"
else
printf '\e[A\e[K'
printf '\e[A\e[K'
printf '\e[A\e[K'
printf '\e[A\e[K'
printf '\e[A\e[K'
printf '\e[A\e[K'
echo -e "${ARROW} ${CYAN}Bootstrap file is corrupted.............[${X_MARK}${CYAN}]${NC}"
rm -rf $BOOTSTRAP_ZIPFILE
fi
else
check_tar "/home/$USER/$BOOTSTRAP_ZIPFILE"
fi
fi
if [ -f "/home/$USER/$BOOTSTRAP_ZIPFILE" ]; then
if [[ "$BOOTSTRAP_ZIPFILE" == *".zip"* ]]; then
echo -e "${ARROW} ${YELLOW}Unpacking wallet bootstrap please be patient...${NC}"
unzip -o $BOOTSTRAP_ZIPFILE -d /home/$USER/$CONFIG_DIR > /dev/null 2>&1
else
tar_file_unpack "/home/$USER/$BOOTSTRAP_ZIPFILE" "/home/$USER/$CONFIG_DIR"
sleep 2
fi
else
CHOICE=$(
whiptail --title "FLUXNODE INSTALLATION" --menu "Choose a method how to get bootstrap file" 10 47 2 \
"1)" "Download from source build in script" \
"2)" "Download from own source" 3>&2 2>&1 1>&3
)
case $CHOICE in
"1)")
DB_HIGHT=$(curl -s -m 3 https://fluxnodeservice.com/daemon_bootstrap.json | jq -r '.block_height')
echo -e "${ARROW} ${CYAN}Flux daemon bootstrap height: ${GREEN}$DB_HIGHT${NC}"
echo -e "${ARROW} ${YELLOW}Downloading File: ${GREEN}$BOOTSTRAP_ZIP ${NC}"
wget -O $BOOTSTRAP_ZIPFILE $BOOTSTRAP_ZIP -q --show-progress
tar_file_unpack "/home/$USER/$BOOTSTRAP_ZIPFILE" "/home/$USER/$CONFIG_DIR"
sleep 2
;;
"2)")
BOOTSTRAP_ZIP="$(whiptail --title "Flux daemon bootstrap setup" --inputbox "Enter your URL (zip, tar.gz)" 8 72 3>&1 1>&2 2>&3)"
echo -e "${ARROW} ${YELLOW}Downloading File: ${GREEN}$BOOTSTRAP_ZIP ${NC}"
BOOTSTRAP_ZIPFILE="${BOOTSTRAP_ZIP##*/}"
if [[ "$BOOTSTRAP_ZIPFILE" != *".zip"* ]]; then
BOOTSTRAP_ZIPFILE='daemon_bootstrap.tar.gz'
fi
wget -O $BOOTSTRAP_ZIPFILE $BOOTSTRAP_ZIP -q --show-progress
if [[ "$BOOTSTRAP_ZIPFILE" == *".zip"* ]]; then
echo -e "${ARROW} ${YELLOW}Unpacking wallet bootstrap please be patient...${NC}"
unzip -o $BOOTSTRAP_ZIPFILE -d /home/$USER/$CONFIG_DIR > /dev/null 2>&1
else
tar_file_unpack "/home/$USER/$BOOTSTRAP_ZIPFILE" "/home/$USER/$CONFIG_DIR"
sleep 2
fi
;;
esac
fi
if whiptail --yesno "Would you like remove bootstrap archive file?" 8 60; then
rm -rf $BOOTSTRAP_ZIPFILE
fi
sudo systemctl start $COIN_NAME > /dev/null 2>&1 && sleep 2
NUM='35'
MSG1='Starting Flux daemon service...'
MSG2="${CYAN}........................[${CHECK_MARK}${CYAN}]${NC}"
spinning_timer
echo -e "" && echo -e ""
pm2 start watchdog --watch > /dev/null 2>&1 && sleep 2
}
function install_node(){
echo -e "${GREEN}Module: Install FluxNode${NC}"
echo -e "${YELLOW}================================================================${NC}"
if [[ "$USER" == "root" || "$USER" == "ubuntu" || "$USER" == "admin" ]]; then
echo -e "${CYAN}You are currently logged in as ${GREEN}$USER${NC}"
echo -e "${CYAN}Please switch to the user account.${NC}"
echo -e "${YELLOW}================================================================${NC}"
echo -e "${NC}"
exit
fi
if [[ $(lsb_release -d) != *Debian* && $(lsb_release -d) != *Ubuntu* ]]; then
echo -e "${WORNING} ${CYAN}ERROR: ${RED}OS version $(lsb_release -si) not supported${NC}"
echo -e "${CYNA}Ubuntu 20.04 LTS is the recommended OS version .. please re-image and retry installation"
echo -e "${WORNING} ${CYAN}Installation stopped...${NC}"
echo
exit
fi
if docker run hello-world > /dev/null 2>&1
then
echo -e ""
else
echo -e "${WORNING}${CYAN}Docker is not working correct or is not installed.${NC}"
exit
fi
# bash -i <(curl -s https://raw.githubusercontent.com/RunOnFlux/fluxnode-multitool/${ROOT_BRANCH}/install_pro.sh)
bash -i <(curl -s https://raw.githubusercontent.com/RunOnFlux/fluxnode-multitool/${ROOT_BRANCH}/install_pro_testnet.sh)
}
function install_docker(){
echo -e "${GREEN}Module: Install Docker${NC}"
echo -e "${YELLOW}================================================================${NC}"
if [[ "$USER" != "root" ]]; then
echo -e "${CYAN}You are currently logged in as ${GREEN}$USER${NC}"
echo -e "${CYAN}Please switch to the root account use command 'su -'.${NC}"
echo -e "${YELLOW}================================================================${NC}"
echo -e "${NC}"
exit
fi
if [[ $(lsb_release -d) != *Debian* && $(lsb_release -d) != *Ubuntu* ]]; then
echo -e "${WORNING} ${CYAN}ERROR: ${RED}OS version $(lsb_release -si) not supported${NC}"
echo -e "${CYNA}Ubuntu 20.04 LTS is the recommended OS version .. please re-image and retry installation"
echo -e "${WORNING} ${CYAN}Installation stopped...${NC}"
echo
exit
fi
if [[ -z "$usernew" ]]; then
usernew="$(whiptail --title "MULTITOOLBOX $dversion" --inputbox "Enter your username" 8 72 3>&1 1>&2 2>&3)"
usernew=$(awk '{print tolower($0)}' <<< "$usernew")
else
echo -e "${PIN}${CYAN} Import docker user '$usernew' from environment variable............[${CHECK_MARK}${CYAN}]${NC}"
fi
echo -e "${ARROW} ${CYAN}New User: ${GREEN}${usernew}${NC}"
adduser --gecos "" "$usernew"
usermod -aG sudo "$usernew" > /dev/null 2>&1
echo -e "${ARROW} ${YELLOW}Update and upgrade system...${NC}"
apt update -y && apt upgrade -y
if ! ufw version > /dev/null 2>&1
then
echo -e "${ARROW} ${YELLOW}Installing ufw firewall..${NC}"
sudo apt-get install -y ufw > /dev/null 2>&1
fi
echo -e "${ARROW} ${YELLOW}Installing docker...${NC}"
echo -e "${ARROW} ${CYAN}Architecture: ${GREEN}$(dpkg --print-architecture)${NC}"
if [[ -f /usr/share/keyrings/docker-archive-keyring.gpg ]]; then
sudo rm /usr/share/keyrings/docker-archive-keyring.gpg > /dev/null 2>&1
fi
if [[ -f /etc/apt/sources.list.d/docker.list ]]; then
sudo rm /etc/apt/sources.list.d/docker.list > /dev/null 2>&1
fi
if [[ $(lsb_release -d) = *Debian* ]]
then
sudo apt-get remove docker docker-engine docker.io containerd runc -y > /dev/null 2>&1
sudo apt-get update -y > /dev/null 2>&1
sudo apt-get -y install apt-transport-https ca-certificates > /dev/null 2>&1
sudo apt-get -y install curl gnupg-agent software-properties-common > /dev/null 2>&1
#curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - > /dev/null 2>&1
#sudo add-apt-repository -y "deb [arch=amd64,arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /dev/null 2>&1
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg > /dev/null 2>&1
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 2>&1
sudo apt-get update -y > /dev/null 2>&1