forked from WebDollar/Node-WebDollar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-fullnode.sh
executable file
·344 lines (255 loc) · 14.4 KB
/
install-fullnode.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
#!/bin/bash
#### COLOR SETTINGS ####
black=$(tput setaf 0 && tput bold)
red=$(tput setaf 1 && tput bold)
green=$(tput setaf 2 && tput bold)
yellow=$(tput setaf 3 && tput bold)
blue=$(tput setaf 4 && tput bold)
magenta=$(tput setaf 5 && tput bold)
cyan=$(tput setaf 6 && tput bold)
white=$(tput setaf 7 && tput bold)
blackbg=$(tput setab 0 && tput bold)
redbg=$(tput setab 1 && tput bold)
greenbg=$(tput setab 2 && tput bold)
yellowbg=$(tput setab 3 && tput bold)
bluebg=$(tput setab 4 && tput dim)
magentabg=$(tput setab 5 && tput bold)
cyanbg=$(tput setab 6 && tput bold)
whitebg=$(tput setab 7 && tput bold)
stand=$(tput sgr0)
### System dialog VARS
showinfo="$green[info]$stand"
showerror="$red[error]$stand"
showexecute="$yellow[running]$stand"
showok="$magenta[OK]$stand"
showdone="$blue[DONE]$stand"
showinput="$cyan[input]$stand"
showwarning="$red[warning]$stand"
showremove="$green[removing]$stand"
shownone="$magenta[none]$stand"
redhashtag="$redbg$white#$stand"
abortte="$cyan[abort to Exit]$stand"
showport="$yellow[PORT]$stand"
##
#### ROOT User Check
function checkroot(){
if [[ $(id -u) = 0 ]]; then
echo -e "$showinfo Checking for ROOT: ${green}PASSED${stand}"
else
echo -e "$showinfo Checking for ROOT: $showerror\\n${red}This Script Needs To Run Under ROOT user!${stand}"
exit 0
fi
}
####
#checkroot
### GENERAL VARS
getiptpersist=$(if cat /etc/*release | grep -q -o -m 1 Ubuntu; then echo "$(sudo apt-cache policy iptables-persistent | grep Installed | grep none | awk '{print$2}' | sed s'/[()]//g')"; elif cat /etc/*release | grep -q -o -m 1 Debian; then echo "$(sudo apt-cache policy iptables-persistent | grep Installed | grep none | awk '{print$2}' | sed s'/[()]//g')"; elif cat /etc/*release | grep -q -o -m 1 centos; then echo "NA"; fi)
getgit=$(if cat /etc/*release | grep -q -o -m 1 Ubuntu; then echo "$(sudo apt-cache policy git | grep Installed | grep none | awk '{print$2}' | sed s'/[()]//g')"; elif cat /etc/*release | grep -q -o -m 1 Debian; then echo "$(sudo apt-cache policy git | grep Installed | grep none | awk '{print$2}' | sed s'/[()]//g')"; elif cat /etc/*release | grep -q -o -m 1 centos; then echo "$(if yum list git | grep -q -o "Available Packages"; then echo "none"; else echo "Installed"; fi)"; fi)
###
#### Dependencies START
function deps() {
if [[ "$getiptpersist" == "none" ]]; then
echo "$showinfo We need to install IPtables Persistent"
echo "$showinfo When asked, press YES to save your current IPtables settings."
echo "$showinfo IPtables Persistent keeps your IPT rules after a REBOOT."
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y iptables-persistent; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y iptables-persistent; fi
else
if [[ "$getiptpersist" == NA ]]; then
echo "$showok IPtables Persistent is not available for CentOS"
else
if [[ "$getiptpersist" == * ]]; then
echo "$showok IPtables Persistent is already installed!"
fi
fi
fi
if [[ "$getgit" == "none" ]]; then
echo "$showinfo We need to install Git"
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y git; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y git; elif cat /etc/*release | grep -q -o -m 1 centos; then yum install -y git; fi
else
if [[ "$getgit" == Installed ]]; then
echo "$showok Git is already installed!"
elif [[ "$getgit" == * ]]; then
echo "$showok Git is already installed!"
fi
fi
}
#### Dependencies check END
deps # call deps function
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt update -y; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get update -y; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum update -y; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt upgrade -y; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get upgrade -y; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum upgrade -y; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y linuxbrew-wrapper; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y linuxbrew-wrapper; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y build-essential; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y build-essential; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum group install -y "Development Tools"; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo apt install -y clang; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo apt-get install -y clang; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo yum install -y clang; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then if [[ -d $HOME/.nvm ]]; then echo "$showok NVM is already installed!"; elif [[ ! -d $HOME/.nvm ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && source ~/.profile && nvm install 8.2.1 && nvm use 8.2.1 && nvm alias default 8.2.1; fi \
elif cat /etc/*release | grep -q -o -m 1 Debian; then if [[ -d $HOME/.nvm ]]; then echo "$showok NVM is already installed!"; elif [[ ! -d $HOME/.nvm ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && source ~/.profile && nvm install 8.2.1 && nvm use 8.2.1 && nvm alias default 8.2.1; fi \
elif cat /etc/*release | grep -q -o -m 1 centos; then if [[ -d $HOME/.nvm ]]; then echo "$showok NVM is already installed!"; elif [[ ! -d $HOME/.nvm ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash && export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && source ~/.bash_profile && nvm install 8.2.1 && nvm use 8.2.1 && nvm alias default 8.2.1; fi fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo npm install -g node-gyp; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo npm install -g node-gyp; elif cat /etc/*release | grep -q -o -m 1 centos; then npm install -g node-gyp; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo npm install pm2 -g --unsafe-perm; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo npm install pm2 -g --unsafe-perm; elif cat /etc/*release | grep -q -o -m 1 centos; then sudo npm install pm2 -g --unsafe-perm ; fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then if [[ $(node --version) ]]; then echo "$showok NVM sourced ok..."; else echo "$showinfo ${red}MANDATORY$stand: execute ${yellow}source ~/.profile$stand"; fi elif cat /etc/*release | grep -q -o -m 1 Debian; then if [[ $(node --version) ]]; then echo "$showok NVM sourced ok..."; else echo "$showinfo ${red}MANDATORY$stand: execute ${yellow}source ~/.profile$stand"; fi elif cat /etc/*release | grep -q -o -m 1 centos; then if [[ $(node --version) ]]; then echo "$showok NVM sourced ok..."; else echo "$showinfo ${red}MANDATORY$stand: execute ${yellow}source ~/.bash_profile$stand"; fi fi
function ftconfig()
{
echo -e "-----\\n${white}1. First time config - Create a WebDollar Full Node\\n2. Deploy clean WebDollar Full Nodes\\n3. Clone WebDollar Node \\n4. Exit$stand"
read -r -e -p "$showinput Choose option: " readft ### Ask if this is the first time node configuration
if [[ "$readft" == 1 ]]; then
echo "$redhashtag If you will use more than one PORT (80, 8080 etc), please note that it's better to create multiple Node-WebDollar folders. $redhashtag"
echo "$redhashtag This way you can backup and restore the blockchainDB3 and deploy new PORTS whenever you want. $redhashtag"
read -r -e -p "$showinput How many nodes do you want to deploy? " readnrofnodes ### How many nodes will the user deploy
if [[ "$readnrofnodes" == 0 ]]; then
echo "$showerror You can't deploy 0 WebDollar Nodes."
ftconfig
elif [[ "$readnrofnodes" == "" ]]; then
echo "$showerror Empty space is not a number."
ftconfig
elif [[ "$readnrofnodes" =~ ^[[:digit:]]+$ ]]; then
for ((nodes=1; nodes<=readnrofnodes; nodes++));
do
if [[ ! -d Node-WebDollar1 ]]; then
git clone https://github.com/WebDollar/Node-WebDollar.git Node-WebDollar$nodes
cd Node-WebDollar$nodes && npm install && cd ..
echo "$showok Node-WebDollar$nodes Deployed successfully!"
else
echo "$showwarning Node-WebDollar1 is already deployed!"
fi
done
elif [[ "$readnrofnodes" == * ]]; then
echo "$showerror Only numbers are accepted."
ftconfig
fi
echo "$showinfo Don't forget to FORWARD PORTS on your router!"
echo "$showinfo Now you may run sudo bash node-start.sh"
elif [[ "$readft" == 2 ]]; then
function f_addmorenodes(){
read -r -e -p "$showinfo Would you like to deploy more Nodes?(y or n): " readdeploy
if [[ "$readdeploy" =~ ^(y|yes|Y|YES|Yes)$ ]]; then
read -r -e -p "$showinfo How many Nodes do you want to deploy? " readnrofnodesdeploy
if [[ "$readnrofnodesdeploy" =~ ^[[:digit:]]+$ ]]; then
echo "$showexecute Deploying $readnrofnodesdeploy Nodes..."
echo "$showinfo Current directory is $(pwd)"
crnt_dir=$(pwd)
countcurrentnodes=$(sudo find / -name "Node-WebDollar[0-9]" | wc -l)
# countcurrentnodes="7" # this is for testing purposes only
if [[ $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showinfo We are inside a Node-WebDollar Folder"
cd .. && echo "$showinfo Location changed to $(pwd)"
for ((i=countcurrentnodes+1; i<=countcurrentnodes+readnrofnodesdeploy; i++));
do
git clone https://github.com/WebDollar/Node-WebDollar.git Node-WebDollar$i
cd Node-WebDollar$i && npm install && cd ..
echo "$showok Node-WebDollar$i Deployed successfully!"
done
else
if [[ ! $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showok We are outside of a Node-WebDollar Folder"
for ((i=countcurrentnodes+1; i<=countcurrentnodes+readnrofnodesdeploy; i++));
do
git clone https://github.com/WebDollar/Node-WebDollar.git Node-WebDollar$i
cd Node-WebDollar$i && npm install && if cd "$crnt_dir"; then echo "$showinfo Current DIR changed to $(pwd)"; else echo "$showerror Couldn't change DIR to $crnt_dir!"; fi
echo "$showok Node-WebDollar$i Deployed successfully!"
done
fi
fi
elif [[ "$readnrofnodesdeploy" == "" ]]; then
echo "$showerror Empty space is not an option."
f_addmorenodes
elif [[ "$readnrofnodesdeploy" == abort ]]; then
echo "$showinfo Okay. Bye."
exit 0
elif [[ "$readnrofnodesdeploy" == * ]]; then
echo "$showerror Only numbers are accepted."
f_addmorenodes
fi
elif [[ "$readdeploy" =~ ^(n|no|N|NO|No)$ ]]; then
echo "$showinfo Ok. Bye."
exit 0
elif [[ "$readdeploy" == "" ]]; then
echo "$showerror Empty space is not an option."
f_addmorenodes
elif [[ "$readdeploy" == * ]]; then
echo "$showerror Enter y or n."
f_addmorenodes
fi
}
f_addmorenodes # deploy more clean nodes function
elif [[ "$readft" == 3 ]]; then
function f_clonewebdnode(){
read -r -e -p "$showinfo Would you like to Clone a WebDollar Node?(y or n) " clonewebdnode
if [[ "$clonewebdnode" =~ ^(y|yes|Y|YES|Yes)$ ]]; then
read -r -e -p "$showinfo How many Nodes do you want to Clone? " deployclones
echo "$showinfo Proceeding with WebDollar Node Cloning so you can use it on another $showport"
if [[ "$deployclones" =~ ^[[:digit:]]+$ ]]; then
echo "$showexecute Deploying $deployclones Nodes..."
echo "$showinfo Current directory is $(pwd)"
crnt_dir=$(pwd)
countcurrentnodes=$(sudo find / -name "Node-WebDollar[0-9]" | wc -l)
# countcurrentnodes="7" # this is for testing purposes only
if [[ $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showinfo We are inside a Node-WebDollar Folder"
cd .. && echo "$showinfo Location changed to $(pwd)"
echo -e "---\\n${cyan}$(ls)$stand\\n---"
read -r -e -p "$showinput Enter the full location for the Node-WebDollar you want to clone: " nodewebdloc
if [[ -d $nodewebdloc ]]; then
echo "$showinfo Entered folder location $showok"
for ((i=countcurrentnodes+1; i<=countcurrentnodes+deployclones; i++));
do
cp -r "$nodewebdloc" Node-WebDollar$i
ls -la Node-WebDollar$i
echo "$showok Node-WebDollar$i Deployed successfully @ $nodewebdloc/Node-WebDollar$i!"
done
else
if [[ ! -d $nodewebdloc ]]; then
echo "$showerror Folder location does not exist! Try again."
f_clonewebdnode
fi
fi
else
if [[ ! $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showok We are outside of a Node-WebDollar Folder"
echo -e "---\\n${cyan}$(ls)$stand\\n---"
read -r -e -p "$showinput Enter the full location for the Node-WebDollar you want to clone: " nodewebdloc
if [[ -d $nodewebdloc ]]; then
echo "$showinfo Folder location $showok"
for ((i=countcurrentnodes+1; i<=countcurrentnodes+deployclones; i++));
do
cp -r "$nodewebdloc" Node-WebDollar$i
ls -la Node-WebDollar$i
echo "$showok Node-WebDollar$i Deployed successfully @ $nodewebdloc/Node-WebDollar$i!"
done
else
if [[ ! -d $nodewebdloc ]]; then
echo "$showerror Folder location does not exist! Try again."
f_clonewebdnode
fi
fi
fi
fi
elif [[ "$deployclones" == "" ]]; then
echo "$showerror Empty space is not an option."
f_clonewebdnode
elif [[ "$deployclones" == abort ]]; then
echo "$showinfo Okay. Bye."
exit 0
elif [[ "$deployclones" == * ]]; then
echo "$showerror Only numbers are accepted."
f_clonewebdnode
fi
elif [[ "$clonewebdnode" =~ ^(n|no|N|NO|No)$ ]]; then
echo "$showinfo Ok. Bye."
exit 0
elif [[ "$clonewebdnode" == "" ]]; then
echo "$showerror Empty space is not an option."
f_clonewebdnode
elif [[ "$clonewebdnode" == * ]]; then
echo "$showerror Wrong option."
f_clonewebdnode
fi
}
f_clonewebdnode # node-webdollar clone function
elif [[ "$readft" =~ ^(4|exit)$ ]]; then
echo "$showinfo Okay. Bye."
exit 0
elif [[ "$readft" == * ]]; then
echo "$showerror Wrong option entered."
ftconfig
fi
} # function ftconfig END
ftconfig