-
Notifications
You must be signed in to change notification settings - Fork 0
/
beacon_masternode_manager.sh
2526 lines (2248 loc) · 101 KB
/
beacon_masternode_manager.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
#########################################################################################################
# MASTERNODE MANAGER #
#########################################################################################################
# Creator: Eddy Erkel #
# Discord: Eddy#6547 #
# Date : July, 2020 #
# Github : https://github.com/EddyErkel/ #
# #
# Disclamer: #
# This script is provided 'as is', without warranty of any kind. #
# Be aware that this script is run at your own risk and while this script #
# has been written with the intention of minimizing the potential for #
# unintended consequences, the owners, providers and contributors #
# can not be held responsible for any misuse or script problems. #
# The owners, providers and contributors assume no liability for any #
# financial loss, loss in revenue, loss of data, damages, direct or #
# consequential that may result from the use of this script and #
# the software that is downloaded and installed with it. #
# #
# By running this script you agree to understand and #
# accept the above terms and conditions. #
# #
# Thanks: #
# Special thanks to the creator(s) of dupmn. #
# This piece of brilliant software makes it very easy to create #
# and manage additional masternodes on the same system. #
# Please visit dupmn on github for more information about dupmn: #
# https://github.com/neo3587/dupmn #
# #
# To do someday maybe: #
# - remove option #
# - version check #
# - add IPv6 yes/no option #
# - remove private IP addresses from external-ip selection #
# #
#########################################################################################################
# MASTERNODE MANAGER #
#########################################################################################################
# Script version
VERSION=0.8b
# Donation addresses
# Grateful for this work, reusing this work, or in a generous mood?
# Feel free to send a donation to one of the below addresses.
# It will be much appreciated.
DONADDR1="BECN: bWVQh4kn8XK3ZjCwcm2g9MKgUCAaypYHgz"
DONADDR2="BTC : 18JNWyGhfAmhkWs7jzuuHn54jEZRPj81Jx"
DONADDR3="ETH : 0x067e8b995f7dbaf32081bc32927f6fac29b32055"
DONADDR4="LTC : LLqwyRiKiuvxkx76grFmbxEeoChLnxvaKH"
#########################################################################################################
# MASTERNODE SPECIFIC VARIABLES #
#########################################################################################################
# Masternode variables
NODE_NAME="Beacon"
COIN_NAME="beacon"
COIN_TICKER="BECN"
COIN_PATH="/usr/local/bin"
COIN_DAEMON="beacond"
COIN_CLI="beacon-cli"
COIN_PID="beacond.pid"
COIN_FOLDER="/root/.beacon"
COIN_CONFIG="beacon.conf"
COIN_SERVICE="beacon.service"
COIN_PORT="11115"
RPC_PORT="11116"
KEY_DUMMY="ReplaceThisDummyPrivateKeyByAManuallyGeneratedPrivateKey" # Dummy private key, will be assigned if a private key can not be generated.
OSVERSIONS=(16.04) # Preferred Ubuntu OS version(s) (separate by spaces, e.g. 16.04 18.04).
# Masternode commands
MNCLI_STATUS="getmasternodestatus" # Masternode status command, usually 'masternode status' or 'getmasternodestatus'.
MNCLI_KEYGEN="createmasternodekey" # Generate masternode key, usually 'masternode genkey' or 'createmasternodekey'.
MNCLI_BLOCK="getblockcount" # Get block height, usually 'getblockcount'.
MNCLI_INFO="getinfo" # Masternode info summary, usually 'getinfo'.
MNCLI_SYNC="mnsync status" # Masternode sync status, usually 'mnsync status'.
# Masternode binaries URL
COIN_URL16="https://github.com/beaconcrypto/beacon/releases/download/6054d89/beacon-3.4-6054d89-legacylin64.tgz" # Binaries compressed file for Ubuntu 16.
COIN_URL18="https://github.com/beaconcrypto/beacon/releases/download/6054d89/beacon-3.4-6054d89-lin64.tgz" # Binaries compressed file for Ubuntu 18.
COIN_ZIPDIR="beacon-6054d89-lin64/" # Path inside the zipfile that contains the binaries.
# Masternode Bootstrap URL
CHAIN_URL="http://167.86.85.70/becn-bootstrap.zip" # Bootstrap URL. The Bootstrap is compressed file containing chain directory's.
CHAIN_ZIP=$(echo $CHAIN_URL | awk -F'/' '{print $NF}') # Get bootstrap file name from URL. Will be lowercase <COIN_TICKER>_bootstrap.zip when not provided.
CHAIN_DATA="blocks chainstate peers.dat" # Folders and files used for creating bootstrap.zip (separate by spaces, usually blocks chainstate peers.dat).
# These folders and files will also be deleted when installing bootstrap.
# Masternode Addnodes URL
NODES_URL="https://github.com/beaconcrypto/beacon/releases/addnodes.txt" # Addnodes URL.
NODES_TXT=$(echo $NODES_URL | awk -F'/' '{print $NF}') # Get addnodes.txt file name from URL.
# Masternode related website URLs (shown at installation summary)
WWW_MAIN="https://www.beaconcrypto.io/" # Main website URL
WWW_GHUB="https://github.com/beaconcrypto/beacon/releases" # Github URL
WWW_EXPL="https://beacon.exp.monitorit4.me/" # Explorer URL
WWW_MNO="https://masternodes.online/currencies/BECN/" # Masternodes.Online URL
WWW_CMC="https://coinmarketcap.com/currencies/beacon/" # CoinMarketCap URL
# Dupmn variables
DUPMN_ENABLE="true" # Enable/Disable dupmn. Disable:false, enable:true.
DUPMN_NAME="dupmn"
DUPMN_EXEC="/usr/bin/dupmn"
DUPMN_CONFIG="/root/.dupmn/dupmn.conf"
DUPMN_MNCONF="/root/.dupmn/${COIN_NAME}.dmn"
DUPMN_URL="https://raw.githubusercontent.com/neo3587/dupmn/master/dupmn_install.sh" # Dupmn URL.
DUPMN_SH=$(echo $DUPMN_URL | awk -F'/' '{print $NF}') # Get dupmn install file name from URL.
# Dupmn related website URLs (shown at installation summary)
WWW_DUPMN="https://github.com/neo3587/dupmn"
WWW_DUPMN1="https://github.com/neo3587/dupmn/wiki"
WWW_DUPMN2="https://github.com/neo3587/dupmn/wiki/FAQs"
WWW_DUPMN3="https://github.com/neo3587/dupmn/wiki/Commands"
# Bash-completion commands
MNMGTCOMMANDS="help autocompletion install summary update addnodes bootstrap createbootstrap stop start status monitor showconf replace createswap optimize disclaimer donation dupmn"
MNCLICOMMANDS="help getblockchaininfo getblockcount getinfo createmasternodekey getmasternodecount getmasternodestatus getnetworkinfo getconnectioncount getpeerinfo 'masternode status' 'mnsync status'"
DUPMNCOMMANDS="help profadd profdel install uninstall bootstrap iplist systemctlall list checkmem swapfile update"
# Get file names from URLs
COIN_ZIP=$(echo $COIN_URL | awk -F'/' '{print $NF}')
CHAIN_ZIP=$(echo $CHAIN_URL | awk -F'/' '{print $NF}')
NODES_TXT=$(echo $NODES_URL | awk -F'/' '{print $NF}')
DUPMN_SH=$(echo $DUPMN_URL | awk -F'/' '{print $NF}')
#########################################################################################################
# MASTERNODE SPECIFIC FUNCTIONS #
#########################################################################################################
# Display FIGlet logo
# http://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=%0A
function display_logo() {
if [ ! -z $1 ]; then DELAY=$1; else DELAY=0.04; fi
echo -e "${W} "; sleep $DELAY
echo -e "${W} ██████╗ ███████╗ █████╗ ██████╗ ██████╗ ███╗ ██╗ "; sleep $DELAY
echo -e "${W} ██╔══██╗ ██╔════╝ ██╔══██╗ ██╔════╝ ██╔═══██╗ ████╗ ██║ "; sleep $DELAY
echo -e "${W} ██████╔╝ █████╗ ███████║ ██║ ██║ ██║ ██╔██╗ ██║ "; sleep $DELAY
echo -e "${W} ██╔══██╗ ██╔══╝ ██╔══██║ ██║ ██║ ██║ ██║╚██╗██║ "; sleep $DELAY
echo -e "${W} ██████╔╝ ███████╗ ██║ ██║ ╚██████╗ ╚██████╔╝ ██║ ╚████║ "; sleep $DELAY
echo -e "${W} ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ "; sleep $DELAY
echo -e "${W} "; sleep $DELAY
echo -e "${W} Building A Better World Through The Blockchain "; sleep $DELAY
echo -e "${W} "; sleep $DELAY
echo -e "${W} Beacon is an unique cryptocurrency project building "; sleep $DELAY
echo -e "${W} a conglomerate of transparent and legitimate platforms "; sleep $DELAY
echo -e "${W} in a trust-less industry "; sleep $DELAY
echo -e "${W} "; sleep $DELAY
echo -e "${D}───────────────────────────────────────────────────────────────────────────────"; sleep $DELAY
}
# Display disclaimer
function display_disclaimer() {
echo
echo
echo
echo -e "${G}DISCLAIMER${N}"
echo
echo -e "${D}This script is provided 'as is', without warranty of any kind.${N}"
echo -e "${D}Be aware that this script is run at your own risk and while this script${N}"
echo -e "${D}has been written with the intention of minimizing the potential for${N}"
echo -e "${D}unintended consequences, the owners, providers and contributors${N}"
echo -e "${D}can not be held responsible for any misuse or script problems.${N}"
echo -e "${D}The owners, providers and contributors assume no liability for any${N}"
echo -e "${D}financial loss, loss in revenue, loss of data, damages, direct or${N}"
echo -e "${D}consequential that may result from the use of this script and${N}"
echo -e "${D}the software that is downloaded and installed with it.${N}"
echo
if [[ $1 != "noselection" ]]; then
echo -e "${D}Do you understand and accept the above terms and conditions? [Y/n]${N}"
echo
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo -e "${Y}Thank you for accepting the above terms and conditions.${N}"
else
echo -e "${R}Sorry for not accepting the above terms and conditions.${N}"
echo
echo -e "${Y}As a result this script has been aborted.${N}"
echo
echo
exit 1
fi
fi
}
#########################################################################################################
# GENERIC VARIABLES #
#########################################################################################################
# Script variables
VALIDCMD="false" # Set value for valid command option check
DATE_TIME="`date +%Y-%m-%d\ %H:%M:%S`" # Set date and time variable
FILE_DATE="`date +%Y%m%d_%H%M%S`" # Set date and time variable for use with filename (no spaces)
SWAP_FILE="/swap.img" # Set swap file name and path
ARG1=$1 # First argument
ARG2=$2 # Second argument
ARG3=$3 # Third argument
ARG1=$(echo $ARG1 | sed -r 's/[-]//gi') # Remove '-' characters from first argument
ARG1=${ARG1,,} # Force lower case for first argument
if [ -f /bin/readlink ]; then
SCRIPT_FULL=$(readlink -nf $0) # Script real file name (not symbolic link) including full path
else
SCRIPT_NAME="$(basename "$0")" # Script file name
SCRIPT_DIR="$(cd $(dirname "$0") && pwd)" # Script location path
SCRIPT_FULL="$SCRIPT_DIR/$SCRIPT_NAME" # Script file name including full path (could be symbolic link)
SCRIPT_FULL="$(stat $SCRIPT_FULL | grep File | sed 's/.*> //' | sed -e "s/'//g" | sed 's/ *File: *//')" # Get real filename
fi
SCRIPT_DIR=$(dirname $SCRIPT_FULL) # Script location path
SCRIPT_NAME=$(basename $SCRIPT_FULL) # Script file name without path
SCRIPT_BASE="${SCRIPT_NAME%.*}" # Script file name without extension
SCRIPT_EXT="${SCRIPT_NAME##*.}" # Script file extension
CURRENT_DIR=$(pwd) # Set current directory variable
# Script colors config
R='\033[0;31m' # Red
G='\033[0;32m' # Green
Y='\033[0;33m' # Yellow
B='\033[0;34m' # Blue
P='\033[0;35m' # Purple
C='\033[0;36m' # Cyan
W='\033[0;97m' # White
D='\033[0;37m' # Grey (Default)
N='\033[0m' # No Color
#########################################################################################################
# GENERIC FUNCTIONS #
#########################################################################################################
# Display script version
function script_version() {
echo -e " v$VERSION ${N}"
}
# Clear screen
function clear_screen() {
#clear
tput reset # Clear screen while maintaining scrollback
}
# Display help
function display_help() {
if [[ ! "$1" == "noheader" ]] ; then
echo -e "${G} ${NODE_NAME^^} MASTERNODE MANAGER${N}"
echo -e "${D}───────────────────────────────────────────────────────────────────────────────${N}"
echo
echo -e "${G}This script will guide you through the installation, configuration${N}"
echo -e "${G}and management of your $NODE_NAME masternode${N}."
if [[ $DUPMN_ENABLE == "true" ]]; then
echo
echo -e "${Y}To install and manage additional $NODE_NAME masternodes this script${N}"
echo -e "${Y}will install and configure dupmn for $NODE_NAME when required.${N}"
echo
fi
fi
echo
echo -e "${D}Usage: $SCRIPT_NAME ${C}<option> [parameters]${N}"
echo
echo -e "${C}install ${D}: Install one or more $NODE_NAME masternodes${N}"
echo -e "${C}summary ${D}: Display $NODE_NAME main masternode installation summary${N}"
echo -e "${C}help ${D}: Display extended help text (incl. dupmn)${N}"
echo -e "${C}update ${D}: Update $NODE_NAME binaries${N}"
echo -e "${C}addnodes ${D}: Add/replace addnode list in $COIN_CONFIG${N}"
echo -e "${C}bootstrap ${D}: Download and install $NODE_NAME bootstrap${N}"
echo -e "${C}createbootstrap ${D}: Create $NODE_NAME bootstrap (from installed masternode)${N}"
echo -e "${C}stop ${D}: Stop $NODE_NAME masternode${N}"
echo -e "${C}start ${D}: Start $NODE_NAME masternode${N}"
echo -e "${C}status ${D}: Show $NODE_NAME masternode status${N}"
echo -e "${C}monitor [seconds] ${D}: Monitor $NODE_NAME masternode and system continuously${N}"
echo -e "${C}bashcompletion ${D}: Add bash-completion commands${N}"
echo -e "${C}showconf ${D}: Display contents of $COIN_CONFIG${N}"
echo -e "${C}replace [strA] [strB] ${D}: Replace 'string A' with 'string B' in $COIN_CONFIG${N}"
echo -e "${C}createswap ${D}: Create swap file${N}"
echo -e "${C}optimize ${D}: Enable SSD optimizations${N}"
if [[ $DUPMN_ENABLE == "true" ]]; then
echo -e "${C}dupmn ${D}: Install or update dupmn${N}"
fi
echo -e "${C}disclaimer ${D}: Display disclaimer${N}"
echo -e "${C}donation ${D}: Show donation addresses${N}"
echo
echo
echo -e "${D}${NODE_NAME^} related websites:${N}"
if [ ! -z "$WWW_MAIN" ]; then echo -e "${D}- ${NODE_NAME} main website : ${Y}$WWW_MAIN${N}" ; fi
if [ ! -z "$WWW_EXPL" ]; then echo -e "${D}- Explorer website : ${Y}$WWW_EXPL${N}" ; fi
if [ ! -z "$WWW_GHUB" ]; then echo -e "${D}- Github website : ${Y}$WWW_GHUB${N}" ; fi
if [ ! -z "$WWW_MNO" ]; then echo -e "${D}- MasterNodes.Online website: ${Y}$WWW_MNO${N}" ; fi
if [ ! -z "$WWW_CMC" ]; then echo -e "${D}- CoinMarkedCap website : ${Y}$WWW_CMC${N}" ; fi
if [[ $DUPMN_ENABLE == "true" ]]; then
if [ ! -z "$WWW_DUPMN" ]; then echo -e "${D}- Dupmn website : ${Y}$WWW_DUPMN${N}" ; fi
fi
}
# Check Ubuntu OS version
function check_os() {
PREFOS="false"
for OS in ${OSVERSIONS[@]}; do
if [[ $(lsb_release -rs) == $OS ]]; then
PREFOS="true"
RELEASE=$(lsb_release -rs | awk -F. '{print $1}')
case $RELEASE in
16)
COIN_URL=$COIN_URL16
;;
18)
COIN_URL=$COIN_URL18
;;
esac
else
COIN_URL=$COIN_URL16
fi
done
COIN_ZIP=$(echo $COIN_URL | awk -F'/' '{print $NF}')
}
# Pre-installation checks
function checks() {
echo
echo
echo
echo -e "${G}PRE-INSTALLATION CHECKS${N}"
echo
FAILED="0"
# Check if user is root
if [[ $EUID -ne 0 ]]; then
echo -e "${D}[${R}FAILED${D}] This script must be run as root.${N}"
FAILED="1"
else
echo -e "${D}[${G} OK ${D}] This script is run as root.${N}"
fi
# Check if a masternode has already been installed
if [ -f $COIN_FOLDER/$COIN_CONFIG ]; then
echo -e "${D}[${R}FAILED${D}] A $NODE_NAME masternode has already been installed.${N}"
FAILED="1"
else
echo -e "${D}[${G} OK ${D}] No $NODE_NAME masternode installed.${N}"
fi
# Check Ubuntu OS version
check_os
if [[ $PREFOS == "false" ]]; then
echo -e "[${R}FAILED${D}] You are running Ubuntu $(lsb_release -rs) which is not a preferred OS version (${OSVERSIONS[*]}).${N}"
FAILED="1"
else
echo -e "${D}[${G} OK ${D}] You are running a preferred Ubuntu OS version (${OS}).${N}"
fi
echo
if [[ $FAILED -eq "0" ]]; then
echo -e "${Y}Passed all pre-installation checks.${N}"
else
echo -e "${R}One or more pre-installation checks failed.${N}"
echo
#if [[ $DUPMN_ENABLE == "true" ]]; then
echo -e "${D}Do you want to continue the installation anyway (not recommended)? [y/N]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("N"|"n"|"") ]]; then
exit 1
fi
#fi
fi
}
# Update system with latest updates
function update_system() {
echo
echo
echo
echo -e "${G}INSTALL SYSTEM UPDATES${N}"
echo
echo -e "${D}Do you want to update the system? [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
echo -e "${D}Updating system...${N}"
apt-get -y update # Update the list of available packages and their versions
apt-get -y upgrade # Install newer versions of packages currently installed
#apt-get -y dist-upgrade # Install newer versions of packages and remove obsolete packages (avoid on production systems)
apt-get -y autoremove # Remove orphaned packages which are not longer needed
echo
echo -e "${D}Install system tools...${N}"
apt-get -y install zip unzip
apt-get -y install wget nano htop jq curl rsync
apt-get -y install software-properties-common
echo
echo -e "${Y}Finished system update.${N}"
else
echo
echo -e "${Y}System update skipped.${N}"
fi
}
# Install masternode dependencies
function install_dependencies() {
echo
echo
echo
echo -e "${G}INSTALL DEPENDENCIES${N}"
echo
echo -e "${D}Do you want to install dependencies? [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
echo -e "${D}Installing dependencies...${N}"
apt-get -y install libzmq3-dev
apt-get -y install libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev
apt-get -y install libevent-dev
if [[ $(lsb_release -rs) < "19.04" ]]; then
add-apt-repository -y ppa:bitcoin/bitcoin
apt-get -y update
apt-get -y install libdb4.8-dev libdb4.8++-dev
else
apt-get install -y libdb5.3-dev
apt-get install -y libdb5.3++-dev
wget http://ftp.nl.debian.org/debian/pool/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u8_amd64.deb
dpkg -i libssl1.0.0_1.0.1t-1+deb8u8_amd64.deb
fi
apt-get -y install libminiupnpc-dev
echo
echo -e "${Y}Masternode dependencies have been installed.${N}"
else
echo
echo -e "${Y}Masternode dependencies installation skipped.${N}"
fi
}
# Install masternode binaries
function install_binaries() {
echo
echo
echo
echo -e "${G}INSTALL ${NODE_NAME^^} MASTERNODE BINARIES${N}"
echo
echo -e "${D}Do you want to download and install $NODE_NAME masternode binaries? [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
if [ -f $SCRIPT_DIR/$COIN_ZIP ]; then
COIN_ZIP_DATE=$(date -r $COIN_ZIP '+%Y%m%d_%H%M%S') # Get binaries file date
mv $SCRIPT_DIR/$COIN_ZIP $SCRIPT_DIR/$COIN_ZIP.$COIN_ZIP_DATE
fi
echo -e "${D}Downloading $COIN_ZIP...${N}"
wget -q $COIN_URL -P $SCRIPT_DIR
if [ "$?" -gt "0" ]; then
echo
echo -e "${R}Failed to download $COIN_ZIP.${N}"
exit 1
else
echo
echo -e "${D}Extracting $COIN_ZIP to $COIN_PATH...${N}"
extract $SCRIPT_DIR/$COIN_ZIP $COIN_PATH
if [ "$?" -gt "0" ]; then
echo
echo -e "${R}Failed to extract $COIN_ZIP.${N}"
exit 1
else
rm -f $SCRIPT_DIR/$COIN_ZIP
echo
echo -e "${D}Deleting ${COIN_ZIP}...${N}"
echo
echo -e "${D}Setting execution permissions...${N}"
chmod +x $COIN_PATH/$COIN_DAEMON
chmod +x $COIN_PATH/$COIN_CLI
fi
fi
echo
echo -e "${Y}Masternode binaries have been installed.${N}"
else
echo
if [ -f $COIN_PATH/$COIN_DAEMON ]; then
echo -e "${Y}Masternode binaries installation skipped.${N}"
else
echo -e "${Y}Masternode installation aborted.${N}"
exit 1
fi
fi
}
# Update masternode binaries
function update_binaries() {
echo
echo
echo
echo -e "${G}UPDATE ${NODE_NAME^^} MASTERNODE BINARIES${N}"
echo
if [ -f $DUPMN_CONFIG ]; then
echo -e "${Y}Please make sure that all additional masternodes are stopped before and restarted after the update.${N}"
echo
fi
echo -e "${D}Do you want to download and update $NODE_NAME masternode binaries? [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
# Check Ubuntu OS version
check_os
if [[ $PREFOS == "false" ]]; then
echo -e "${R}You are running Ubuntu $(lsb_release -rs) which is not a preferred OS version (${OSVERSIONS[*]}).${N}"
echo
echo -e "${D}Do you want to continue the installation anyway (not recommended)? [y/N]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("N"|"n"|"") ]]; then
echo
echo -e "${Y}Masternode binaries update aborted.${N}"
echo
exit 1
fi
fi
if [ -f $SCRIPT_DIR/$COIN_ZIP ]; then
COIN_ZIP_DATE=$(date -r $COIN_ZIP '+%Y%m%d_%H%M%S') # Get binaries file date
mv $SCRIPT_DIR/$COIN_ZIP $SCRIPT_DIR/$COIN_ZIP.$COIN_ZIP_DATE
fi
echo -e "${D}Downloading $COIN_ZIP...${N}"
wget -q $COIN_URL -P $SCRIPT_DIR
if [ "$?" -gt "0" ]; then
echo -e "${R}Failed to download $COIN_ZIP.${N}"
exit 1
else
if [ -f "$COIN_FOLDER/$COIN_PID" ]; then
ps -ef | grep $(/bin/cat $COIN_FOLDER/$COIN_PID) | grep $COIN_DAEMON | grep -v grep >/dev/null 2>&1
EXITCODE="$?"
if [[ "$EXITCODE" -eq "0" ]]; then
STARTED="yes"
node_stop
else
STARTED="no"
echo
echo -e "${R}Masternode PID file exist, but no process found.${N}"
fi
else
STARTED="no"
echo
echo -e "${D}Masternode is not running.${N}"
fi
echo
echo
echo
echo -e "${G}UPDATE BINARIES${N}"
echo
echo -e "${D}Extracting $COIN_ZIP to $COIN_PATH...${N}"
extract $SCRIPT_DIR/$COIN_ZIP $COIN_PATH
if [ "$?" -gt "0" ]; then
echo -e "${R}Failed to extract $COIN_ZIP.${N}"
exit 1
else
echo
echo -e "${D}Setting execution permissions...${N}"
chmod +x $COIN_PATH/$COIN_DAEMON
chmod +x $COIN_PATH/$COIN_CLI
fi
if [[ "$STARTED" == "yes" ]]; then
node_start
else
echo
echo -e "${D}Would you like the masternode to be started? [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
node_start
fi
fi
fi
echo
echo -e "${Y}Masternode binaries have been updated.${N}"
echo
else
echo
echo -e "${Y}Masternode binaries update aborted.${N}"
echo
exit 1
fi
}
# Install fail2ban
# https://www.fail2ban.org
function install_fail2ban() {
echo
echo
echo
echo -e "${G}INSTALL FAIL2BAN${N}"
echo
echo -e "${D}Do you want to install Fail2Ban? (Recommended) [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
echo -e "${D}Installing fail2ban...${N}"
echo
apt-get -y install fail2ban
service fail2ban restart
echo
echo -e "${Y}Fail2Ban has been installed.${N}"
else
echo
echo -e "${Y}Fail2Ban installation skipped.${N}"
fi
}
# Create swap file
# https://help.ubuntu.com/community/SwapFaq
function create_swapfile() {
echo
echo
echo
echo -e "${G}CREATE SWAP SPACE${N}"
echo
# Check if swap has already been enabled
SWAP=$(swapon --show --noheadings | awk '{ print $3 }')
if [ -z "$SWAP" ]; then
echo -e "${D}For recommended swap file sizes please check 'https://help.ubuntu.com/community/SwapFaq#How_much_swap_do_I_need.3F'.${N}"
echo
echo -e "${D}Do you want to create a swap file? (Recommended for HDD, optional for SSD) [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
# Calculate swap file size
MEM=$(grep MemTotal /proc/meminfo | awk '{print $2 / 1024 / 1024 }')
SWAP=$(awk -v var="$MEM" 'BEGIN{print sqrt(var);}' | awk '{print ($0-int($0)<0.499)?int($0):int($0)+1}')
SWAP="${SWAP}G"
echo -e "${D}Please enter swap size or press enter for recommended ${SWAP}B swap file size. [$SWAP]${N}"
read SWAP_SIZE
while [[ "${SWAP_SIZE: -1}" != @("M"|"G"|"") ]]; do
echo -e "${D}Please enter correct swap file size, by adding trailing M or G, or press enter for recommended ${SWAP}B swap file size. [$SWAP]${N}"
read SWAP_SIZE
done
if [[ "$SWAP_SIZE" == "" ]]; then
SWAP_SIZE="$SWAP"
fi
echo
echo -e "${D}Creating ${SWAP_SIZE}B swap file $SWAP_FILE, this may take a few minutes...${N}"
echo
# Create swap file
fallocate -l ${SWAP_SIZE} $SWAP_FILE
# Set root only permssions for swap file
chmod 600 $SWAP_FILE
# Display swap file
ls -lh $SWAP_FILE
echo
# Set swap file as Linux swap area
mkswap $SWAP_FILE
echo
# Enable swap
swapon $SWAP_FILE
if [ $? -eq 0 ]; then
TIMESTAMP="`date +%Y%m%d_%H%M%S`"
# Create backup copy of /etc/fstab
cp /etc/fstab /etc/fstab.$TIMESTAMP
# Create backup copy of /etc/sysctl.conf
cp /etc/sysctl.conf /etc/sysctl.conf.$TIMESTAMP
# Delete swap file entry if already exists in /etc/fstab
sed -i "/${SWAP_FILE/\//} none swap sw 0 0/d" /etc/fstab
# Define swap file entry in /etc/fstab
echo "$SWAP_FILE none swap sw 0 0" | tee -a /etc/fstab
echo
# Delete current swappiness
sed -i '/vm.swappiness/d' /etc/sysctl.conf
# Add swappiness
echo 'vm.swappiness=10' >> /etc/sysctl.conf
# Activate swappiness
sysctl -w vm.swappiness=10
echo
# Delete current vfs_cache_pressure
sed -i '/vm.vfs_cache_pressure/d' /etc/sysctl.conf
# Add vfs_cache_pressure
echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf
# Activate vfs_cache_pressure
sysctl -w vm.vfs_cache_pressure=50
echo
echo -e "${Y}Swap was created and enabled successfully:${N}"
free -h
echo
swapon --show
else
echo
echo -e "${R}Operation not permitted! Swap could not be created.${N}"
fi
else
echo
echo -e "${Y}Swap file creation skipped.${N}"
fi
else
echo -e "${Y}Swap has already been enabled:${N}"
free -h
echo
swapon --show
fi
}
# SSD Optimizations
function ssd_optimizations() {
echo
echo
echo
echo -e "${G}OPTIMIZATIONS FOR SSD USAGE${N}"
echo
echo -e "${D}This will set swappiness value, set vfs_cache_pressure value, disable access time logging and enabe TRIM support.${N}"
echo
echo -e "${D}Do you want to enable optimizations for SSD usage? (Recommended when using SSD) [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
# Create backup copy of /etc/fstab
TIMESTAMP="`date +%Y%m%d_%H%M%S`"
cp /etc/sysctl.conf /etc/sysctl.conf.$TIMESTAMP
# Set swappiness to avoid using swapping as much as possible
# https://www.kernel.org/doc/Documentation/sysctl/vm.txt
CURRENTSWAPPINESS=$(sysctl -n vm.swappiness)
echo -e "${D}Set swappiness (minimize=0, maximize=100, default=60, currently defined=$CURRENTSWAPPINESS).${N}"
echo -e "${D}Please enter swappiness value. [0]${N}"
read SWAPPINESS
if [[ "$SWAPPINESS" == "" ]]; then
SWAPPINESS="0"
fi
echo -e "${D}Define swappiness in /etc/sysctl.conf.${N}"
# Delete current swappiness
sed -i '/vm.swappiness/d' /etc/sysctl.conf
# Add swappiness
echo "vm.swappiness=$SWAPPINESS" >> /etc/sysctl.conf
echo
# Activate swappiness
echo -e "${D}Activate swappiness.${N}"
sysctl -w vm.swappiness=$SWAPPINESS
echo
# Set vfs_cache_pressure to avoid using swapping as much as possible
# https://www.kernel.org/doc/Documentation/sysctl/vm.txt
CURRENTCACHEPRESSURE=$(sysctl -n vm.vfs_cache_pressure)
echo -e "${D}Set vfs_cache_pressure (minimize=0, maximize=1000, default=100, currently defined=$CURRENTCACHEPRESSURE).${N}"
echo -e "${D}Please enter vfs_cache_pressure value. [200]${N}"
read CACHEPRESSURE
if [[ "$CACHEPRESSURE" == "" ]]; then
CACHEPRESSURE="200"
fi
CACHEPRESSURE_NEW="vm.vfs_cache_pressure=$CACHEPRESSURE"
echo -e "${D}Define cache pressure in /etc/sysctl.conf.${N}"
# Delete current vfs_cache_pressure
sed -i '/vm.vfs_cache_pressure/d' /etc/sysctl.conf
# Add vfs_cache_pressure
echo "vm.vfs_cache_pressure=$CACHEPRESSURE" >> /etc/sysctl.conf
echo
# Activate vfs_cache_pressure
sysctl -w vm.vfs_cache_pressure=$CACHEPRESSURE
echo
# Disable access time logging
echo -e "${D}Disable access time logging.${N}"
echo
# Create backup copy of fstab
echo -e "${D}Backup fstab to /etc/fstab.$TIMESTAMP.${N}"
mv /etc/fstab /etc/fstab.$TIMESTAMP
echo
echo -e "${D}Add 'noatime' to /etc/fstab.${N}"
# Add noatime to fstab
awk '!/^#/ && ($2 != "swap") && ($3 != "swap") { if(!match($4, "noatime")) $4=$4",noatime" } 1' /etc/fstab.$TIMESTAMP > /etc/fstab
echo
# Enable TRIM support
echo -e "${D}Enable TRIM support (to discard blocks not in use by the filesystem).${N}"
echo
# Create nfstrim script
echo -e "${D}Create /etc/cron.daily/trim.${N}"
echo -e "#\x21/bin/sh\\nfstrim -v /" > /etc/cron.daily/trim
# Add execution permissions to trim script
chmod +x /etc/cron.daily/trim
echo
echo -e "${Y}SSD optimizations configured and enabled.${N}"
else
echo
echo -e "${Y}SSD optimizations skipped.${N}"
fi
}
# Create masternode config file
function create_config() {
echo
echo
echo
echo -e "${G}CREATE MASTERNODE CONFIGURATION FILE${N}"
echo
echo -e "${D}Creating masternode configuration file ${P}$COIN_CONFIG${N}...${N}"
# Create coin folder
if [ ! -d $COIN_FOLDER ]; then
mkdir -p $COIN_FOLDER
fi
RPCUSER=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w10 | head -n1)
RPCPASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w22 | head -n1)
{
echo 'rpcuser='$RPCUSER
echo 'rpcpassword='$RPCPASSWORD
echo 'rpcallowip=127.0.0.1'
echo 'rpcport='$RPC_PORT
echo ''
echo 'port='$COIN_PORT
echo 'server=1'
echo 'listen=1'
echo 'daemon=1'
} > $COIN_FOLDER/$COIN_CONFIG
sleep 0.5
echo
echo -e "${Y}Masternode configuration file has been created.${N}"
}
function add_alias() {
echo
echo
echo
echo -e "${G}ADD ALIAS TO MASTERNODE CONFIGURATION FILE${N}"
echo
echo -e "${D}For easy recognition add an alias to the masternode configuration file.${N}"
echo
echo -e "${D}Please type an alias below (optional):${N}"
read -e ALIAS
#cat /etc/systemd/system/coinname*.service | grep ExecStart | sed -e 's/.*-conf=\(.*\).*-datadir.*/\1/'
if [[ -z "$COINKEY" ]]; then
echo
echo -e "${D}Please enter masternode private key to set alias for:${N}"
read -e COINKEY
fi
# Selecting correct config file
CONFIG=$(grep -l $COINKEY $COIN_FOLDER*/$COIN_CONFIG)
if [[ ! -z "$CONFIG" ]]; then
if [[ "$ALIAS" ]]; then
# Delete alias (copied by dupmn)
sed -i '/\#\[.*\]\#/d' $CONFIG
# Delete empty lines at beginning of Masternode config file
sed -i '/./,$!d' $CONFIG
# Add new alias
sed -i "1i #[ ${ALIAS} ]#\n" $CONFIG
echo
echo -e "${Y}Masternode alias added to configuration file $CONFIG.${N}"
else
# Delete alias (copied by dupmn)
sed -i '/\#\[.*\]\#/d' $CONFIG
# Delete empty lines at beginning of Masternode config file
sed -i '/./,$!d' $CONFIG
echo
echo -e "${Y}Masternode alias deleted from configuration file $CONFIG.${N}"
fi
else
echo
echo -e "${R}Config file with masternode private key $COINKEY not found.${N}"
fi
}
# Install masternode bootstrap
function install_bootstrap() {
echo
echo
echo
echo -e "${G}INSTALL ${NODE_NAME^^} MASTERNODE BOOTSTRAP${N}"
echo
echo -e "${D}Your masternode will be able to start without a bootstrap but it will take longer to sync.${N}"
echo
# Create coin folder
if [ ! -d $COIN_FOLDER ]; then
mkdir -p $COIN_FOLDER
fi
# Change to coin folder
cd $COIN_FOLDER > /dev/null 2>&1
if [ -f $COIN_FOLDER/$CHAIN_ZIP ]; then
CHAIN_DATE=$(date -r $COIN_FOLDER/$CHAIN_ZIP '+%Y-%m-%d %H:%M:%S') # Get bootstrap file date
echo
echo -e "${D}A previously downloaded bootstrap file ${P}$CHAIN_ZIP${N} was found on disk, dated $CHAIN_DATE:${N}"
ls -lh $COIN_FOLDER/$CHAIN_ZIP
echo
echo -e "${D}Would you like to ${C}D${D}elete or ${C}U${D}se the file on disk? [d/U]${N}"
read -s -n1 SELECTION
case $SELECTION in
D|d)
echo
echo -e "${D}Deleting bootstrap file from disk...${N}"
rm $COIN_FOLDER/$CHAIN_ZIP
DOWNLOAD="yes"
;;
U|u|*)
echo
echo -e "${D}Using bootstrap file from disk...${N}"
DOWNLOAD="no"
;;
esac
else
DOWNLOAD="yes"
fi
if [ ! -z $CHAIN_URL ]; then
if [[ "$DOWNLOAD" == "yes" ]]; then
wget --spider $CHAIN_URL 2>&1 | grep -q 'Remote file exists.'
if [ "$?" -gt "0" ]; then
echo
echo -e "${R}Unable to download bootstrap file, the remote file does not exist.${N}"
echo
echo -e "${D}No worries, your masternode will be able to start without a bootstrap.${N}"
else
CHAIN_SIZE=$(wget --spider $CHAIN_URL 2>&1 | grep Length | awk -F"[()]" '{print $2}')
echo
echo -e "${D}Do you want to download $CHAIN_SIZE bootstrap file? [Y/n]${N}"
read -s -n1 SELECTION
if [[ $SELECTION == @("Y"|"y"|"") ]]; then
echo
echo -e "${D}Downloading bootstrap file ($CHAIN_ZIP), this may take a few minutes...${N}"
wget -q $CHAIN_URL -P $COIN_FOLDER --show-progress
if [ "$?" -gt "0" ]; then
echo
echo -e "${R}Failed to download bootstrap file.${N}"
echo
echo -e "${D}No worries, your masternode will be able to start without a bootstrap.${N}"
else