forked from ZelScripts/ZelNodeInstallv3
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzelnodev3.sh
385 lines (350 loc) · 15.6 KB
/
zelnodev3.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
#!/bin/bash
#############################################################################################################################################################################
# IF PLANNING TO RUN ZELNODE FROM HOME/OFFICE/PERSONAL EQUIPMENT & NETWORK!!!
# You must understand the implications of running a ZelNode on your on equipment and network. There are many possible security issues. DYOR!!!
# Running a ZelNode from home should only be done by those with experience/knowledge of how to set up the proper security.
# It is recommended for most operators to use a VPS to run a ZelNode
#
#**Potential Issues (not an exhaustive list):**
#1. Your home network IP address will be displayed to the world. Without proper network security in place, a malicious person sniff around your IP for vulnerabilities to access your network.
#2. Port forwarding: The p2p port for ZelCash will need to be open.
#3. DDOS: VPS providers typically provide mitigation tools to resist a DDOS attack, while home networks typically don't have these tools.
#4. Zelcash daemon is ran with sudo permissions, meaning the daemon has elevated access to your system. **Do not run a ZelNode on equipment that also has a funded wallet loaded.**
#5. Static vs. Dynamic IPs: If you have a revolving IP, every time the IP address changes, the ZelNode will fail and need to be stood back up.
#6. Anti-cheating mechanisms: If a ZelNode fails benchmarking/anti-cheating tests too many times in the future, its possible your IP will be blacklisted and no nodes can not dirun using that public-facing IP.
#7. Home connections typically have a monthly data cap. ZelNodes will use 2.5 - 6 TB monthly usage depending on ZelNode tier, which can result in overage charges. Check your ISP agreement.
#8. Many home connections provide adequate download speeds but very low upload speeds. ZelNodes require 100mbps (12.5MB/s) download **AND** upload speeds. Ensure your ISP plan can provide this continually.
#9. ZelNodes can saturate your network at times. If you are sharing the connection with other devices at home, its possible to fail a benchmark if network is saturated.
#############################################################################################################################################################################
#Version V4.1
###### you must be logged in as a sudo user, not root #######
COIN_NAME='zelcash'
#wallet information
WALLET_BOOTSTRAP='https://apt.zel.cash/zelcashbootstraptxindex.zip'
BOOTSTRAP_ZIP_FILE='zelcashbootstraptxindex.zip'
FETCHPARAMS='https://raw.githubusercontent.com/zelcash/zelcash/master/zcutil/fetch-params.sh'
ZIPTAR='unzip'
CONFIG_FILE='zelcash.conf'
RPCPORT='16124'
PORT='16125'
SSHPORT=22
COIN_DAEMON='zelcashd'
COIN_CLI='zelcash-cli'
COIN_TX='zelcash-tx'
COIN_PATH='/usr/local/bin'
USERNAME="$(whoami)"
#color codes
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
GREEN='\033[1;32m'
CYAN='\033[1;36m'
NC='\033[0m'
STOP='\e[0m'
#end of required details
#
#
#
#countdown timers to provide outputs for forced pauses
#usage: count 30s, count 1m15s, count 1h10m05s
wget https://github.com/antonmedv/countdown/releases/download/v1.0.0/countdown_linux_amd64 -O count &> /dev/null
sudo chmod 755 count
sudo mv count /usr/local/bin
#countdown "00:00:30" is a 30 second countdown
countdown()
(
IFS=:
set -- $*
secs=$(( ${1#0} * 3600 + ${2#0} * 60 + ${3#0} ))
while [ $secs -gt 0 ]
do
sleep 1 &
printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
secs=$(( $secs - 1 ))
wait
done
echo -e "\033[1K"
)
#Suppressing password prompts for this user so zelnode can operate
sudo echo -e "$(whoami) ALL=(ALL) NOPASSWD:ALL" | sudo EDITOR='tee -a' visudo
clear
echo -e "${YELLOW}==========================================================="
echo -e "ZelNode Setup, v4.1"
echo -e "${YELLOW}===========================================================${NC}"
echo -e "${BLUE}21 Oct 2019, by AltTank fam, dk808, Goose-Tech, Skyslayer, & Packetflow${NC}"
echo -e
echo -e "${CYAN}Node setup starting, press [CTRL-C] to cancel.${NC}"
count 4s
echo -e
if [ "$USERNAME" = "root" ]; then
echo -e "${CYAN}You are currently logged in as ${NC}root${CYAN}, please log out and log back in with the username you just created.${NC}"
exit
fi
# searcch sshd conf file for ssh port if not default ask user for new port/
# set var SSHPORT by user imput if not default this is used for UFW firewall settings
searchString="Port 22"
file="/etc/ssh/sshd_config"
if grep -Fq "$searchString" $file ; then
echo -e "SSH is currently set to the default port 22."
else
echo -e "Looks like you have configured a custom SSH port..."
echo -e
read -p 'Enter your custom SSH port, or hit [ENTER] for default: ' SSHPORT
if [ -z "$SSHPORT" ]; then
SSHPORT=22
fi
fi
echo -e "${YELLOW}Using SSH port:${GREEN}" $SSHPORT
echo -e "${NC}"
sleep 2
#get WAN IP ask user to verify it and or change it if needed
WANIP=$(wget http://ipecho.net/plain -O - -q)
whiptail --title "IP ADDRESS CONFIRMATION" --yesno "Detected IP address is $WANIP is this correct?" 8 58
ANSWER=$?
if [ $ANSWER = 1 ]; then
WANIP=$(whiptail --inputbox "Enter IP address" 8 58 3>&1 1>&2 2>&3)
fi
#Ask user to input Zelnode privkey
zelnodeprivkey=$(whiptail --title "ZELNODE PRIVKEY" --inputbox "Enter your Zelnode Privkey generated by your Zelcore/Zelmate wallet" 8 72 3>&1 1>&2 2>&3)
#check for any instances of zel and remove them to allow script to run again
sudo systemctl stop zelcash > /dev/null 2>&1 && sleep 3
sudo zelcash-cli stop > /dev/null 2>&1 && sleep 5
sudo killall $COIN_DAEMON > /dev/null 2>&1
sudo rm /usr/local/bin/zelcash* > /dev/null 2>&1 && sleep 2
sudo rm /usr/bin/zelcash* > /dev/null 2>&1 && sleep 2
sudo apt-get purge zelcash -y > /dev/null 2>&1 && sleep 2
if [ -f /etc/apt/sources.list.d/zelcash.list ]; then
sudo rm /etc/apt/sources.list.d/zelcash.list
fi
echo -e "${YELLOW}=========================================================="
echo "INSTALLING ZELNODE DEPENDENCIES"
echo -e "==========================================================${NC}"
echo "Adding ZelCash Repos & Installing Packages..."
sleep 2
#adding ZelCash APT Repo
echo 'deb https://zelcash.github.io/aptrepo/ all main' | sudo tee /etc/apt/sources.list.d/zelcash.list > /dev/null
gpg --keyserver keyserver.ubuntu.com --recv 4B69CA27A986265D > /dev/null
gpg --keyserver na.pool.sks-keyservers.net --recv 4B69CA27A986265D > /dev/null
gpg --keyserver eu.pool.sks-keyservers.net --recv 4B69CA27A986265D > /dev/null
gpg --export 4B69CA27A986265D | sudo apt-key add -
sudo apt-get update -y
#installing dependencies
echo -e "${YELLOW}Installing Packages...${NC}"
sudo apt-get install software-properties-common -y
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install nano htop pwgen ufw figlet -y
sudo apt-get install build-essential libtool pkg-config -y
sudo apt-get install libc6-dev m4 g++-multilib -y
sudo apt-get install autoconf ncurses-dev unzip git python python-zmq -y
sudo apt-get install wget curl bsdmainutils automake -y
sudo apt-get remove sysbench -y
echo -e "${YELLOW}Packages complete...${NC}"
echo -e
if [ -f ~/.zelcash/zelcash.conf ]; then
echo -e "${CYAN}Existing conf file found, backing up to zelcash.old ...${NC}"
sudo mv ~/.zelcash/zelcash.conf ~/.zelcash/zelcash.old;
fi
RPCUSER=`pwgen -1 8 -n`
PASSWORD=`pwgen -1 20 -n`
if [ "x$PASSWORD" = "x" ]; then
PASSWORD=${WANIP}-`date +%s`
fi
echo -e "${GREEN}Creating MainNet Conf File...${NC}"
sleep 3
mkdir ~/.zelcash
touch ~/.zelcash/$CONFIG_FILE
echo "rpcuser=$RPCUSER" >> ~/.zelcash/$CONFIG_FILE
echo "rpcpassword=$PASSWORD" >> ~/.zelcash/$CONFIG_FILE
echo "rpcallowip=127.0.0.1" >> ~/.zelcash/$CONFIG_FILE
echo "rpcport=$RPCPORT" >> ~/.zelcash/$CONFIG_FILE
echo "port=$PORT" >> ~/.zelcash/$CONFIG_FILE
echo "zelnode=1" >> ~/.zelcash/$CONFIG_FILE
echo zelnodeprivkey=$zelnodeprivkey >> ~/.zelcash/$CONFIG_FILE
echo "server=1" >> ~/.zelcash/$CONFIG_FILE
echo "daemon=1" >> ~/.zelcash/$CONFIG_FILE
echo "txindex=1" >> ~/.zelcash/$CONFIG_FILE
echo "listen=1" >> ~/.zelcash/$CONFIG_FILE
echo "logtimestamps=1" >> ~/.zelcash/$CONFIG_FILE
echo "externalip=$WANIP" >> ~/.zelcash/$CONFIG_FILE
echo "bind=$WANIP" >> ~/.zelcash/$CONFIG_FILE
echo "addnode=explorer.zel.cash" >> ~/.zelcash/$CONFIG_FILE
echo "addnode=explorer.zel.zelcore.io" >> ~/.zelcash/$CONFIG_FILE
echo "addnode=explorer2.zel.cash" >> ~/.zelcash/$CONFIG_FILE
echo "addnode=blockbook.zel.network" >> ~/.zelcash/$CONFIG_FILE
echo "maxconnections=256" >> ~/.zelcash/$CONFIG_FILE
sleep 2
#Setup zel debug.log log file rotation
echo -e "${YELLOW}Configuring log rotate function...${NC}"
sleep 1
if [ -f /etc/logrotate.d/zeldebuglog ]; then
echo -e "${CYAN}Existing log rotate conf found, backing up to ~/zeldebuglogrotate.old ...${NC}"
sudo mv /etc/logrotate.d/zeldebuglog ~/zeldebuglogrotate.old;
sleep 2
fi
touch /home/$USERNAME/zeldebuglog
cat <<EOM > /home/$USERNAME/zeldebuglog
/home/$USERNAME/.zelcash/debug.log {
compress
copytruncate
missingok
daily
rotate 7
}
EOM
cat /home/$USERNAME/zeldebuglog | sudo tee -a /etc/logrotate.d/zeldebuglog > /dev/null
rm /home/$USERNAME/zeldebuglog
echo -e "${GREEN}Log rotate configuration complete.\n~/.zelcash/debug.log file will be backed up daily for 7 days then rotated.${NC}"
sleep 5
#begin downloading wallet binaries
echo -e "Installing ZelCash daemon...${NC}"
sudo apt-get install zelcash -y
sudo chmod 755 /usr/local/bin/zelcash*
# Download and extract the bootstrap chainstate and blocks files to ~/.zelcash
rm -rf $BOOTSTRAP_ZIP_FILE
if [ -e ~/.zelcash/blocks -a -e ~/.zelcash/chainstate ]; then
rm -rf ~/.zelcash/blocks ~/.zelcash/chainstate
echo -e "${GREEN}Downloading wallet bootstrap please be patient...${NC}"
wget $WALLET_BOOTSTRAP
unzip -o $BOOTSTRAP_ZIP_FILE -d /home/$USERNAME/.zelcash
rm -rf $BOOTSTRAP_ZIP_FILE
else
echo -e "${GREEN}Downloading wallet bootstrap please be patient...${NC}"
wget $WALLET_BOOTSTRAP
unzip -o $BOOTSTRAP_ZIP_FILE -d /home/$USERNAME/.zelcash
rm -rf $BOOTSTRAP_ZIP_FILE
fi
sleep 2
#Downloading chain params
echo ""
echo -e "${GREEN}Downloading chain params...${NC}"
wget -q $FETCHPARAMS
chmod 770 fetch-params.sh &> /dev/null
bash fetch-params.sh
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME
rm fetch-params.sh
echo -e "${YELLOW}Done fetching chain params.${NC}"
#Downloading update script
if [ -f ~/zelnodeupdate.sh ]; then
rm ~/zelnodeupdate.sh
echo -e "${GREEN}Downloading update script for future updates...${NC}"
wget https://raw.githubusercontent.com/zelcash/ZelNodeInstallv3/master/zelnodeupdate.sh && chmod +x zelnodeupdate.sh
else
echo -e "${GREEN}Downloading update script for future updates...${NC}"
wget https://raw.githubusercontent.com/zelcash/ZelNodeInstallv3/master/zelnodeupdate.sh && chmod +x zelnodeupdate.sh
fi
#Downloading chown script and create cron job to run it every minute
if [ -f ~/chown.sh ]; then
rm ~/chown.sh
echo -e "${GREEN}Installing chown script to make sure working directory is owned by User...${NC}"
wget https://raw.githubusercontent.com/zelcash/ZelNodeInstallv3/master/chown.sh && chmod +x chown.sh
else
echo -e "${GREEN}Installing chown script to make sure working directory is owned by User...${NC}"
wget https://raw.githubusercontent.com/zelcash/ZelNodeInstallv3/master/chown.sh && chmod +x chown.sh
fi
echo -e "${GREEN}Creating cron job to run the chown script...${NC}"
crontab -l | grep -v "home/$USERNAME/chown.sh" | crontab -
sleep 1
echo "* * * * * /home/$USERNAME/chown.sh >/dev/null 2>&1" >> tempcron
crontab tempcron
rm tempcron
# setup zelnode daemon to run as a service
echo -e "${GREEN}Creating system service file...${NC}"
sudo touch /etc/systemd/system/$COIN_NAME.service
sudo chown $USERNAME:$USERNAME /etc/systemd/system/$COIN_NAME.service
cat << EOF > /etc/systemd/system/$COIN_NAME.service
[Unit]
Description=$COIN_NAME service
After=network.target
[Service]
Type=forking
User=$USERNAME
Group=$USERNAME
WorkingDirectory=/home/$USERNAME/.zelcash/
ExecStart=$COIN_PATH/$COIN_DAEMON -datadir=/home/$USERNAME/.zelcash/ -conf=/home/$USERNAME/.zelcash/$CONFIG_FILE -daemon
ExecStop=-$COIN_PATH/$COIN_CLI stop
Restart=always
RestartSec=3
PrivateTmp=true
TimeoutStopSec=60s
TimeoutStartSec=10s
StartLimitInterval=120s
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
EOF
sudo chown root:root /etc/systemd/system/$COIN_NAME.service
sudo systemctl daemon-reload
sleep 3
sudo systemctl enable $COIN_NAME.service &> /dev/null
echo -e "${YELLOW}Systemctl Complete....${NC}"
echo ""
echo -e "${YELLOW}=================================================================="
echo "DO NOT CLOSE THIS WINDOW OR TRY TO FINISH THIS PROCESS "
echo "PLEASE WAIT UNTIL YOU SEE THE RESTARTING WALLET MESSAGE"
echo -e "==================================================================${NC}"
echo ""
echo -e "${GREEN}Configuring firewall and enabling fail2ban...${NC}"
sudo ufw allow $SSHPORT/tcp
sudo ufw allow $PORT/tcp
sudo ufw logging on
sudo ufw default deny incoming
sudo ufw default allow outgoing
echo "y" | sudo ufw enable >/dev/null 2>&1
sudo systemctl enable fail2ban >/dev/null 2>&1
sudo systemctl start fail2ban >/dev/null 2>&1
echo -e "${YELLOW}Basic security completed...${NC}"
echo -e "${GREEN}Starting daemon & syncing ZelNode with blockchain, please be patient...${NC}"
$COIN_DAEMON -daemon &> /dev/null
count 4m
$COIN_CLI stop &> /dev/null
sleep 15
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME
echo -e "${GREEN}Restarting ZelNode Daemon and benchmarking...${NC}"
$COIN_DAEMON -daemon &> /dev/null
count 6m
sleep 1
for (( counter=30; counter>0; counter-- ))
do
echo -n ". "
sleep 1
done
printf "\n"
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME
echo -e "${GREEN}Finalizing ZelNode Setup...${NC}"
sleep 5
printf "${BLUE}"
figlet -t -k "WELCOME TO ZELNODES"
printf "${STOP}"
echo -e "${YELLOW}============================================================================================="
echo -e "${GREEN}PLEASE COMPLETE THE ZELNODE SETUP IN YOUR ZELCORE/ZELMATE WALLET${NC}"
echo -e "COURTESY OF ${BLUE}ALTTANK FAM${NC}, ${BLUE}DK808${NC}, ${BLUE}GOOSE-TECH${NC}, ${BLUE}SKYSLAYER${NC}, & ${BLUE}PACKETFLOW"
echo
echo -e "${GREEN}Commands to manage $COIN_NAME service${NC}"
echo -e " TO START- ${CYAN}systemctl start $COIN_NAME.service${NC}"
echo -e " TO STOP - ${CYAN}systemctl stop $COIN_NAME.service${NC}"
echo -e " STATUS - ${CYAN}systemctl status $COIN_NAME.service${NC}"
echo -e "In the event server ${RED}reboots${NC} daemon service will ${GREEN}auto-start${NC}"
echo
echo -e "${GREEN}To update binaries wait for announcement that update is ready then enter:${NC} ${CYAN}./zelnodeupdate.sh${NC}"
echo -e "${YELLOW}=============================================================================================${NC}"
echo -e
read -n1 -r -p "Press any key to continue..." key
for (( countera=120; countera>0; countera-- ))
do
clear
echo -e "${YELLOW}==================================================================================="
echo -e "${GREEN}ZELNODE SYNC STATUS"
echo -e "THIS SCREEN REFRESHES EVERY 30 SECONDS"
echo -e "TO VIEW THE CURRENT BLOCK GO TO https://explorer.zel.cash/ "
echo -e "DO NOT START THE ZELNODE UNTIL THE ZNSYNC STATUS RETURNS WITH SYNCHRONIZATION FINISHED"
echo -e "AND AT LEAST 15 CONFIRMATIONS OF YOUR COLLATERAL TX"
echo -e "${YELLOW}===================================================================================${NC}"
echo ""
$COIN_CLI getinfo
sleep 2
$COIN_CLI znsync status
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME
echo -e "${GREEN}Press [CTRL-C] when correct blockheight has been reached and znsync status returns with Synchronization finished.${NC}"
countdown "00:00:30"
done
printf "\n"