-
Notifications
You must be signed in to change notification settings - Fork 0
/
prime_IPv4.sh
367 lines (334 loc) · 14.5 KB
/
prime_IPv4.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
#!/usr/bin/env bash
#:: Kabberry team
#:: Copyright // 2019-01-01
#:: Version: v3.1
#:: Tested on Ubuntu 18.04 & Ubuntu 16.04
cat << "PSC"
_____ _____ _____ ___ ____ _____ ______ _______ _ _ _____
| __ \ / ____|/ ____| |__ \ |___ \ / ____| ____|__ __| | | | __ \
| |__) | (___ | | ) | __) | | (___ | |__ | | | | | | |__) |
| ___/ \___ \| | / / |__ < \___ \| __| | | | | | | ___/
| | ____) | |____ / /_ _ ___) | ____) | |____ | | | |__| | |
|_| |_____/ \_____| |____(_)____/ |_____/|______| |_| \____/|_|
PSC
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo $(date)
echo ""
echo "Good day. This is automated cold masternode setup for Kabberry project. Auto installer was tested on specific environment. Don't try to install masternode with undocumented operating system!"
echo ""
echo "Installation content:"
echo "kabberry core v3.1"
echo
echo "Setup can be launched"
echo "Do you agree?"
echo -e "${GREEN}(y)es${NC}/${RED}(n)o"${NC}?
read agree
if [ "$agree" != "y" ]; then
echo "Setup canceled" && exit 1
fi
OS_version=$(cat /etc/lsb-release | grep -c bionic)
OS_version2=$(cat /etc/lsb-release | grep -c xenial)
if [ "$OS_version" -ne "1" ]; then
echo ""
echo -e "${RED}Looks like your OS version is not Ubuntu 18.04 Bionic //${GREEN} Maybe Ubuntu 16.04 Xenial? - Checking...${NC}"
if [ "$OS_version2" -eq "1" ]; then
echo ""
else
echo ""
echo -e "${RED}Looks like your OS version is not Ubuntu 16.04 Xenial or Ubuntu 18.04 Bionic${NC}" && exit 1
fi
fi
sudo apt-get update -y
if [ $? -ne "0" ]; then echo -e "${RED}Cannot update ubuntu repos${NC}" && exit 1; fi
sudo apt-get install software-properties-common -y 1> /dev/null
if [ $? -ne "0" ]; then echo -e "${RED}Unable to install software-properties-common${NC}" && exit 1; fi
sudo add-apt-repository universe -y 1> /dev/null
if [ $? -ne "0" ]; then echo -e "${RED}Unable to add repository universe${NC}" && exit 1; fi
sudo apt-get install dnsutils jq curl -y 1> /dev/null
if [ $? -ne "0" ]; then echo -e "${RED}Unable to install dnsutils jq curl${NC}" && exit 1; fi
echo ""
wanip=$(curl -s 4.ipquail.com/ip)
if [ -z "${wanip}" ]; then
echo -e "${RED}Sorry, we don't know your external IPv4 addr${NC}" && echo ""
echo -e "${GREEN}Input your IPv4 addr manually:${NC}" && read wanip
fi
echo "Your external IP is $wanip y/n?"
read wan
if [ "$wan" != "y" ]; then
echo -e "${RED}Sorry, we don't know your external IPv4 addr${NC}" && exit 1
fi
# Check install or update for Bionic //
[ -f /etc/apt/sources.list.d/bitcoin-ubuntu-bitcoin-bionic.list ]
if [ "$?" -eq "0" ]; then
echo ""
echo -e "Looks like you are trying to setup second time? You need fresh ${GREEN}(i)nstall${NC} or ${RED}(u)pdate${NC} your MN?"
echo -e "${GREEN}i${NC}/${RED}u"${NC}?
read setorupd
if [ "$setorupd" = "u" ]; then
sudo systemctl stop kabberrycore &&
echo -e "${GREEN}1/5 Kabberry service is stopped${NC}" &&
cd /usr/bin &&
sudo rm -fr kabberry-cli kabberryd &&
cd ~ &&
rm -fr kabberry-cli kabberryd kabberry-tx kabberry_linux.zip &&
echo -e "${GREEN}2/5 Old Kabberry wallet is deleted${NC}" &&
wget https://github.com/KABBERRY/Kabberry-Coin/releases/download/v3.1.99/kabberry_linux.zip &&
echo -e "${GREEN}3/5 Kabberry wallet is downloaded${NC}" &&
unzip -o kabberry*.zip &&
sudo cp -fr kabberry-cli kabberryd /usr/bin/ &&
rm -fr kabberry-cli kabberryd kabberry-tx kabberry-qt kabberry_linux.zip &&
cd /usr/bin &&
chmod -R 755 kabberry-cli kabberryd &&
cd ~ &&
echo -e "${GREEN}4/5 Kabberry wallet is updated${NC}" &&
sudo systemctl start kabberrycore &&
echo -e "${GREEN}5/5 Kabberry service is started${NC}" &&
echo -e "${GREEN}Update is full completed.${NC}" && exit 1; fi
if [ "$setorupd" = "i" ]; then
sudo systemctl stop kabberrycore &&
echo "" &&
echo -e "${GREEN}Setup Kabberry masternode started${NC}" &&
sleep 5
else
echo "" &&
echo -e "${RED}Sorry, we cannot continue${NC}" && exit 1; fi
fi
# Check install or update for Xenial //
[ -f /etc/apt/sources.list.d/bitcoin-ubuntu-bitcoin-xenial.list ]
if [ "$?" -eq "0" ]; then
echo ""
echo -e "Looks like you are trying to setup second time? You need fresh ${GREEN}(i)nstall${NC} or ${RED}(u)pdate${NC} your MN?"
echo -e "${GREEN}i${NC}/${RED}u"${NC}?
read setorupd
if [ "$setorupd" = "u" ]; then
sudo systemctl stop kabberrycore &&
echo -e "${GREEN}1/5 Kabberry service is stopped${NC}" &&
cd /usr/bin &&
sudo rm -fr kabberry-cli kabberryd &&
cd ~ &&
rm -fr kabberry-cli kabberryd kabberry-tx kabberry_linux.zip &&
echo -e "${GREEN}2/5 Old Kabberry wallet is deleted${NC}" &&
wget https://github.com/KABBERRY/Kabberry-Coin/releases/download/v3.0/kabberry_ubuntu_16.zip &&
echo -e "${GREEN}3/5 Kabberry wallet is downloaded${NC}" &&
unzip -o kabberry*.zip &&
sudo cp -fr kabberry-cli kabberryd /usr/bin/ &&
rm -fr kabberry-cli kabberryd kabberry-tx kabberry-qt kabberry_ubuntu_16.zip &&
cd /usr/bin &&
chmod -R 755 kabberry-cli kabberryd &&
cd ~ &&
echo -e "${GREEN}4/5 Kabberry wallet is updated${NC}" &&
sudo systemctl start kabberrycore &&
echo -e "${GREEN}5/5 Kabberry service is started${NC}" &&
echo -e "${GREEN}Update is full completed.${NC}" && exit 1; fi
if [ "$setorupd" = "i" ]; then
sudo systemctl stop kabberrycore &&
echo "" &&
echo -e "${GREEN}Setup Kabberry masternode started${NC}" &&
sleep 5
else
echo "" &&
echo -e "${RED}Sorry, we cannot continue${NC}" && exit 1; fi
fi
if [ "$OS_version" -eq "1" ]; then
# Install dep. for Bionic //
sudo add-apt-repository ppa:bitcoin/bitcoin -y
if [ $? -ne "0" ]; then echo "Unable to add bitcoin dependencies" && exit 1; fi
sudo apt-get update -y
if [ $? -ne "0" ]; then echo "Cannot update ubuntu repos" && exit 1; fi
sudo apt-get install -y libdb4.8-dev libdb4.8++-dev
if [ $? -ne "0" ]; then echo "Unable to install libdb dependencies" && exit 1; fi
sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils software-properties-common libminiupnpc-dev libcrypto++-dev libboost-all-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev libboost-thread-dev libssl-dev libssl-dev software-properties-common unzip libzmq3-dev ufw wget git python-openssl -y
if [ $? -ne "0" ]; then echo "Unable to install major dependencies" && exit 1; fi
sudo wget https://github.com/KABBERRY/MN-Script-IPv4/raw/master/libs.zip
unzip -o libs.zip
sudo cp -fr libboost_filesystem.so.1.58.0 libboost_chrono.so.1.58.0 libboost_program_options.so.1.58.0 libboost_system.so.1.58.0 libboost_thread.so.1.58.0 libminiupnpc.so.10 libevent_core-2.0.so.5 libevent_pthreads-2.0.so.5 libevent-2.0.so.5 /usr/lib/
rm -fr libboost_filesystem.so.1.58.0 libboost_chrono.so.1.58.0 libboost_program_options.so.1.58.0 libboost_system.so.1.58.0 libboost_thread.so.1.58.0 libminiupnpc.so.10 libevent_core-2.0.so.5 libevent_pthreads-2.0.so.5 libevent-2.0.so.5 libs.zip
if [ $? -ne "0" ]; then echo "Unable to install libboost dependencies" && exit 1; fi
else
# Install dep. for Xenial //
sudo add-apt-repository ppa:bitcoin/bitcoin -y
if [ $? -ne "0" ]; then echo "Unable to add bitcoin dependencies" && exit 1; fi
sudo apt-get update -y
if [ $? -ne "0" ]; then echo "Cannot update ubuntu repos" && exit 1; fi
sudo apt-get install libdb4.8-dev libdb4.8++-dev -y
if [ $? -ne "0" ]; then echo "Unable to install libdb dependencies" && exit 1; fi
sudo apt-get install libboost-system1.58-dev libboost-system1.58.0 -y
if [ $? -ne "0" ]; then echo "Unable to install libboost dependencies" && exit 1; fi
sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-pthreads-2.0-5 libevent-dev bsdmainutils software-properties-common libminiupnpc-dev libcrypto++-dev libboost-all-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev libboost-thread-dev libssl-dev libssl-dev software-properties-common unzip libzmq3-dev ufw wget git python-openssl -y
if [ $? -ne "0" ]; then echo "Unable to install major dependencies" && exit 1; fi
fi
# Download Kabberry sources //
echo ""
echo -e "${GREEN}1/6 Downloading Kabberry sources...${NC}"
echo ""
cd /usr/bin
sudo rm -fr kabberry-cli kabberryd
cd ~/.kabberry
rm -R -fr database .lock peers.dat blocks db.log masternode.conf kabberry.conf zerocoin budget.dat debug.log mncache.dat kabberryd.pid chainstate fee_estimates.dat mnpayments.dat sporks
cd ~
rm -fr kabberry*.zip
rm -R -fr kabberry_linux
if [ "$OS_version" -eq "1" ]; then
wget https://github.com/KABBERRY/Kabberry-Coin/releases/download/v3.1.99/kabberry_linux.zip
if [ $? -ne "0" ]; then echo "Failed to download kabberryd binary" && exit 1; fi
elif [ "$OS_version2" -eq "1" ]; then
wget https://github.com/KABBERRY/Kabberry-Coin/releases/download/v3.0/kabberry_ubuntu_16.zip
if [ $? -ne "0" ]; then echo "Failed to download kabberryd binary" && exit 1; fi
fi
# Manage coin daemon and configuration //
unzip -o kabberry*.zip
echo ""
sudo cp -fr kabberry-cli kabberryd /usr/bin/
rm -fr kabberry-cli kabberryd kabberry-tx kabberry-qt kabberry_linux.zip kabberry_ubuntu_16.zip
cd /usr/bin
chmod -R 755 kabberry-cli kabberryd
cd ~
mkdir -p ~/.kabberry/
touch ~/.kabberry/kabberry.conf
cat << EOF > ~/.kabberry/kabberry.conf
rpcuser=kabberryuser
rpcpassword=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '')
txindex=1
kabberrystake=1
rpcport=34126
listen=1
port=34124
rpcallowip=127.0.0.1
daemon=1
masternode=1
addnode=77.55.217.107
addnode=89.65.101.63
addnode=77.55.216.249
EOF
#Create kabberrycore.service
echo -e "${GREEN}2/6 Create kabberrycore.service for systemd${NC}"
echo ""
echo \
"[Unit]
Description=Kabberry Core Wallet daemon & service
After=network.target
[Service]
User=root
Type=forking
ExecStart=/usr/bin/kabberryd -daemon -pid=$(echo $HOME)/.kabberry/kabberryd.pid --datadir=$(echo $HOME)/.kabberry/
PIDFile=$(echo $HOME)/.kabberry/kabberryd.pid
ExecStop=/usr/bin/kabberry-cli stop
Restart=always
RestartSec=3600
TimeoutStopSec=60s
TimeoutStartSec=10s
StartLimitInterval=120s
StartLimitBurst=5
[Install]
WantedBy=default.target" | sudo tee /etc/systemd/system/kabberrycore.service
sudo chmod 664 /etc/systemd/system/kabberrycore.service
sudo systemctl enable kabberrycore
real_user=$(echo $USER)
sudo chown -R $real_user:$real_user $(echo $HOME)/.kabberry/
# Check if user is root? If not create sudoers files to manage systemd services
echo ""
echo -e "${GREEN}3/6 Check if user is root? If not create sudoers files to manage systemd services${NC}"
if [ "$EUID" -ne 0 ]; then
sudo echo \
"%$real_user ALL= NOPASSWD: /bin/systemctl start kabberrycore
%$real_user ALL= NOPASSWD: /bin/systemctl stop kabberrycore
%$real_user ALL= NOPASSWD: /bin/systemctl restart kabberrycore" | sudo tee /tmp/$real_user
sudo mv /tmp/$(echo $real_user) /etc/sudoers.d/
fi
# Start kabberry daemon, wait for wallet creation //
sudo systemctl start kabberrycore &&
echo "" ; echo "Please wait for few minutes..."
sleep 120 &
PID=$!
i=1
sp="/-\|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "\b${sp:i++%${#sp}:1}"
done
echo ""
sudo systemctl stop kabberrycore &&
echo ""
echo -e "Shutting down daemon, reconfiguring kabberry.conf, we want to know your cold wallet ${GREEN}masternodeprivkey${NC} (example: 887Bmc8UCAuvttkt3vhFgiWCd2P6NqFpyrQZSTYbrkLpNZ1LjCL), please input now:"
echo""
read masternodeprivkey
privkey=$(echo $masternodeprivkey)
checkpriv_key=$(echo $masternodeprivkey | wc -c)
if [ "$checkpriv_key" -ne "52" ];
then
echo ""
echo "Looks like your $privkey is not correct, it should cointain 52 symbols, please paste it one more time"
read masternodeprivkey
privkey=$(echo $masternodeprivkey)
checkpriv_key=$(echo $masternodeprivkey | wc -c)
if [ "$checkpriv_key" -ne "52" ];
then
echo "Something wrong with masternodeprivkey, cannot continue" && exit 1
fi
fi
echo ""
echo "Give some time to shutdown the wallet..."
echo ""
sleep 60 &
PID=$!
i=1
sp="/-\|"
echo -n ' '
while [ -d /proc/$PID ]
do
printf "\b${sp:i++%${#sp}:1}"
done
cat << EOF > ~/.kabberry/kabberry.conf
rpcuser=kabberryuser
rpcpassword=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '')
txindex=1
kabberrystake=1
rpcport=34126
listen=1
port=34124
rpcallowip=127.0.0.1
daemon=1
masternode=1
masternodeaddr=$wanip
masternodeprivkey=$privkey
addnode=77.55.217.107
addnode=89.65.101.63
addnode=77.55.216.249
EOF
# Firewall //
echo -e "${GREEN}4/6 Update firewall rules${NC}"
echo ""
echo "Update firewall rules"
sudo /usr/sbin/ufw limit ssh/tcp comment 'Rate limit for openssh server'
sudo /usr/sbin/ufw allow 34124/tcp comment 'Kabberry Wallet daemon'
sudo /usr/sbin/ufw --force enable
echo ""
# Fast download Blockchain
cd ~
cd .kabberry
rm -R blocks chainstate
echo ""
echo -e "${GREEN}5/6 please wait, installation script downloads Kabberry blockchain ${NC}"
echo ""
wget https://github.com/KABBERRY/Kabberry-Coin/releases/download/v3.1.99/kabberry-blockchain.zip
unzip -o kabberry-blockchain.zip
rm -f kabberry-blockchain.zip
# Final start
echo ""
echo -e "${GREEN}6/6 Masternode config done, Kabberry wallet installed - starting again${NC}"
echo ""
sudo systemctl start kabberrycore
echo -e "${RED}The blockchain is syncing from scratch. You have to wait few hours to sync all the blocks!${NC}"
echo ""
echo "Setup summary:"
echo "Masternode privkey: $privkey"
echo "Your external IPv4 addr: $wanip"
echo "Installation log: ~/kabberry_masternode_installation.log"
echo "Kabberry Core datadir: "$(echo $HOME/.kabberry/)""
echo ""
echo -e "Need additional help? Please visit Kabberry Discord channel: ${GREEN}https://discord.gg/D6KeMSA${NC}"
echo ""
kabberry-cli getinfo | grep blocks