-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup_zoc_mn.sh
363 lines (319 loc) · 10.5 KB
/
setup_zoc_mn.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
#!/bin/bash
echo "*******************************************************************************"
echo " 01coin Masternode Setup Shell Script"
echo " Created by Evydder"
echo "*******************************************************************************"
homedir=$( getent passwd "$USER" | cut -d: -f6 )
install_preqs()
{
echo "*******************************************************************************"
echo " Installing Requirements"
echo "*******************************************************************************"
issudoinstalled="$(dpkg-query -W -f='${Status}' sudo 2>/dev/null | grep -c 'ok installed')"
if [ $issudoinstalled = '0' ]
then
apt install -y sudo
fi
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:bitcoin/bitcoin
sudo apt update
sudo apt install -y build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils libboost-all-dev libdb4.8-dev libdb4.8++-dev python-virtualenv nano git openssl dnsutils
}
download()
{
echo "*******************************************************************************"
echo " Downloading and Installing 01coin"
echo "*******************************************************************************"
if [ "$release" = '16.04' ]
then
#Only needed for 16.04
sudo apt-get install -y libminiupnpc-dev
fi
mkdir ~/zeroone
# wget http://files.01coin.io/build/linux/zeroonecore-0.12.3-x86_64-linux-gnu.tar.gz
wget https://bitbucket.org/zocteam/zeroonecoin/downloads/zeroonecore-0.12.3-x86_64-linux-gnu.tar.gz
tar -xvf zeroonecore-0.12.3-x86_64-linux-gnu.tar.gz
rm ~/zeroonecore-0.12.3-x86_64-linux-gnu.tar.gz
mv ~/zeroonecore-0.12.3/bin/* ~/zeroone/
mkdir ~/.zeroonecore
}
compile()
{
#checks ram and makes swap if nessary
ram="$(awk '/MemTotal/ {print $2}' /proc/meminfo)"
minram="1048576"
if [ "$ram" -le "$minram" ]
then
dd if=/dev/zero of=/swapfile count=2048 bs=1M
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" > /etc/fstab
fi
# Download and Compile
git clone https://github.com/zocteam/zeroonecoin
cd ~/zeroonecoin
sudo ./autogen.sh
sudo ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768"
cpucores = grep -c ^processor /proc/cpuinfo
sudo make -j$cpucores
mkdir ~/zeroone
mv ~/zeroonecoin/src/zerooned ~/zeroone/zerooned
mv ~/zeroonecoin/src/zeroone-cli ~/zeroone/zeroone-cli
mv ~/zeroonecoin/src/zeroone-tx ~/zeroone/zeroone-tx
}
configQuestions()
{
echo "*******************************************************************************"
echo " Config"
echo "*******************************************************************************"
#ram
ram="$(awk '/MemTotal/ {print $2}' /proc/meminfo)"
minram="1048576"
if [ "$ram" -le "$minram" ]
then
echo "**************************************************************"
while true; do
read -p "Would you like to setup an swapfile to help with compiling? [Y/N] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "This script will now close";exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
#IP
vpsip=$(dig +short myip.opendns.com @resolver1.opendns.com)
while true; do
read -p "Is this your VPS IP address? ${vpsip} [Y/N] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Please type in your VPS IP address below:"; read vpsip;;
* ) echo "Please answer yes or no.";;
esac
done
rpcuser=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32})
rpcpassword=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32})
#Needed to be appended to the file before ask for incase of want to gen key Privatekey
if [ ! -d ".zeroonecore" ]; then
mkdir ~/.zeroonecore
fi
echo "rpcuser=${rpcuser}" >> .zeroonecore/zeroone.conf
echo "rpcpassword=${rpcpassword}" >> .zeroonecore/zeroone.conf
echo "**************************************************************"
while true; do
read -p "Would you like to provide a private key (if you already have one)? ${privkey} [Y/N] " yn
case $yn in
[Yy]* ) echo "Please type in your private key below:"; askforprivatekey;break;;
[Nn]* ) genkey;break;;
* ) echo "Please answer yes or no.";;
esac
done
echo "**************************************************************"
while true; do
read -p "Would you like a shell script to start the node? [Y/N] " yn
case $yn in
[Yy]* ) echo "$homedir/zeroone/zerooned -daemon ">> startZeroOne.sh;askstartonboot;break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo "**************************************************************"
while true; do
read -p "Would you like to install a node manager to keep the blockchain synced? [Y/N] " yn
case $yn in
[Yy]* ) setup_manager;break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
}
askforprivatekey()
{
#Masternode Priv Key
read privkey
while true; do
read -p "Is this the correct private key? ${privkey} [Y/N] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Please type in your private key below:"; read privkey;;
* ) echo "Please answer yes or no.";;
esac
done
}
askstartonboot()
{
echo "**************************************************************"
while true; do
read -p "Would you like to start the node automatically on boot? [Y/N] " yn
case $yn in
[Yy]* ) startonboot;break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
}
startonboot()
{
chmod -x startZeroOne.sh
chmod 777 startZeroOne.sh
sudo echo "@reboot $homedir/startZeroOne.sh" >> /etc/crontab
}
genkey()
{
$homedir/zeroone/zerooned -daemon
echo "Please wait while the 01coin daemon generates a new private key..."
sleep 10
while ! $homedir/zeroone/zeroone-cli getinfo; do
sleep 10
done
privkey=$($homedir/zeroone/zeroone-cli masternode genkey)
$homedir/zeroone/zeroone-cli stop
sleep 10
}
setup_manager()
{
wget https://raw.githubusercontent.com/zocteam/zoc-tools/master/mnchecker
chmod 777 mnchecker
echo "rpcport=10101" >> .zeroonecore/zeroone.conf
crontab -l > mncheckercron
echo "*/10 * * * * $homedir/mnchecker --currency-bin-cli=$homedir/zeroone/zeroone-cli --currency-bin-daemon=$homedir/zeroone/zerooned --currency-datadir=.zeroonecore" >> mncheckercron
crontab mncheckercron
rm mncheckercron
}
config()
{
echo "*******************************************************************************"
echo " Configuring 01coin Masternode"
echo "*******************************************************************************"
echo "externalip=${vpsip}:10000" >> .zeroonecore/zeroone.conf
echo "masternode=1" >> .zeroonecore/zeroone.conf
echo "masternodeprivkey=${privkey}" >> .zeroonecore/zeroone.conf
echo "maxconnections=16" >> .zeroonecore/zeroone.conf
}
sentinel()
{
echo "*******************************************************************************"
echo " Installing 01coin Sentinel"
echo "*******************************************************************************"
cd ~
sudo apt install -y python-virtualenv virtualenv
git clone https://github.com/zocteam/sentinel.git zoc_sentinel
cd zoc_sentinel
virtualenv ./venv
./venv/bin/pip install -r requirements.txt
crontab -l > mycron
echo "* * * * * cd $(pwd) && SENTINEL_DEBUG=1 ./venv/bin/python bin/sentinel.py >> zoc_sentinel.log >/dev/null 2>&1" >> mycron
crontab mycron
rm mycron
cd ~
}
bootstrap()
{
cd $homedir
cd .zeroonecore
rm -f bootstrap.dat.old
wget https://files.01coin.io/mainnet/bootstrap.dat.tar.gz
tar xvf bootstrap.dat.tar.gz
rm -f bootstrap.dat.tar.gz
}
start_mn()
{
echo "*******************************************************************************"
echo " Starting 01coin Masternode"
echo "*******************************************************************************"
$homedir/zeroone/zerooned -daemon -assumevalid=0000000005812118515c654ab36f46ef2b7b3732a6115271505724ff972417c7
echo 'If the above says "ZeroOne Core server starting" then masternode is installed'
}
adds_nodes()
{
$homedir/zeroone/zeroone-cli stop
sleep 10
#fixes error if folders dont exist
if [ ! -d ".zeroonecore" ]; then
mkdir .zeroonecore
fi
addnodes
#Reason for not starting it manually is I don't know where it's installed
echo "*******************************************************************************"
echo " Please Manually Start Your Masternode"
echo "*******************************************************************************"
info
#Kill off the program
exit 1
}
info()
{
echo "*******************************************************************************"
echo " Information"
echo "*******************************************************************************"
echo "In your local wallet, please append the following to masternode.conf:"
echo ""
echo "MN-X ${vpsip}:10000 ${privkey} collateral_output_txid collateral_output_index"
echo ""
echo "To manually start the node run : zeroone/zerooned -daemon "
echo "To check the status of the masternode run : zeroone/zeroone-cli getinfo "
echo ""
echo "If you require any help ask in the Discord server: https://discord.gg/jbMjjnV"
echo ""
echo "If this helps you out and you want to tip :"
echo "(ZOC) ZNZL6JXTeF3nP8fSWf46wbRqAMjLezyRHK"
echo "*******************************************************************************"
}
install_mn()
{
#Checks Versions
release=$(lsb_release -r -s)
case $release in
"14.04")
download;;
"16.04")
download;;
"18.04")
download;;
"19.04")
download;;
"20.04")
download;;
*)
compile;;
esac
}
#checks if install is there and ask if want reset it
if [ -d ".zeroonecore" ]; then
echo "*******************************************************************************"
echo " An Existing Setup Detected"
echo "*******************************************************************************"
while true; do
read -p "Would you like to reset the install? [Y/N] " yn
case $yn in
[Yy]* ) sudo rm -R .zeroonecore/;break;;
[Nn]* ) exit 1;break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
#checks args then runs the functions
case $1 in
compile)
install_preqs
compile
configQuestions
sentinel
config
bootstrap
start_mn
info;;
manager)
setup_manager;;
*)
install_preqs
install_mn
configQuestions
sentinel
config
bootstrap
start_mn
info
;;
esac