forked from BitSavage0202/NodeBaseCoin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
263 lines (225 loc) · 7.86 KB
/
setup.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
# Color config
BLUE='\033[1;34m'
CLEAR='\033[0m'
DARK='\033[2m'
GREEN='\033[1;32m'
GREY='\033[36m'
NC='\033[0m'
RED='\033[1;31m'
WHITE='\033[1;39m'
# Configure
TMP_FOLDER=$(mktemp -d)
NODEIP=$(curl -s4 api.ipify.org)
function download_node() {
echo -e ":: Downloading coin ${GREEN}nodebase${NC}..."
cd $TMP_FOLDER >/dev/null 2>&1
wget -q https://github.com/Hamdiovish/NodeBaseCoin/releases/download/v1.0.2/nodebased
compile_error
echo -e ":: Moving coin..."
chmod +x nodebased
mv nodebased /usr/local/bin/
cd - >/dev/null 2>&1
rm -rf $TMP_FOLDER >/dev/null 2>&1
}
function download_node_cli() {
echo -e ":: Downloading coin cli ${GREEN}nodebase${NC}..."
cd $TMP_FOLDER >/dev/null 2>&1
wget -q https://github.com/Hamdiovish/NodeBaseCoin/releases/download/v1.0.2/nodebase-cli
compile_error
echo -e ":: Moving coin-cli..."
chmod +x nodebase-cli
mv nodebase-cli /usr/local/bin/
cd - >/dev/null 2>&1
rm -rf $TMP_FOLDER >/dev/null 2>&1
}
function configure_systemd() {
cat << EOF > /etc/systemd/system/nodebase.service
[Unit]
Description=nodebase service
After=network.target
[Service]
User=root
Group=root
Type=forking
#PIDFile=/root/.nodebase/nodebase.pid
ExecStart=/usr/local/bin/nodebased -daemon -conf=/root/.nodebase/nodebase.conf -datadir=/root/.nodebase
ExecStop=-/usr/local/bin/nodebase-cli -conf=/root/.nodebase/nodebase.conf -datadir=/root/.nodebase stop
Restart=always
PrivateTmp=true
TimeoutStopSec=60s
TimeoutStartSec=10s
StartLimitInterval=120s
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
sleep 3
systemctl start nodebase.service
systemctl enable nodebase.service >/dev/null 2>&1
if [[ -z "$(ps axo cmd:100 | egrep nodebased)" ]]; then
echo -e "${RED}nodebase is not running${NC}, please investigate. You should start by running the following commands as root:"
echo -e "${GREEN}systemctl start nodebase.service"
echo -e "systemctl status nodebase.service"
echo -e "less /var/log/syslog${NC}"
exit 1
fi
}
function create_config() {
mkdir /root/.nodebase >/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 > /root/.nodebase/nodebase.conf
rpcuser=init
rpcpassword=init
#rpcport=22002
rpcallowip=127.0.0.1
listen=1
server=1
daemon=1
port=22001
EOF
}
function create_key() {
echo -e "${WHITE}:: Enter your nodebase Masternode Private Key${CLEAR}:"
echo -e "${GREY} Leave it blank to generate a new Masternode Private Key for you.${CLEAR}"
echo -n " "
read -t 5 -e COINKEY
if [[ -z "$COINKEY" ]]; then
/usr/local/bin/nodebased -daemon
sleep 30
if [ -z "$(ps axo cmd:100 | grep nodebased)" ]; then
echo -e "${RED}:: nodebase service failed to start. Review journalctl for errors.{$NC}"
exit 1
fi
COINKEY=$(/usr/local/bin/nodebase-cli masternode genkey)
if [ "$?" -gt "0" ];
then
echo -e "${RED}:: Wallet yet to fully load. Waiting 30s before trying again...${NC}"
sleep 30
COINKEY=$(/usr/local/bin/nodebase-cli masternode genkey)
fi
/usr/local/bin/nodebase-cli stop
fi
}
function update_config() {
sed -i 's/daemon=1/daemon=0/' /root/.nodebase/nodebase.conf
cat << EOF >> /root/.nodebase/nodebase.conf
logintimestamps=1
maxconnections=256
#bind=$NODEIP
masternode=1
externalip=$NODEIP:22001
masternodeprivkey=init
addnode=206.189.166.205:22001
addnode=206.189.208.80:22001
EOF
}
function enable_firewall() {
echo -e ":: Configuring firewall to allow access via port ${GREEN}22001${NC}"
ufw allow 22001/tcp comment "nodebase MN port" >/dev/null
ufw allow ssh comment "SSH" >/dev/null 2>&1
ufw limit ssh/tcp >/dev/null 2>&1
ufw default allow outgoing >/dev/null 2>&1
echo "y" | ufw enable >/dev/null 2>&1
}
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 api.ipify.org))
done
if [ ${#NODE_IPS[@]} -gt 1 ]
then
echo -e "${GREEN}:: This machine has more than one IP address. 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}
let INDEX=${INDEX}+1
done
read -e choose_ip
NODEIP=${NODE_IPS[$choose_ip]}
else
NODEIP=${NODE_IPS[0]}
fi
}
function compile_error() {
if [ "$?" -gt "0" ];
then
echo -e "${RED}:: Unable to retrieve binaries for nodebase - URL invalid${NC}"
exit 1
fi
}
function checks() {
if [[ $(lsb_release -d) != *16.04* ]]; then
echo -e "${RED}:: This server is not running Ubuntu 16.04 - aborting setup${NC}"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}:: Must run as root user - aborting setup${NC}"
exit 1
fi
if [ -n "$(pidof nodebased)" ] || [ -e "" ] ; then
echo -e "${RED}:: nodebase is already installed - aborting setup${NC}"
exit 1
fi
}
function prepare_system() {
echo -e ":: Preparing to install ${GREEN}nodebase${NC} master node..."
echo -e ":: Updating system..."
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
apt install -y software-properties-common >/dev/null 2>&1
echo -e ":: Adding bitcoin repository..."
apt-add-repository -y ppa:bitcoin/bitcoin >/dev/null 2>&1
echo -e ":: Installing build packages (this could take some time)..."
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 libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev sudo automake git wget curl libdb4.8-dev bsdmainutils libdb4.8++-dev libminiupnpc-dev libgmp3-dev ufw pkg-config libevent-dev unzip libzmq5 >/dev/null 2>&1
if [ "$?" -gt "0" ];
then
echo -e "${RED}:: Not all required packages were installed properly. Try installing these manually using the following command:${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 unzip libzmq5"
exit 1
fi
}
function important_information() {
clear
echo -e "nodebase Masternode Successfully Set up!"
echo -e "${GREY}--------${CLEAR}"
echo -e "Service running on: ${GREEN}$NODEIP:22001${NC}."
echo -e "Configuration file path: ${GREEN}/root/.nodebase/nodebase.conf${NC}"
echo -e "Private key: ${GREEN}$COINKEY${NC}"
echo -e "To start, run: ${GREEN}systemctl start nodebase.service${NC}"
echo -e "To stop, run: ${GREEN}systemctl stop nodebase.service${NC}"
echo
echo -e "Run ${GREEN}systemctl status nodebase${CLEAR} to check service status"
echo -e "Run ${GREEN}nodebase-cli masternode status${NC} to check your masternode"
if [[ -n $SENTINEL_REPO ]]; then
echo -e "${RED}Sentinel${NC} is installed in ${RED}/root/.nodebase/sentinel${NC}"
echo -e "Sentinel logs is: ${RED}/root/.nodebase/sentinel.log${NC}"
fi
echo
echo -e "YourNodePro\n \ ${GREEN}discord.gg/7v5qzJu${CLEAR}\n \ ${GREEN}facebook.com/yournodepro${CLEAR}\n \ ${GREEN}twitter.com/YourNodePro${CLEAR}"
}
function setup_node() {
get_ip
create_config
create_key
update_config
enable_firewall
important_information
configure_systemd
}
##### Main #####
clear
checks
prepare_system
download_node
download_node_cli
setup_node