-
Notifications
You must be signed in to change notification settings - Fork 1
/
paws_install.sh
352 lines (311 loc) · 10.3 KB
/
paws_install.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
#!/bin/bash
# setup version: 0.0.3
TMP_FOLDER=$(mktemp -d)
CONFIG_FILE='paws.conf'
CONFIGFOLDER='/root/.paws'
COIN_DAEMON='pawsd'
COIN_CLI='paws-cli'
COIN_PATH='/usr/local/bin/'
COIN_REPO='https://github.com/paws-fund/paws-core.git'
COIN_TGZ='https://github.com/paws-fund/paws-core/releases/download/v1.0.0/paws-1.0.0-x86_64-linux-gnu.zip'
COIN_ZIP=$(echo $COIN_TGZ | awk -F'/' '{print $NF}')
COIN_NAME='PAWS'
COIN_PORT=18765
RPC_PORT=20123
NODEIP=$(curl -s4 icanhazip.com)
BINDIP=$NODEIP
BLUE="\033[0;34m"
YELLOW="\033[0;33m"
CYAN="\033[0;36m"
PURPLE="\033[0;35m"
RED='\033[0;31m'
GREEN="\033[0;32m"
NC='\033[0m'
MAG='\e[1;35m'
# this pulls the zip file down and moves it into COIN_PATH
function download_node() {
echo -e "${GREEN}Downloading and Installing VPS $COIN_NAME Daemon${NC}"
cd $TMP_FOLDER >/dev/null 2>&1
wget -q $COIN_TGZ
# this WAS looking for a compile error - but there's no compiling going on?
if [ "$?" -gt "0" ]; then
echo -e "${RED}Failed to retrieve $COIN_NAME. Please investigate.${NC}"
exit 1
fi
unzip $COIN_ZIP >/dev/null 2>&1
chmod +x $COIN_DAEMON $COIN_CLI
cp $COIN_DAEMON $COIN_CLI $COIN_PATH
cd ~ >/dev/null 2>&1
rm -rf $TMP_FOLDER >/dev/null 2>&1
# clear
}
function configure_systemd() {
echo -e "${YELLOW}Setting up systemd...${NC}."
cat << EOF > /etc/systemd/system/$COIN_NAME.service
[Unit]
Description=$COIN_NAME service
After=network.target
[Service]
User=root
Group=root
Type=forking
#PIDFile=$CONFIGFOLDER/$COIN_NAME.pid
ExecStart=$COIN_PATH$COIN_DAEMON -daemon -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER
ExecStop=$COIN_PATH$COIN_CLI -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER stop
Restart=always
PrivateTmp=true
TimeoutStopSec=60s
TimeoutStartSec=10s
StartLimitInterval=120s
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
EOF
echo -e "${YELLOW}Reloading systemd...${NC}."
systemctl daemon-reload
sleep 3
echo -e "${YELLOW}Starting up $COIN_NAME service...${NC}."
systemctl start $COIN_NAME.service
systemctl enable $COIN_NAME.service >/dev/null 2>&1
sleep 3
if [[ -z "$(ps axo cmd:100 | egrep $COIN_DAEMON)" ]]; then
echo -e "${RED}$COIN_NAME is not running${NC}, please investigate. You should start by running the following commands as root:"
echo -e "${GREEN}systemctl start $COIN_NAME.service"
echo -e "systemctl status $COIN_NAME.service"
echo -e "less /var/log/syslog${NC}"
exit 1
else
echo -e "${GREEN}$COIN_NAME service started${NC}."
fi
}
function create_config() {
mkdir $CONFIGFOLDER >/dev/null 2>&1
RPCUSER=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w10 | head -n1)
RPCPASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w22 | head -n1)
cat << EOF > $CONFIGFOLDER/$CONFIG_FILE
rpcuser=$RPCUSER
rpcpassword=$RPCPASSWORD
rpcport=$RPC_PORT
rpcallowip=127.0.0.1
listen=1
server=1
daemon=1
port=$COIN_PORT
EOF
}
function create_key() {
echo -e "${YELLOW}Enter your ${RED}$COIN_NAME Masternode GEN Key${NC}."
read -e COINKEY
if [[ -z "$COINKEY" ]]; then
echo -e "${YELLOW}Generating key: starting daemon...${NC}"
$COIN_PATH$COIN_DAEMON -daemon
sleep 10
if [ -z "$(ps axo cmd:100 | grep $COIN_DAEMON)" ]; then
echo -e "${RED}$COIN_NAME server couldn not start. Check /var/log/syslog for errors.{$NC}"
exit 1
fi
COINKEY=$($COIN_PATH$COIN_CLI masternode genkey)
if [ "$?" -gt "0" ]; then
echo -e "${RED}Wallet not fully loaded. Let us wait and try again to generate the GEN Key${NC}"
sleep 20
COINKEY=$($COIN_PATH$COIN_CLI masternode genkey)
fi
$COIN_PATH$COIN_CLI stop
sleep 5
fi
# clear
}
function update_config() {
sed -i 's/daemon=1/daemon=1/' $CONFIGFOLDER/$CONFIG_FILE
cat << EOF >> $CONFIGFOLDER/$CONFIG_FILE
logintimestamps=1
maxconnections=500
bind=$BINDIP
masternode=1
externalip=$NODEIP:$COIN_PORT
masternodeprivkey=$COINKEY
# addnodes
addnode=164.68.110.103:18765
addnode=164.68.111.75:18765
addnode=116.203.156.64:18765
addnode=159.69.190.7:18765
addnode=95.216.164.118:18765
addnode=116.202.26.146:18765
addnode=164.68.106.143:18765
addnode=95.111.226.176:18765
whitelist=185.147.75.96/28
addnode=185.147.75.100
addnode=185.147.75.101
addnode=185.147.75.102
addnode=185.147.75.103
addnode=185.147.75.104
addnode=185.147.75.105
addnode=185.147.75.106
addnode=185.147.75.107
addnode=185.147.75.108
addnode=185.147.75.109
EOF
}
function get_ip() {
declare -a NODE_IPS
for ips in $(netstat -i | awk '!/Kernel|Iface|lo/ {print $1," "}')
do
NODE_IPS+=($(curl --interface $ips --connect-timeout 2 -s4 icanhazip.com))
done
if [ ${#NODE_IPS[@]} -gt 1 ]
then
echo -e "${GREEN}More than one IP. Please type 0 to use the first IP, 1 for the second and so on...${NC}"
INDEX=0
for ip in "${NODE_IPS[@]}"
do
echo ${INDEX} $ip
let INDEX=${INDEX}+1
done
read -e choose_ip
NODEIP=${NODE_IPS[$choose_ip]}
else
NODEIP=${NODE_IPS[0]}
fi
# NODEIP is now the public ip address, if the server is NAT'd, we'll need to bind to a local ip
# (at least give the option)
echo -e "${YELLOW} Bind ip address (enter if host is behind NAT firewall): ${NC}"
read -e BINDIP
if [[ -z "$BINDIP" ]]; then
BINDIP=$NODEIP
fi
}
function checks() {
local LSB_RELEASE=$(lsb_release -d)
if [[ $LSB_RELEASE != *Ubuntu* ]]; then
echo -e "${RED} You are not running Ubuntu, Installation is cancelled.${NC}"
exit 1
fi
if [[ $LSB_RELEASE != *16.04* && $LSB_RELEASE != *18.04* && $LSB_RELEASE != *20.04* ]]; then
echo -e "${RED}You are not running Ubuntu 16.04, 18.04 or 20.04. Installation is cancelled.${NC}"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}$0 must be run as root.${NC}"
exit 1
fi
# removed this check - if the daemon exists, just consider it an upgrade
#if [ -n "$(pidof $COIN_DAEMON)" ] || [ -e "$COIN_DAEMON" ] ; then
# echo -e "${RED}$COIN_NAME is already installed.${NC}"
# exit 1
#fi
}
function prepare_system() {
# this installs the libraries that the binaries need to run
echo -e "Preparing the VPS to setup. ${CYAN}$COIN_NAME${NC} ${RED}Masternode${NC}"
apt-get update >/dev/null 2>&1
DEBIAN_FRONTEND=noninteractive apt-get update > /dev/null 2>&1
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y -qq upgrade >/dev/null 2>&1
echo -e "Installing required packages, it may take some time to finish.${NC}"
apt-get update >/dev/null 2>&1
apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" make software-properties-common \
build-essential libtool autoconf libssl-dev libboost-dev automake git wget curl libdb-dev bsdmainutils libdb++-dev \
libminiupnpc-dev libgmp3-dev pkg-config libevent-dev unzip >/dev/null 2>&1
if [ "$?" -gt "0" ];
then
echo -e "${RED}Not all required packages were installed properly. Try to install them manually by running the following commands:${NC}\n"
echo "apt-get update"
echo "apt -y install software-properties-common"
echo "apt-add-repository -y ppa:bitcoin/bitcoin"
echo "apt-get update"
echo "apt install -y make build-essential libtool software-properties-common autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev \
libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev sudo automake git curl libdb4.8-dev \
bsdmainutils libdb4.8++-dev libminiupnpc-dev libgmp3-dev ufw pkg-config libevent-dev libdb5.3++ unzip libzmq5"
exit 1
fi
# clear
}
function important_information() {
echo
echo -e "$COIN_NAME Masternode is up and running listening on port ${GREEN}$COIN_PORT${NC}."
echo -e "Configuration file is: ${RED}$CONFIGFOLDER/$CONFIG_FILE${NC}"
echo -e "Start: ${RED}systemctl start $COIN_NAME.service${NC}"
echo -e "Stop: ${RED}systemctl stop $COIN_NAME.service${NC}"
echo -e "VPS_IP:PORT ${GREEN}$NODEIP:$COIN_PORT${NC}"
echo -e "MASTERNODE GENKEY is: ${RED}$COINKEY${NC}"
echo -e "Please check ${RED}$COIN_NAME${NC} is running with the following command: ${RED}systemctl status $COIN_NAME.service${NC}"
echo -e "Use ${RED}$COIN_CLI masternode status${NC} to check your MN."
if [[ -n $SENTINEL_REPO ]]; then
echo -e "${RED}Sentinel${NC} is installed in ${RED}/root/sentinel_$COIN_NAME${NC}"
echo -e "Sentinel logs is: ${RED}$CONFIGFOLDER/sentinel.log${NC}"
fi
}
function create_swap() {
echo -e "${YELLOW} Checking if swap is needed...${NC}"
PHYMEM=$(free -g|awk '/^Mem:/{print $2}')
SWAP=$(swapon -s)
if [[ "$PHYMEM" -lt "2" && -z "$SWAP" ]]
then
echo -e "${GREEN}Server is running with less than 2G of RAM without SWAP, creating 2G swap file.${NC}"
SWAPFILE=$(mktemp)
dd if=/dev/zero of=$SWAPFILE bs=1024 count=2M
chmod 600 $SWAPFILE
mkswap $SWAPFILE
swapon -a $SWAPFILE
else
echo -e "${GREEN}The server running with at least 2G of RAM, or a SWAP file is already in place.${NC}"
fi
# clear
}
function isUpgrade() {
if [ -e $COIN_PATH/$COIN_DAEMON ]
then
# its already here, make sure its not running
echo -e "${YELLOW}$COIN_PATH$COIN_DAEMON already installed, doing an upgrade...${NC}"
if pgrep -x $COIN_DAEMON >/dev/null
then
# stop the daemon from running
echo -e "${YELLOW}Shutting down daemon...${NC}"
systemctl stop $COIN_NAME.service
sleep 10
fi
return 1
else
return 0
fi
}
function upgrade_node() {
# make sure daemon is stopped (it should already be, but this wont hurt)
echo -e "${YELLOW} Making sure daemon is stopped...${NC}"
systemctl stop $COIN_NAME.service
sleep 5
# make copy of old binaries
echo -e "${YELLOW} Backing up existing binaries...${NC}"
cp $COIN_PATH/$COIN_CLI $COIN_PATH/$COIN_CLI~
cp $COIN_PATH/$COIN_DAEMON $COIN_PATH/$COIN_DAEMON~
# copy in new binaries
echo -e "${YELLOW} Pulling new binaries...${NC}"
download_node
# start daemon
echo -e "${YELLOW} Restarting daemon...${NC}"
systemctl start $COIN_NAME.service
sleep 5
}
function setup_node() {
get_ip
create_config
create_key
update_config
# enable_firewall
configure_systemd
important_information
}
##### Main #####
clear
checks
isUpgrade
if [ $? -eq 1 ]
then
# this is an upgrade and deamon should not be running (isUpgrade stops it)
upgrade_node
echo -e "${GREEN}Upgrade complete! Please check masternode status/version to verify ${NC}"
else
prepare_system
create_swap
download_node
setup_node
fi