-
Notifications
You must be signed in to change notification settings - Fork 13
/
sccmultitool.sh
2699 lines (2135 loc) · 70.1 KB
/
sccmultitool.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
#Coin info
version="3.4.7.1"
coinname=stakecubecoin
coinnamed=sccd
coinnamecli=scc-cli
ticker=SCC
coindir=scc
sleeptimerinsec=120
binaries="https://github.com/stakecube/StakeCubeCoin/releases/download/v3.4.7.1/scc-3.4.7.1-linux-nodes.zip"
prereleasebinaries="https://github.com/stakecube/StakeCubeCoin/releases/download/v3.4.7.1/scc-3.4.7.1-linux-nodes.zip"
snapshot='https://stakecubecoin.net/bootstrap.zip'
port=40000
rpcport=39999
discord='https://discord.gg/xxjZzJE'
#setup variables for passwords
pass=`pwgen 14 1 b`
rpcuser=`pwgen 14 1 b`
rpcpass=`pwgen 36 1 b`
#color variables
readonly GRAY='\e[1;30m'
readonly DARKRED='\e[0;31m'
readonly RED='\e[1;31m'
readonly DARKGREEN='\e[0;32m'
readonly GREEN='\e[1;32m'
readonly DARKYELLOW='\e[0;33m'
readonly YELLOW='\e[1;33m'
readonly DARKBLUE='\e[0;34m'
readonly BLUE='\e[1;34m'
readonly DARKMAGENTA='\e[0;35m'
readonly MAGENTA='\e[1;35m'
readonly DARKCYAN='\e[0;36m'
readonly CYAN='\e[1;36m'
readonly UNDERLINE='\e[1;4m'
readonly NC='\e[0m'
readonly ERASEBACK='\e[1K'
readonly BEGINLINE='\e[0G'
#############################
### Functions and Methods ###
#############################
# Console message functions
function msg {
echo -e "${1}${NC}"
}
function msgc {
echo -e "${2}${1}${NC}"
}
# Gets the platform we are running on.
function getPlt {
if [ "$(uname)" == "Darwin" ]; then
echo 1
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo 0
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
echo 1
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
echo 1
elif [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ]; then
echo 1
else
echo 1
fi
}
if [ `getPlt` == 0 ]; then
msgc "Running on Linux.." $YELLOW
else
msgc "Not running on Linux..." $RED
exit
fi
#############################
#############################
#pre-setup checks and dependencies installs
checkforrunningapt=$(ps -e | grep apt)
if [[ $checkforrunningapt == "" ]]
then
echo -e "Apt not currently running"
echo -e ""
else
echo -e "${RED}Error:${NC} Apt is already running, aborting script"
exit
fi
echo -e "Checking/installing/updating other script dependency's"
apt -y -qq install curl zip unzip nano ufw software-properties-common pwgen p7zip-full p7zip-rar
clear
sccmultitool_update=$(curl -s https://raw.githubusercontent.com/stakecube/SCC-Multitool/master/sccmultitool.sh)
if [[ $(cmp <(echo "$sccmultitool_update") ~/sccmultitool.sh) ]] && [[ $(diff <(echo "$sccmultitool_update") ~/sccmultitool.sh) ]]
then
updatesccmultitool=$([[ -f ~/sccmultitool.sh ]] && echo "1" || echo "0")
else
updatesccmultitool=0
fi
function displayname() {
cat << "EOF"
_____ _ _ _____ _
/ ____| | | | / ____| | |
| (___ | |_ __ _| | _____| | _ _| |__ ___
\___ \| __/ _` | |/ / _ \ | | | | | '_ \ / _ \
____) | || (_| | < __/ |___| |_| | |_) | __/
|_____/ \__\__,_|_|\_\___|\_____\__,_|_.__/ \___|
EOF
}
displayname
#Tool menu
echo -e ""
echo -e "${UNDERLINE}${CYAN}Welcome to the StakeCube Multitools ${version}${NC}"
#echo -e '\e[4mWelcome to the StakeCube Multitools '${version}' \e[24m'
echo -e "${YELLOW}Please enter a number from the list and press [ENTER] to start tool"
echo -e "${YELLOW}1 - Newserver 8GB swap + IPv6 setup. REQUIRES RESTART ${MAGENTA}Contabo VPS only${NC}"
echo -e "${YELLOW}2 - Setup/Resize/Delete swap space with X MB swap space"
echo -e "${YELLOW}3 - Wallet update (all ${ticker} nodes)"
echo -e "${YELLOW}4 - Masternode stop/start/restart (stop/start/restart all ${ticker} nodes)"
echo -e "${YELLOW}5 - Remove MasterNode"
echo -e "${YELLOW}6 - Remove Multiple Masternodes"
echo -e "${YELLOW}7 - Masternode install"
echo -e "${YELLOW}8 - Masternode install with optional sleep delay function"
echo -e "${YELLOW}9 - Install New Node with manually specified IPv4/IPv6 Address"
echo -e "${YELLOW}10 - Download/Update StakeCubeCoin local bootstrap file from stakecube"
echo -e "${YELLOW}11 - Make/Update your StakeCubeCoin local bootstrap file from an existing SCC node"
echo -e "${YELLOW}12 - Chain/PoSe maintenance tool (single ${ticker} node)"
echo -e "${YELLOW}13 - Check block count status against explorer (all ${ticker} nodes)"
echo -e "${YELLOW}14 - Check MN health status and optional repair (all ${ticker} nodes)"
echo -e "${YELLOW}15 - Check block count and optional chain repair (all ${ticker} nodes)"
echo -e "${YELLOW}16 - Output some system diagnostic info"
echo -e ""
echo -e "${CYAN}97 - Pre-Release Menu${NC}"
echo -e "${YELLOW}98 - Maintenance Sub-Menu - extra functions"
echo -e "${YELLOW}99 - Check for updated script from GitHub${NC}"
echo -e ""
echo -e "${YELLOW}0 - Exit"
echo -e ""
echo -e "${MAGENTA}This script can now use an optional sleep delay of up to 5 minutes per node on startup${NC}"
echo -e "${MAGENTA}This helps to prevent the VPS from being overloaded upon reboot when there are many nodes installed${NC}"
echo -e "${MAGENTA}This can make the install/start/restart/repair node(s) look like it has stopped working${NC}"
echo -e "${MAGENTA}This is just a side effect of the delay only(if it occurs)${NC}"
echo -e ""
echo -e "${YELLOW}This is an ${RED}OPTIONAL${YELLOW} feature that you can use by selecting appropriate options${NC}"
echo -e "${YELLOW}Please run the check install/update service files before installing nodes${NC}"
echo -e "${RED}only IF${YELLOW} you want to use the sleep delay functionality, it only needs to be ran once${NC}"
echo -e "${NC}"
if [[ $updatesccmultitool == "1" ]]
then
echo -e "${CYAN}New version of ${GREEN}SCCMultitool${NC}${CYAN} available${NC}"
echo -e ""
fi
read -p "> " start
echo -e ""
function displaypause() {
local delaycount=$1
echo -e "${YELLOW}Press any key to abort countdown and continue${NC}"
while [ $delaycount -ge 0 ]
do
echo -en "${GREEN}Countdown ${NC}$delaycount"
sleep 1
echo -en "${ERASEBACK}${NC}${BEGINLINE}${NC}"
read -n 1 -t 0.05 $anykey
anykeystatus=$?
if [[ $anykeystatus -le 127 ]]
then
echo -en "${ERASEBACK}${NC}${BEGINLINE}${NC}"
return
fi
delaycount=$(($delaycount - 1))
done
echo -e ""
return
}
function checkprocess() {
local processname=$1
processidentoutput=$(ps -U $processname -jh)
processident=$(echo $processidentoutput | grep -c $processname -)
processidentstatus=$?
checkprocessname=$(echo $processidentoutput | grep -c sleep -)
checkprocessstatus=$?
if [[ $checkprocessstatus == 0 ]]
then
echo -e ""
echo -e "${YELLOW}Process is in sleep mode waiting to start still${NC}"
sleepcounter="$(echo $processidentoutput | grep 'sleep[ 0-9]' | awk '{print $NF}')"
echo -e "${YELLOW}$sleepcounter"
sleepcounter=$(( $sleepcounter + 15 ))
echo -e "$sleepcounter"
displaypause $sleepcounter
fi
# echo -e ""
# echo -e "$processidentoutput"
# echo -e "$processident"
# echo -e "$processidentstatus"
if [[ $processident == 0 ]]
then
return 1
else
return 0
fi
#always return false if it gets this far
return 1
}
function debugmodeonoffsub() {
local alias=$1
local onoff=$2
local debugcmd=$3
local debugcount=$4
local grepcheckstatus=$5
if [[ $grepcheckstatus == 1 && $debugcount == 0 && $onoff == 1 ]]
then
echo -e ""
echo -e "${YELLOW}Debug line not found, inserting turned on${NC}"
echo 'debug=1' >> /home/$alias/.scc/stakecubecoin.conf
echo -e ""
echo -e "${YELLOW}Restarting node and pausing $sleeptimerinsec seconds${NC}"
systemctl restart $alias --no-block
displaypause $sleeptimerinsec
return
else
if [[ $grepcheckstatus == 1 && $debugcount == 0 && $onoff == 0 ]]
then
echo -e ""
echo -e "${YELLOW}Debug line not found, inserting turned off${NC}"
echo 'debug=0' >> /home/$alias/.scc/stakecubecoin.conf
echo -e ""
echo -e "${YELLOW}Restarting node and pausing $sleeptimerinsec seconds${NC}"
systemctl restart $alias --no-block
displaypause $sleeptimerinsec
return
fi
fi
if [[ ${debugcmd,,} == "debug=0" && $onoff == "0" ]]
then
echo -e ""
echo -e "${YELLOW}Debugging already disabled on node ${CYAN}$i${NC}"
return
fi
if [[ ${debugcmd,,} == "debug=1" && $onoff == "1" ]]
then
echo -e ""
echo -e "${YELLOW}Debugging already enabled on node ${CYAN}$i${NC}"
return
fi
if [[ ${debugcmd,,} == "debug=0" && $onoff == "1" ]]
then
echo -e ""
echo -e "${YELLOW}Enabling debugging on node ${CYAN}$i${NC}"
sed -i 's/debug=0/debug=1/gi' /home/$alias/.scc/stakecubecoin.conf
echo -e ""
echo -e "${YELLOW}Restarting node and pausing $sleeptimerinsec seconds${NC}"
systemctl restart $alias --no-block
displaypause $sleeptimerinsec
return
fi
if [[ ${debugcmd,,} == "debug=1" && $onoff == "0" ]]
then
echo -e ""
echo -e "${YELLOW}Disabling debugging on node ${CYAN}$i${NC}"
sed -i 's/debug=1/debug=0/gi' /home/$alias/.scc/stakecubecoin.conf
echo -e ""
echo -e "${YELLOW}Restarting node and pausing $sleeptimerinsec seconds${NC}"
systemctl restart $alias --no-block
displaypause $sleeptimerinsec
return
fi
return
}
function checkifstart() {
local alias=$1
local yesnostart=""
echo -e ""
echo -e "${YELLOW}Do you wish to try and start ${CYAN}$alias${YELLOW}?${NC}"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read yesnostart
checkyesno $yesnostart
if [[ $yesnostart == "yes" ]]
then
echo -e ""
echo -e "${YELLOW}This will only attempt a start and will not verify it started${NC}"
systemctl start $alias --no-block
echo -e "${CYAN}Sent start command${NC}"
else
echo -e ""
echo -e "${YELLOW}Not starting${NC}"
fi
return
}
function debugmodeonoff() {
local alias=$1
local onoff=$2
local errorpid=0
foundone=0
echo -e ""
echo -e "${YELLOW}Checking for $ticker MN's${NC}"
echo -e ""
if [[ $alias != 0 ]]
then
if ! checkprocess $alias
then
errorpid=1
echo -e ""
echo -e "${RED}ERROR ${YELLOW}process for ${CYAN}$alias${YELLOW} not found${NC}"
return
fi
debugcount=$(grep -cFi 'debug' /home/$alias/.scc/stakecubecoin.conf)
debugcmd=$(grep -ix 'debug=[0-1]' /home/$alias/.scc/stakecubecoin.conf)
grepcheckstatus=$?
echo -e "found ${CYAN}$alias${NC}..."
debugmodeonoffsub $alias $onoff $debugcmd $debugcount $grepcheckstatus
return
fi
for i in $(ls /home/); do
echo -e ""
if [[ $i == *scc* ]]
then
foundone=1
errorpid=0
grepcheckstatus=""
echo -e "found ${CYAN}$i${NC}..."
debugcount=$(grep -cFi 'debug' /home/$i/.scc/stakecubecoin.conf)
debugcmd=$(grep -ix 'debug=[0-1]' /home/$i/.scc/stakecubecoin.conf)
grepcheckstatus=$?
# echo -e ""
# echo -e "$countdebug"
# echo -e "$debugcmd"
# echo -e "$grepcheckstatus"
if ! checkprocess $i
then
errorpid=1
echo -e ""
echo -e "${RED}ERROR ${YELLOW}process for ${CYAN}$i${YELLOW} not found${NC}"
fi
if [[ $errorpid == 0 ]]
then
if [[ $debugcmd == "" ]]
then
debugcmd=1
debugcount=0
fi
debugmodeonoffsub $i $onoff $debugcmd $debugcount $grepcheckstatus
fi
fi
if [[ $foundone == 0 ]]
then
echo -e ""
echo -e "${CYAN}No $ticker nodes found${NC}"
fi
done
}
function is_number() {
# Author: neo3587
# Source: https://github.com/neo3587/dupmn
# <$1 = number>
[[ "$1" =~ ^[0-9]+$ ]] && echo "1"
}
function pad() {
[ "$#" -gt 1 ] && [ -n "$2" ] && printf "%$2.${2#-}s" "$1";
}
function checkyesno() {
local yesno=$1
if [[ $yesno == "yes" ]] || [[ $yesno == "no" ]]
then
return
else
echo -e "${YELLOW}Please enter only${MAGENTA} yes${YELLOW} or${MAGENTA} no${NC}"
echo -e ""
echo -e "${RED}Aborting script${NC}"
echo -e ""
exit
fi
}
function checknetcfgfile() {
local netdone=0
netcfg=/etc/netplan/01-netcfg.yaml
if [[ $netdone == 0 ]]
then
if [[ -f $netcfg ]]
then
netdone=1
else
netcfg=/etc/netplan/00-installer-config.yaml
netdone=0
fi
fi
#echo -e "$netdone"
#echo -e "$netcfg"
if [[ $netdone == 0 ]]
then
if [[ -f $netcfg ]]
then
netdone=1
else
netcfg=/etc/netplan/50-cloud-init.yaml
netdone=0
fi
fi
#echo -e "$netdone"
#echo -e "$netcfg"
if [[ $netdone == 0 ]]
then
if [[ -f $netcfg ]]
then
netdone=1
else
netdone=0
fi
fi
#echo -e "$netdone"
#echo -e "$netcfg"
if [[ $netdone == 0 ]]
then
msg ""
msgc "Error - network config file not found (01-netcfg.yaml or 00-installer-config.yaml or 50-cloud-init.yaml)" $red
msg ""
exit
fi
}
function checkaliasvalidity() {
local aliasname=$1
if [[ ! -f /home/$aliasname/.${coindir}/${coinname}.conf ]]
then
echo -e ""
echo -e "${RED}Error node not found${NC}"
echo -e ""
exit
fi
}
function sleeprandomfilecheck() {
local sleepnumberfile=/usr/local/bin/sleeprandom
if test -e "$sleepnumberfile"
then
echo -e "${CYAN}Sleep/delay file exists, not creating${NC}"
echo -e ""
else
echo -e "${CYAN}Installing sleep/delay file${NC}"
cd /usr/local/bin
echo -e "#!/bin/bash" > $sleepnumberfile
echo -e "MINWAIT=10" >> $sleepnumberfile
echo -e "MAXWAIT=310" >> $sleepnumberfile
echo -e 'sleep $((MINWAIT+RANDOM%(MAXWAIT-MINWAIT)))' >> $sleepnumberfile
chmod +x $sleepnumberfile
fi
}
function chain_repair() {
local alias=$1
local bootstrapchoice=$2
local chaindownload=0
local nodeblock=0
if [[ $alias == "" ]]
then
echo -e ""
echo -e "Checking home directory for masternode alias's"
echo -e ""
ls /home
echo -e ""
echo -e "${YELLOW}Above are the alias names for the installed masternodes${NC}"
echo -e "${CYAN}Please enter the masternode alias name to repair${NC}"
echo -e ""
read alias
checkaliasvalidity $alias
fi
echo -e ""
echo -e "${YELLOW}Checking ${CYAN}$alias${YELLOW} block count against explorer"
echo -e ""
currentblock=$(curl -s https://www.coinexplorer.net/api/v1/SCC/getblockcount)
nodeblock=$($alias getblockcount)
nodestatus=$?
if [[ $nodestatus == 0 ]]
then
if [[ $currentblock == $nodeblock ]]
then
echo -e "${CYAN}$i ${NC}sccnode: $nodeblock explorer: $currentblock ${CYAN}Same as explorer${NC}"
echo -e ""
echo -e "${MAGENTA}Chain Repair is not needed for this node"
echo -e ""
echo -e "${YELLOW}Do you wish to still do the chain repair?"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read forcechainrepair
checkyesno $forcechainrepair
if [[ $forcechainrepair == "no" ]]
then
return
fi
else
echo -e "${CYAN}$i ${NC}sccnode: $nodeblock explorer: $currentblock ${RED}Different block count from explorer${NC}"
echo -e ""
echo -e "${CYAN}Continuing with repair of node${NC}"
echo -e ""
fi
else
echo -e "${RED}Something is wrong with ${CYAN}$alias${NC}"
echo -e "${YELLOW}Continuing repair${NC}"
echo -e ""
if [[ $updateallnodes == "no" ]]
then
echo -e "${YELLOW}Do you wish to still chain repair?"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read checkchainrepair2
checkyesno $checkchainrepair2
else
checkchainrepair2="yes"
fi
if [[ $checkchainrepair2 == "no" ]]
then
exit
fi
fi
echo -e ""
echo -e "Stopping ${MAGENTA}$alias${NC}"
aliasvalid=$(systemctl stop $alias)
aliasvalidstatus=$?
if [[ $aliasvalidstatus != 0 ]]
then
echo -e ""
echo -e "${RED}Error: ${CYAN}$alias ${MAGENTA} does not exist or has other errors${NC}"
echo -e ""
exit
fi
displaypause 10
if [[ $bootstrapchoice != "yes" ]]
then
echo -e ""
echo -e "${YELLOW}Use offline bootstrap?${NC}"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read bootstrapchoice
checkyesno $bootstrapchoice
else
echo -e "${YELLOW}Using offline bootstrap file${NC}"
fi
echo -e ""
cd /home/$alias
find /home/$alias/.${coindir}/ -name ".lock" -delete
find /home/$alias/.${coindir}/ -name ".walletlock" -delete
find /home/$alias/.${coindir}/* ! -name "wallet.dat" ! -name "*.conf" -delete
echo -e "${YELLOW}Downloading and/or Unzipping and replacing chain files for ${MAGENTA}$alias${NC}"
if [[ $bootstrapchoice == yes ]]
then
sccfile=~/${coinname}.zip
if test -e "$sccfile"
then
7za x ~/${coinname}.zip
echo -e "${YELLOW}$coinname local chain directory updated${NC}"
else
echo -e ""
echo -e "${RED}File doesn't exist${NC}, ${YELLOW}downloading chain${NC}"
wget -nv --show-progress ${snapshot} -O ~/${coinname}.zip
7za x ~/${coinname}.zip
echo -e ""
echo -e "${YELLOW}$coinname chain directory updated${NC}"
fi
else
echo -e ""
echo -e "${YELLOW}Do you wish to download from the web (${CYAN}yes${YELLOW}) or full chain downlaod (${CYAN}no${YELLOW})${NC}"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read chaindownload
checkyesno $chaindownload
fi
if [[ $chaindownload == yes ]]
then
echo -e ""
echo -e "${YELLOW}Downloading bootstrap for offline use as well${NC}"
echo -e ""
wget -nv --show-progress ${snapshot} -O ~/${coinname}.zip
7za x ~/${coinname}.zip
echo -e ""
echo -e "${YELLOW}$coinname chain directory updated${NC}"
fi
chown -R $alias:$alias /home/${alias}
echo -e ""
echo -e "${CYAN}Starting $alias after repair${NC}"
echo -e ""
systemctl start --no-block ${alias}.service
displaypause 10
echo -e ""
echo -e "${YELLOW}Please wait for a moment.. and use ${CYAN}$alias masternode status${YELLOW} to check if $alais is ready for POSE unban or still showing READY${NC}"
echo -e "${YELLOW}If $alias showing POSE banned you will need to run the protx update command to unban${NC}"
echo -e "${YELLOW}Below is an example of the protx update command to use in your main wallets debug console${NC}"
echo -e "${YELLOW}protx update_service proTxHash ipAndPort operatorKey (operatorPayoutAddress feeSourceAddress)${NC}"
echo -e ""
echo -e "${YELLOW}Example: protx update_service proTxHash (127.0.0.1:40000 or [2001:2000:2000:2000:0000:0000:0000:0052]:40000) (blsprivatekey) '""' (feeSourceAddress)${NC}"
echo -e "${CYAN}Chain repair tool finished${NC}"
}
function install_mn() {
local bypassipv6setup=$1
local bypassipv6addr=$2
local sleepdelay=$3
if [[ $bypassipv6setup == yes ]]
then
# test=$bypassipv6addr
echo -e "${MAGENTA}Setting config file for IPV6 address $bypassipv6addr${NC}"
echo -e ""
ipchoice=yes
# else
# test=0
fi
#get user input alias and bind set varible#
echo -e ""
echo -e "${YELLOW}Checking home directory for masternode alias's${NC}"
echo -e ""
ls /home
echo -e ""
echo -e "${YELLOW}Above are the alias names for the installed masternodes${NC}"
echo -e "${YELLOW}Please enter MN alias. Example: ${CYAN}sccmn001${NC}"
echo -e "${YELLOW}To use other tools you must include ${CYAN}$ticker${YELLOW} in the alias${NC}"
read alias
if [[ -f /home/$alias/.${coindir}/${coinname}.conf ]]
then
echo -e ""
echo -e "${RED}Error duplicate node name${NC}"
echo -e ""
exit
fi
echo -e ""
echo -e "${YELLOW}${UNDERLINE}Enter the BLS secret key${NC}"
read key
echo -e ""
echo -e "${YELLOW}${UNDERLINE}Please enter a unique RPC port number. Default is ${CYAN}$rpcport${NC}"
echo -e "${YELLOW}Examples: for ${CYAN}sccmn001 ${YELLOW}use ${CYAN}40010 ${YELLOW}and so on${NC}"
echo -e "${YELLOW}So it's 4(node number)0 (40010 for sccmn001)${NC}"
read rpcport
if [[ $bypassipv6setup == no ]]
then
#IPv4/v6 choice and setup
echo -e ""
echo -e "${YELLOW}Would you like to setup with an IPv6 address?{$NC}"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read ipchoice
checkyesno $ipchoice
# echo -e "Passed yes/no check"
#script network config dependency
echo -e ""
echo -e "Checking/installing dependency for auto IP setup"
if [[ $ipchoice == yes ]]
then
#set default IPv6
checknetcfgfile
sed -i '1{/^$/d}' $netcfg
netconfcount=$(grep -c "/64" $netcfg)
linenumber1=$((grep -n "/64" $netcfg) | cut -d\: -f1 | head -n 1)
linenumber2=$(( $linenumber1+$netconfcount ))
# echo -e "$linenumber1"
# echo -e "$linenumber2"
dipv6=$(sed -n "$linenumber1"p $netcfg)
spaces=$(echo -e "$dipv6" | tr -cd ' \t' | wc -c)
spaces=$(( $spaces-2 ))
ipv6test="$(echo $dipv6 | grep -E '.{0,4}\/64')"
ipv6test2="$(echo $ipv6test | awk 'match($0,"/64"){print substr($0,RSTART-4,4)}')"
ipv6test2="$(echo $ipv6test2 | cut -d\: -f3)"
ipv6test2="$(echo $ipv6test2 | tr -d ':')"
ipv6test3=$(( $ipv6test2 + $netconfcount + 50 ))
# echo -e "ipv6test $ipv6test"
# echo -e "ipv6test2 $ipv6test2"
# echo -e "ipv6test3 $ipv6test3"
# echo -e " 2 $dipv6"
# echo -e " 3 $spaces"
# echo -e "$netconfcount"
cipv6=$(( $ipv6test3 ))
# echo -e "$cipv6"
ipv6="$(echo $dipv6 | sed "s/\:$ipv6test2/\:$cipv6/g")"
echo -e ""
echo -e "New IPv6 is $ipv6"
finalconfigipv6="$(echo -e "$(pad " " $spaces) ${ipv6}")"
# echo -e "$finalconfigipv6"
# sed -i "${linenumber2}i\\${finalconfigipv6}" $netcfg
# sed -i '1{/^$/d}' $netcfg
# netconfcount=$(grep -c :0000:0000 $netcfg)
# linenumber1=$((grep -n ":0000:0000" $netcfg) | cut -d\: -f1 | head -n 1)
# echo -e "$linenumber1"
# dipv6=$(sed -n "$linenumber1"p $netcfg)
# echo -e " 2 $dipv6"
# echo -e "$netconfcount"
# cipv6=$(( $netconfcount+51 ))
# echo -e "$cipv6"
# ipv6="$(echo $dipv6 | sed "s/:0001/:$cipv6/g")"
# echo -e "New IPv6 is $ipv6"
# #Add IPv6 address to netcfg file
# sed -i "/gateway6/i \ \ \ \ \ \ \ \ ${ipv6}" $netcfg
# netplan apply
#tidy IP input for conf
ipv6conf="$(echo $ipv6 | sed 's/.\{3\}$//')"
ipv6conf="$(echo $ipv6conf | sed "s/- //g")"
else
#check ip set IP/bind variable
echo -e "Finding IPv4 address"
ipadd=$(curl http://ifconfig.me/ip)
echo -e "Your IPv4 is $ipadd"
echo -e "Auto IPv4 set"
fi
else
ipadd=$bypassipv6addr
fi
echo -e ""
echo -e "${YELLOW}Use offline bootstrap?${NC}"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read bootstrapchoice
checkyesno $bootstrapchoice
if [[ $bootstrapchoice == no ]]
then
echo -e ""
echo -e "${YELLOW}Do you wish to download from the web (${CYAN}yes${YELLOW}) or full chain downlaod (${CYAN}no${YELLOW})${NC}"
echo -e "${CYAN}Please enter ${MAGENTA}yes${NC} ${CYAN}or${NC} ${MAGENTA}no${CYAN} only${NC}"
read chaindownload
checkyesno $chaindownload
else
chaindownload=0
fi
if [[ $ipchoice == yes ]]
then
echo -e ""
echo -e "${CYAN}Applying IP configuration${NC}"
sed -i "${linenumber2}i\\${finalconfigipv6}" $netcfg
netplan apply
fi
echo -e ""
ufw allow ssh
echo -e "${CYAN}Making sure your VPS is up to date before continuing install${NC}"
apt update -y
#setup user
echo -e ""
echo -e "${YELLOW}Setting up user ${CYAN}$alias${NC}"
adduser "$alias" <<EOF
echo ${pass}
echo ${pass}
/
/
/
/
/
/
/
EOF
echo -e ""
echo -e "${CYAN}User ${CYAN}$alias${CYAN} setup${NC}"
echo -e ""
#Sleep/Delay check and install
if [[ $sleepdelay == yes ]]
then
sleeprandomfilecheck
fi
#Node binaries check and install if needed
cd /usr/local/bin
binfile=/usr/local/bin/${coinnamecli}
if test -e "$binfile"
then
echo -e "${CYAN}Node binaries already downloaded and setup${NC}"
echo -e ""
else
echo -e "${YELLOW}Installing node binaries for ${MAGENTA}$alias${NC}"
cd /usr/local/bin
wget -nv --show-progress ${binaries} -O ${coinname}.zip
7za x ${coinname}.zip
chmod +x ${coinnamecli} ${coinnamed}
rm ${coinname}.zip
echo -e "${CYAN}$alias node binaries downloaded and installed${NC}"
echo -e ""
fi
#Node intergration - creation of alias in /usr/local/bin for executing commands to users daemon
echo -e "${YELLOW}Node Intergration${NC}"
echo -e "#!/bin/bash" >> $alias
echo -e "/usr/local/bin/$coinnamecli -conf=/home/$alias/.$coindir/$coinname.conf -datadir=/home/$alias/.$coindir \$@" >> $alias
chmod +x $alias
cd /etc/systemd/system
echo -e "${CYAN}Node Intergration done${NC}"
echo -e ""
#Setup system service
echo -e "${YELLOW}Setting up system service${NC}"
echo -e "[Unit]" >> $alias.service
echo -e "Description=$ticker service" >> $alias.service
echo -e "After=network.target" >> $alias.service
echo -e "" >> $alias.service
echo -e "[Service]" >> $alias.service
echo -e "User=$alias" >> $alias.service
echo -e "Group=root" >> $alias.service
echo -e "" >> $alias.service
echo -e "Type=forking" >> $alias.service
if [[ $sleepdelay == yes ]]
then
echo -e "ExecStartPre=/usr/local/bin/sleeprandom" >> $alias.service
fi
echo -e "ExecStart=/usr/local/bin/$coinnamed -daemon -conf=/home/$alias/.$coindir/$coinname.conf -datadir=/home/$alias/.$coindir">> $alias.service
echo -e "ExecStop=-/usr/local/bin/$coinnamecli -conf=/home/$alias/.$coindir/$coinname.conf -datadir=/home/$alias/.$coindir stop" >> $alias.service
echo -e "" >> $alias.service
echo -e "Restart=always" >> $alias.service
echo -e "PrivateTmp=true" >> $alias.service
echo -e "TimeoutStopSec=6000s" >> $alias.service
echo -e "TimeoutStartSec=3000s" >> $alias.service
echo -e "StartLimitInterval=120s" >> $alias.service
echo -e "StartLimitBurst=5" >> $alias.service
echo -e "" >> $alias.service
echo -e "[Install]" >> $alias.service
echo -e "WantedBy=multi-user.target" >> $alias.service
systemctl enable $alias
echo -e "${CYAN}System service setup and enabled${NC}"
#update/copy chain files or get snapshot# from web or fresh complete chain download
echo -e ""
cd /home/$alias
find /home/$alias/.${coindir}/* ! -name "wallet.dat" ! -name "*.conf" -delete
echo -e "${YELLOW}Downloading and/or Unzipping chain files for ${MAGENTA}$alias${NC}"
echo -e ""
mkdir /home/$alias/.${coindir}
chown $alias:$alias /home/$alias/.${coindir}
if [[ $bootstrapchoice == yes ]] && [[ $chaindownload == 0 ]]
then
sccfile=~/${coinname}.zip
if test -e "$sccfile"
then
7za x ~/${coinname}.zip
echo -e "${YELLOW}$coinname local bootstrap directory updated${NC}"
else
echo -e "${RED}File doesn't exist${NC}, ${YELLOW}downloading chain${NC}"
wget -nv --show-progress ${snapshot} -O ${coinname}.zip
7za x ${coinname}.zip
echo -e "${YELLOW}$coinname chain directory updated${NC}"
echo -e "${YELLOW}Removing downloaded temp file${NC}"
rm /home/${alias}/${coinname}.zip