This repository has been archived by the owner on Dec 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
install_masternode.sh
200 lines (176 loc) · 6 KB
/
install_masternode.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
#/bin/bash
clear
cd ~
echo "*************************************************************************"
echo "* Ubuntu 16.04 is the recommended opearting system for this install. *"
echo "* *"
echo "* This script will install and configure your polis masternode *"
echo "* v1.2.1 *"
echo "*************************************************************************"
echo && echo && echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! !"
echo "! Make sure you double check before hitting enter !"
echo "! !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo && echo && echo
sleep 3
# Check for systemd
systemctl --version >/dev/null 2>&1 || { echo "systemd is required. Are you using Ubuntu 16.04?" >&2; exit 1; }
# Gather input from user
read -e -p "Masternode Private Key (e.g. 31o6u1Ga4WxFog2b8QP9bQMrfbUtRj2tSk7sZVM9sryvQHamkyM) : " key
if [[ "$key" == "" ]]; then
echo "WARNING: No private key entered, exiting!!!"
echo && exit
fi
read -e -p "Server IP Address : " ip
echo && echo "Pressing ENTER will use the default value for the next prompts."
echo && sleep 3
read -e -p "Add swap space? (Recommended) [Y/n] : " add_swap
if [[ ("$add_swap" == "y" || "$add_swap" == "Y" || "$add_swap" == "") ]]; then
read -e -p "Swap Size [2G] : " swap_size
if [[ "$swap_size" == "" ]]; then
swap_size="2G"
fi
fi
read -e -p "Install Fail2ban? (Recommended) [Y/n] : " install_fail2ban
read -e -p "Install UFW and configure ports? (Recommended) [Y/n] : " UFW
# Add swap if needed
if [[ ("$add_swap" == "y" || "$add_swap" == "Y" || "$add_swap" == "") ]]; then
if [ ! -f /swapfile ]; then
echo && echo "Adding swap space..."
sleep 3
sudo fallocate -l $swap_size /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
else
echo && echo "WARNING: Swap file detected, skipping add swap!"
sleep 3
fi
fi
# Update system
echo && echo "Upgrading system..."
echo
sleep 3
sudo apt-get -y update
sudo apt-get -y upgrade
# Add Berkely PPA
echo && echo "Installing bitcoin PPA..."
echo
sleep 3
sudo apt-get -y install software-properties-common
sudo apt-add-repository -y ppa:bitcoin/bitcoin
sudo apt-get -y update
# Install required packages
echo && echo "Installing base packages and dependencies..."
echo
sleep 3
sudo apt-get -y install \
wget \
git \
unzip \
monit \
libevent-dev \
libboost-dev \
libboost-chrono-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-system-dev \
libboost-test-dev \
libboost-thread-dev \
libdb4.8-dev \
libdb4.8++-dev \
libminiupnpc-dev \
build-essential \
libtool \
autotools-dev \
automake \
pkg-config \
libssl-dev \
libevent-dev \
bsdmainutils \
libzmq3-dev
# Install fail2ban if needed
if [[ ("$install_fail2ban" == "y" || "$install_fail2ban" == "Y" || "$install_fail2ban" == "") ]]; then
echo && echo "Installing fail2ban (intrusion prevention software that protects computer servers from brute-force attacks)..."
echo
sleep 3
sudo apt-get -y install fail2ban
sudo service fail2ban restart
fi
# Install firewall if needed
if [[ ("$UFW" == "y" || "$UFW" == "Y" || "$UFW" == "") ]]; then
echo && echo "Installing UFW (Uncomplicated Firewall)..."
echo
sleep 3
sudo apt-get -y install ufw
echo && echo "Configuring UFW..."
sleep 3
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 24126/tcp
sudo ufw enable
echo && echo "Firewall installed and enabled!"
fi
# Download polis
echo && echo "Downloading polis v1.2.1..."
echo
sleep 3
wget https://github.com/polispay/polis/releases/download/v1.2.1/poliscore-1.2.1-linux64.tar.gz
# Install polis
echo && echo "Installing poliscore-1.2.1..."
echo
sleep 3
tar -xzvf ~/poliscore-1.2.1-linux64.tar.gz
sudo cp ~/poliscore-1.2.1/bin/polis{d,-cli} /usr/bin
rm -R ~/poliscore-1.2.1-linux64.tar.gz ~/poliscore-1.2.1-linux64.tar.gz
# Create config for poliscore
echo && echo "Configuring poliscore-1.2.1..."
echo
sleep 3
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`
mkdir -p /home/masternode/.poliscore
touch /home/masternode/.poliscore/polis.conf
echo '
rpcuser='$rpcuser'
rpcpassword='$rpcpassword'
rpcallowip=127.0.0.1
listen=1
server=1
logtimestamps=1
maxconnections=256
externalip='$ip'
masternodeprivkey='$key'
masternode=1
' | tee /home/masternode/.poliscore/polis.conf
# start polisd
polisd -daemon
# Download and install sentinel
echo && echo "Installing Sentinel..."
echo
sleep 3
sudo apt-get -y install virtualenv python-pip
git clone https://github.com/polispay/sentinel /home/masternode/sentinel
cd /home/masternode/sentinel
virtualenv venv
. venv/bin/activate
pip install -r requirements.txt
export EDITOR=nano
(crontab -l -u masternode 2>/dev/null; echo '* * * * * cd /home/masternode/sentinel && ./venv/bin/python bin/sentinel.py >/dev/null 2>&1') | sudo crontab -u masternode -
cd ~
# Configuring monit
wget https://raw.githubusercontent.com/digitalmine/Guide/master/polis_node.sh
chmod u+x polis_node.sh
# Add alias to run polis-cli
#echo && echo "Masternode setup complete!"
#touch ~/.bash_aliases
#echo "alias polis-cli='polis-cli -conf=/home/masternode/.poliscore/polis.conf -datadir=/home/masternode/.poliscore'" | tee -a ~/.bash_aliases
#echo && echo "Now run 'source ~/.bash_aliases' (without quotes) to use polis-cli"