-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelio-MN.sh
More file actions
276 lines (246 loc) · 9.13 KB
/
Helio-MN.sh
File metadata and controls
276 lines (246 loc) · 9.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/bin/bash
# HelioCoin Masternode Setup Script V1.0 for Ubuntu LTS
#
# Script will attempt to autodetect primary public IP address
# and generate masternode private key unless specified in command line
#
# Usage:
# bash heliocoin.autoinstall.sh
#
#Color codes
RED='\033[0;91m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
#TCP port
PORT=14920
RPC=14919
#Clear keyboard input buffer
function clear_stdin { while read -r -t 0; do read -r; done; }
#Delay script execution for N seconds
function delay { echo -e "${GREEN}Sleep for $1 seconds...${NC}"; sleep "$1"; }
#Stop daemon if it's already running
function stop_daemon {
if pgrep -x 'heliod' > /dev/null; then
echo -e "${YELLOW}Attempting to stop heliod${NC}"
helio-cli stop
sleep 30
if pgrep -x 'heliod' > /dev/null; then
echo -e "${RED}heliod daemon is still running!${NC} \a"
echo -e "${RED}Attempting to kill...${NC}"
sudo pkill -9 heliod
sleep 30
if pgrep -x 'heliod' > /dev/null; then
echo -e "${RED}Can't stop heliod! Reboot and try again...${NC} \a"
exit 2
fi
fi
fi
}
#Process command line parameters
genkey=$1
clear
echo -e "${GREEN} ------- Helio Coin MASTERNODE INSTALLER v1.0.0--------+
| |
| |::
| The installation will install and run |::
| the masternode under a user Helio Coin. |::
| |::
| This version of installer will setup |::
| fail2ban and ufw for your safety. |::
| |::
+------------------------------------------------+::
::::::::::::::::::::::::::::::::::::::::::::::::::S${NC}"
echo "Do you want me to generate a masternode private key for you?[y/n]"
read DOSETUP
if [[ $DOSETUP =~ "n" ]] ; then
read -e -p "Enter your private key:" genkey;
read -e -p "Confirm your private key: " genkey2;
fi
#Confirming match
if [ $genkey = $genkey2 ]; then
echo -e "${GREEN}MATCH! ${NC} \a"
else
echo -e "${RED} Error: Private keys do not match. Try again or let me generate one for you...${NC} \a";exit 1
fi
sleep .5
clear
# Determine primary public IP address
dpkg -s dnsutils 2>/dev/null >/dev/null || sudo apt-get -y install dnsutils
publicip=$(dig +short myip.opendns.com @resolver1.opendns.com)
if [ -n "$publicip" ]; then
echo -e "${YELLOW}IP Address detected:" $publicip ${NC}
else
echo -e "${RED}ERROR: Public IP Address was not detected!${NC} \a"
clear_stdin
read -e -p "Enter VPS Public IP Address: " publicip
if [ -z "$publicip" ]; then
echo -e "${RED}ERROR: Public IP Address must be provided. Try again...${NC} \a"
exit 1
fi
fi
if [ -d "/var/lib/fail2ban/" ];
then
echo -e "${GREEN}Packages already installed...${NC}"
else
echo -e "${GREEN}Updating system and installing required packages...${NC}"
sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y autoremove
sudo apt-get -y install wget nano htop jq
sudo apt-get install unzip
sudo apt -y install software-properties-common
fi
#Generating Random Password for JSON RPC
rpcuser=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
rpcpassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
#Create 2GB swap file
if grep -q "SwapTotal" /proc/meminfo; then
echo -e "${GREEN}Skipping disk swap configuration...${NC} \n"
else
echo -e "${YELLOW}Creating 2GB disk swap file. \nThis may take a few minutes!${NC} \a"
touch /var/swap.img
chmod 600 swap.img
dd if=/dev/zero of=/var/swap.img bs=1024k count=2000
mkswap /var/swap.img 2> /dev/null
swapon /var/swap.img 2> /dev/null
if [ $? -eq 0 ]; then
echo '/var/swap.img none swap sw 0 0' >> /etc/fstab
echo -e "${GREEN}Swap was created successfully!${NC} \n"
else
echo -e "${RED}Operation not permitted! Optional swap was not created.${NC} \a"
rm /var/swap.img
fi
fi
#Installing Daemon
cd ~
rm -rf /usr/local/bin/heliod*
wget http://206.189.123.128/Helio-daemon.tar.gz
tar -xzvf Helio-daemon.tar.gz
sudo chmod -R 755 helio-cli
sudo chmod -R 755 heliod
cp -p -r heliod /usr/local/bin
cp -p -r helio-cli /usr/local/bin
helio-cli stop
sleep 5
#Create datadir
if [ ! -f ~/.helio/helio.conf ]; then
sudo mkdir ~/.helio
fi
cd ~
clear
echo -e "${YELLOW}Creating helio.conf...${NC}"
# If genkey was not supplied in command line, we will generate private key on the fly
if [ -z $genkey ]; then
cat <<EOF > ~/.helio/helio.conf
rpcuser=$rpcuser
rpcpassword=$rpcpassword
EOF
sudo chmod 755 -R ~/.helio/helio.conf
#Starting daemon first time just to generate masternode private key
heliod -daemon
sleep 7
while true;do
echo -e "${YELLOW}Generating masternode private key...${NC}"
genkey=$(helio-cli createmasternodekey)
if [ "$genkey" ]; then
break
fi
sleep 7
done
fi
#Stopping daemon to create helio.conf
helio-cli stop
sleep 5
cd ~/.helio/ && rm -rf blocks chainstate sporks
cd ~/.helio/ && wget http://206.189.123.128/bootstrap.tar.gz
cd ~/.helio/ && tar -xzvf bootstrap.tar.gz
sudo rm -rf ~/.helio/bootstrap.tar.gz
# Create helio.conf
cat <<EOF > ~/.helio/helio.conf
rpcuser=$rpcuser
rpcpassword=$rpcpassword
rpcallowip=127.0.0.1
rpcport=$RPC
port=$PORT
listen=1
server=1
daemon=1
logtimestamps=1
maxconnections=256
masternode=1
externalip=$publicip:$PORT
bind=$publicip:$PORT
masternodeaddr=$publicip:$PORT
masternodeprivkey=$genkey
addnode=206.189.29.97
addnode=206.189.19.123
addnode=209.97.130.232
addnode=178.128.34.0
addnode=142.93.41.217
addnode=206.189.112.54
addnode=206.189.123.128
EOF
heliod -daemon
#Finally, starting daemon with new helio.conf
printf '#!/bin/bash\nif [ ! -f "~/.helio/heliod.pid" ]; then /usr/local/bin/heliod -daemon ; fi' > /root/helioauto.sh
chmod -R 755 helioauto.sh
#Setting auto start cron job for heliod
if ! crontab -l | grep "helioauto.sh"; then
(crontab -l ; echo "*/5 * * * * /root/heliodauto.sh")| crontab -
fi
echo -e "========================================================================
${GREEN}Masternode setup is complete!${NC}
========================================================================
Masternode was installed with VPS IP Address: ${GREEN}$publicip${NC}
Masternode Private Key: ${GREEN}$genkey${NC}
Now you can add the following string to the masternode.conf file
======================================================================== \a"
echo -e "${GREEN}heliod_mn1 $publicip:$PORT $genkey TxId TxIdx${NC}"
echo -e "========================================================================
Use your mouse to copy the whole string above into the clipboard by
tripple-click + single-click (Dont use Ctrl-C) and then paste it
into your ${GREEN}masternode.conf${NC} file and replace:
${GREEN}heliod_mn1${NC} - with your desired masternode name (alias)
${GREEN}TxId${NC} - with Transaction Id from masternode outputs
${GREEN}TxIdx${NC} - with Transaction Index (0 or 1)
Remember to save the masternode.conf and restart the wallet!
To introduce your new masternode to the heliod network, you need to
issue a masternode start command from your wallet, which proves that
the collateral for this node is secured."
clear_stdin
read -p "*** Press any key to continue ***" -n1 -s
echo -e "Wait for the node wallet on this VPS to sync with the other nodes
on the network. Eventually the 'Is Synced' status will change
to 'true', which will indicate a complete sync, although it may take
from several minutes to several hours depending on the network state.
Your initial Masternode Status may read:
${GREEN}Node just started, not yet activated${NC} or
${GREEN}Node is not in masternode list${NC}, which is normal and expected.
"
clear_stdin
read -p "*** Press any key to continue ***" -n1 -s
echo -e "
${GREEN}...scroll up to see previous screens...${NC}
Here are some useful commands and tools for masternode troubleshooting:
========================================================================
To view masternode configuration produced by this script in helio.conf:
${GREEN}cat ~/.helio/helio.conf${NC}
Here is your helio.conf generated by this script:
-------------------------------------------------${GREEN}"
echo -e "${GREEN}heliod_mn1 $publicip:$PORT $genkey TxId TxIdx${NC}"
cat ~/.helio/helio.conf
echo -e "${NC}-------------------------------------------------
NOTE: To edit helio.conf, first stop the heliod daemon,
then edit the helio.conf file and save it in nano: (Ctrl-X + Y + Enter),
then start the heliod daemon back up:
to stop: ${GREEN}helio-cli stop${NC}
to start: ${GREEN}heliod${NC}
to edit: ${GREEN}nano ~/.helio/helio.conf${NC}
to check mn status: ${GREEN}helio-cli getmasternodestatus${NC}
========================================================================
To monitor system resource utilization and running processes:
${GREEN}htop${NC}
========================================================================
"