forked from WebDollar/Node-WebDollar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-fullnode.sh
executable file
·414 lines (310 loc) · 19.5 KB
/
start-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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#!/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"
terminalconn="$yellow[TERMINAL_CONNECTIONS]$stand"
browserconn="$yellow[BROWSER_CONNECTIONS]$stand"
ports="$yellow[PORTS]$stand"
##
### General VARS
fullnode_conf="../.fullnodeconf"
###
#### 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
### START_NODE_PM2_START
function start_node_pm2(){
if [[ $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showinfo We are inside a ${yellow}Node-WebDollar$stand Folder"
read -r -e -p "$showinput Do you want to start a pm2 instance in this ${yellow}$(pwd)$stand foler? (y or n): " startnodeyn
if [[ "$startnodeyn" =~ ^(y|yes|Y|YES|Yes)$ ]]; then
MAXIMUM_CONNECTIONS_FROM_BROWSER=$get_browser_conn MAXIMUM_CONNECTIONS_FROM_TERMINAL=$get_term_conn SERVER_PORT=$readport pm2 start npm -- run start
sleep 1;
pm2 restart npm --name "$readport" --update-env
sleep 3;
echo "$showinfo Run ${white}pm2 log $readport$stand to check if the blockchain is loading."
elif [[ "$startnodeyn" =~ ^(n|no|N|NO|No)$ ]]; then
echo "$showinfo Ok. Bye."
exit 0
elif [[ "$startnodeyn" == "" ]]; then
echo "$showerror Empty space is not an option."
if [[ $nrofports == 1 ]]; then f_oneport; elif [[ $nrofports == 2 ]]; then f_twoports; elif [[ $nrofports == 3 ]]; then f_threeports; elif [[ $nrofports == 4 ]]; then f_fourports; elif [[ $nrofports == 5 ]]; then f_fiveports; elif [[ $nrofports == 6 ]]; then f_sixports; fi
elif [[ "$startnodeyn" == * ]]; then
echo "$showerror Wrong option."
if [[ $nrofports == 1 ]]; then f_oneport; elif [[ $nrofports == 2 ]]; then f_twoports; elif [[ $nrofports == 3 ]]; then f_threeports; elif [[ $nrofports == 4 ]]; then f_fourports; elif [[ $nrofports == 5 ]]; then f_fiveports; elif [[ $nrofports == 6 ]]; then f_sixports; 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 "---Choose where to run PM2 instance\\n${cyan}$(ls -d -1 "$PWD"/** | grep 'Node-WebDollar')$stand\\n---"
read -r -e -p "$showinput Enter the full location of the Node-WebDollar folder where you want to start the pm2 instance: " nodewebdloc
if [[ -d $nodewebdloc ]]; then
if cd "$nodewebdloc"; then echo "$showinfo Changing DIR to $yellow$(pwd)$stand"; else echo "$showerror Couldn't change DIR to $nodewebdloc"; fi
echo "$showinfo Folder location changed to $nodewebdloc"
MAXIMUM_CONNECTIONS_FROM_BROWSER=$get_browser_conn MAXIMUM_CONNECTIONS_FROM_TERMINAL=$get_term_conn SERVER_PORT=$readport pm2 start npm -- run start
sleep 1;
pm2 restart npm --name "$readport" --update-env
sleep 3;
echo "$showinfo Run ${white}pm2 log $readport$stand to check if the blockchain is loading."
else
if [[ ! -d $nodewebdloc ]]; then
echo "$showerror Folder location does not exist! Try again."
if [[ $nrofports == 1 ]]; then f_oneport; elif [[ $nrofports == 2 ]]; then f_twoports; elif [[ $nrofports == 3 ]]; then f_threeports; elif [[ $nrofports == 4 ]]; then f_fourports; elif [[ $nrofports == 5 ]]; then f_fiveports; elif [[ $nrofports == 6 ]]; then f_sixports; fi
fi
fi
fi
fi
} ### START_NODE_PM2_END
### START_NODE_SCREEN_START
function start_node_screen(){
if [[ $(cat package.json | grep "name" | sed s'/[",]//g' | awk '{print $2}') == node-webdollar ]]; then
echo "$showinfo We are inside a ${yellow}Node-WebDollar$stand Folder"
read -r -e -p "$showinput Do you want to start a SCREEN instance in this ${yellow}$(pwd)$stand foler? (y or n): " startnodeyn
if [[ "$startnodeyn" =~ ^(y|yes|Y|YES|Yes)$ ]]; then
echo "$showexecute Starting SCREEN Daemon for PORT=${green}$readport$stand" && screen -dmS $readport
echo "$showexecute Seding command to start NPM inside SCREEN..." && screen -S $readport -p 0 -X stuff "MAXIMUM_CONNECTIONS_FROM_BROWSER=$get_browser_conn MAXIMUM_CONNECTIONS_FROM_TERMINAL=$get_term_conn SERVER_PORT=$readport npm run start^M"
sleep 1;
elif [[ "$startnodeyn" =~ ^(n|no|N|NO|No)$ ]]; then
echo "$showinfo Ok. Bye."
exit 0
elif [[ "$startnodeyn" == "" ]]; then
echo "$showerror Empty space is not an option."
if [[ $nrofports == 1 ]]; then f_oneport; elif [[ $nrofports == 2 ]]; then f_twoports; elif [[ $nrofports == 3 ]]; then f_threeports; elif [[ $nrofports == 4 ]]; then f_fourports; elif [[ $nrofports == 5 ]]; then f_fiveports; elif [[ $nrofports == 6 ]]; then f_sixports; fi
elif [[ "$startnodeyn" == * ]]; then
echo "$showerror Wrong option."
if [[ $nrofports == 1 ]]; then f_oneport; elif [[ $nrofports == 2 ]]; then f_twoports; elif [[ $nrofports == 3 ]]; then f_threeports; elif [[ $nrofports == 4 ]]; then f_fourports; elif [[ $nrofports == 5 ]]; then f_fiveports; elif [[ $nrofports == 6 ]]; then f_sixports; 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 "---Choose where to run SCREEN instance\\n${cyan}$(ls -d -1 "$PWD"/** | grep 'Node-WebDollar')$stand\\n---"
read -r -e -p "$showinput Enter the full location of the Node-WebDollar folder where you want to start the SCREEN instance: " nodewebdloc
if [[ -d $nodewebdloc ]]; then
if cd "$nodewebdloc"; then echo "$showinfo Changing DIR to $yellow$(pwd)$stand"; else echo "$showerror Couldn't change DIR to $nodewebdloc"; fi
echo "$showinfo Folder location changed to $nodewebdloc"
echo "$showexecute Starting SCREEN Daemon for PORT=$green$readport$stand" && screen -dmS $readport
echo "$showexecute Seding command to start NPM inside SCREEN..." && screen -S $readport -p 0 -X stuff "MAXIMUM_CONNECTIONS_FROM_BROWSER=$get_browser_conn MAXIMUM_CONNECTIONS_FROM_TERMINAL=$get_term_conn SERVER_PORT=$readport npm run start^M"
sleep 1;
else
if [[ ! -d $nodewebdloc ]]; then
echo "$showerror Folder location does not exist! Try again."
if [[ $nrofports == 1 ]]; then f_oneport; elif [[ $nrofports == 2 ]]; then f_twoports; elif [[ $nrofports == 3 ]]; then f_threeports; elif [[ $nrofports == 4 ]]; then f_fourports; elif [[ $nrofports == 5 ]]; then f_fiveports; elif [[ $nrofports == 6 ]]; then f_sixports; fi
fi
fi
fi
fi
} ### START_NODE_SCREEN_END
if [[ -s $fullnode_conf ]]; then
### VARS
get_term_conn=$(grep TERM_CONN $fullnode_conf | cut -d '=' -f2)
get_browser_conn=$(grep BROWSER_CONN $fullnode_conf | cut -d '=' -f2)
###
echo "$showok FULLNODE_CONF found! TERM_CONN=${green}$get_term_conn$stand | BROWSER_CONN=${green}$get_browser_conn$stand"
read -r -e -p "$showinput How many $ports to you want to use for the full node (1,2,3,4,5 and 10 or $abortte): " nrofports
echo -e "${yellow}1. Use PM2 instances\\n2. Use SCREEN instances$stand"
read -r -e -p "$showinput Choose: " set_instance
else
if [[ ! -s $fullnode_conf ]]; then
echo "$showerror FULLNODE_CONF not found! Starting config..."
read -r -e -p "$showinput How many $terminalconn do you want to offer (e.g.: 350 or $abortte): " readtermconn # this is a max_term_connections global setting that will apply for every pm2 instance.
### Catch user input before anything - readtermconn
if [[ "$readtermconn" =~ ^[[:digit:]]+$ ]]; then
read -r -e -p "$showinput How many $browserconn do you want to offer (e.g.: 250 or $abortte): " readbrowserconn # if termconn is set ok, proceed to nr of browser_conn input # this is a max_browser_connections global setting that will apply for every pm2 instance.
### Catch user input before anything - readbrowserconn
if [[ "$readbrowserconn" =~ ^[[:digit:]]+$ ]]; then
echo -e "TERM_CONN=$readtermconn\\nBROWSER_CONN=$readbrowserconn" > $fullnode_conf
echo "$showok FULLNODE_CONF saved to $fullnode_conf"
read -r -e -p "$showinput How many $ports to you want to use for the full node (1,2,3,4,5 and 10 or $abortte): " nrofports # if browser_conn is set ok, proceed to number of ports to be used
echo -e "${yellow}1. Use PM2 instances\\n2. Use SCREEN instances$stand"
read -r -e -p "$showinput Choose: " set_instance
elif [[ "$readbrowserconn" == "" ]]; then
echo "$showerror No empty space allowed."
exit 1
elif [[ "$readbrowserconn" == abort ]]; then
echo "$showinfo Okay. Bye."
exit 0
elif [[ "$readbrowserconn" == * ]]; then
echo "$showerror Please enter how many connections you'll give for $browserconn"
exit 1
fi
elif [[ "$readtermconn" == "" ]]; then
echo "$showerror No empty space allowed."
exit 1
elif [[ "$readtermconn" == abort ]]; then
echo "$showinfo Okay. Bye."
exit 0
elif [[ "$readtermconn" == * ]]; then
echo "$showerror Please enter how many connections you'll give for $terminalconn"
exit 1
fi
fi
fi
### Start process
### Catch user input before anything - nrofports
if [[ "$nrofports" =~ ^[[:digit:]]+$ ]]; then
if [[ "$nrofports" == 1 ]];then
function f_oneport(){
read -r -e -p "$showinput We'll use ${green}$nrofports$stand port. Enter PORT number (e.g.: 8080 or $abortte): " readport
if [[ "$readport" =~ ^[[:digit:]]+$ ]]; then
echo "$showinfo Setting IP Table rule for PORT ${green}$readport$stand"
if [[ $(sudo iptables -nL | grep -w "$readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$readport" ]]; then echo "$showok Port $readport is already accepted in Firewall!"; elif [[ ! $(sudo iptables -nL | grep -w "$readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$readport" ]]; then echo "$showdone Setting Firewall rule for PORT $readport."; sudo iptables -A INPUT -p tcp --dport "$readport" -j ACCEPT; fi # set port firewall rule
echo "$showinfo The system will use port $readport"
if [[ $set_instance == 1 ]]; then start_node_pm2; elif [[ $set_instance == 2 ]]; then start_node_screen; elif [[ $set_instance == * ]]; then echo "$showerror Enter 1 or 2."; fi
elif [[ "$readport" == abort ]]; then
echo "$showinfo Ok. Bye." && exit 0
else
echo "$showerror Please enter a PORT number."
f_oneport
fi
}
f_oneport # function for one port
elif [[ "$nrofports" == 2 ]];then
function f_twoports(){
read -r -e -p "$showinput We'll use ${green}$nrofports$stand ports. Enter PORT number (e.g.: 8080 8081): " readnrport2_0 readnrport2_1
if [[ $readnrport2_0 =~ ^[[:digit:]]+$ && $readnrport2_1 =~ ^[[:digit:]]+$ ]]; then
echo "$showinfo The system will use $nrofports ports -> $readnrport2_0 and $readnrport2_1"
for fw_readport in $readnrport2_0 $readnrport2_1;
do
if [[ $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showok Port $fw_readport is already accepted in Firewall!"; elif [[ ! $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showdone Setting Firewall rule for PORT $fw_readport."; sudo iptables -A INPUT -p tcp --dport "$fw_readport" -j ACCEPT; fi # set port firewall rule
done
for readport in $readnrport2_0 $readnrport2_1;
do
if [[ $set_instance == 1 ]]; then start_node_pm2; elif [[ $set_instance == 2 ]]; then start_node_screen; elif [[ $set_instance == * ]]; then echo "$showerror Enter 1 or 2."; fi
cd ..
done
else
echo "$showerror Please enter $nrofports PORT numbers."
f_twoports
fi
}
f_twoports # function for two ports
elif [[ "$nrofports" == 3 ]];then
function f_threeports(){
read -r -e -p "$showinput We'll use ${green}$nrofports$stand ports. Enter PORT number (e.g.: 8080 8081 8082): " readnrport3_0 readnrport3_1 readnrport3_2
if [[ $readnrport3_0 =~ ^[[:digit:]]+$ && $readnrport3_1 =~ ^[[:digit:]]+$ && $readnrport3_2 =~ ^[[:digit:]]+$ ]]; then
echo "$showinfo The system will use three ports -> $readnrport3_0, $readnrport3_1 and $readnrport3_2"
for fw_readport in $readnrport3_0 $readnrport3_1 $readnrport3_2;
do
if [[ $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showok Port $fw_readport is already accepted in Firewall!"; elif [[ ! $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showdone Setting Firewall rule for PORT $fw_readport."; sudo iptables -A INPUT -p tcp --dport "$fw_readport" -j ACCEPT; fi # set port firewall rule
done
for readport in $readnrport3_0 $readnrport3_1 $readnrport3_2;
do
if [[ $set_instance == 1 ]]; then start_node_pm2; elif [[ $set_instance == 2 ]]; then start_node_screen; elif [[ $set_instance == * ]]; then echo "$showerror Enter 1 or 2."; fi
cd ..
done
else
echo "$showerror Please enter $nrofports PORT numbers."
f_threeports
fi
}
f_threeports # function three ports
elif [[ "$nrofports" == 4 ]];then
function f_fourports(){
read -r -e -p "$showinput We'll use ${green}$nrofports$stand ports. Enter PORT number (e.g.: 8080 8081 8082 8083): " readnrport4_0 readnrport4_1 readnrport4_2 readnrport4_3
if [[ $readnrport4_0 =~ ^[[:digit:]]+$ && $readnrport4_1 =~ ^[[:digit:]]+$ && $readnrport4_2 =~ ^[[:digit:]]+$ && $readnrport4_3 =~ ^[[:digit:]]+$ ]]; then
echo "$showinfo The system will use $nrofports ports -> $readnrport4_0, $readnrport4_1, $readnrport4_2, $readnrport4_3"
for fw_readport in $readnrport4_0 $readnrport4_1 $readnrport4_2 $readnrport4_3;
do
if [[ $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showok Port $fw_readport is already accepted in Firewall!"; elif [[ ! $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showdone Setting Firewall rule for PORT $fw_readport."; sudo iptables -A INPUT -p tcp --dport "$fw_readport" -j ACCEPT; fi # set port firewall rule
done
for readport in $readnrport4_0 $readnrport4_1 $readnrport4_2 $readnrport4_3;
do
if [[ $set_instance == 1 ]]; then start_node_pm2; elif [[ $set_instance == 2 ]]; then start_node_screen; elif [[ $set_instance == * ]]; then echo "$showerror Enter 1 or 2."; fi
cd ..
done
else
echo "$showerror Please enter $nrofports PORT numbers."
f_fourports
fi
}
f_fourports # function four ports
elif [[ "$nrofports" == 5 ]];then
function f_fiveports(){
read -r -e -p "$showinput We'll use ${green}$nrofports$stand ports. Enter PORT number (e.g.: 8080 8081 8082 8083 8084): " readnrport5_0 readnrport5_1 readnrport5_2 readnrport5_3 readnrport5_4
if [[ $readnrport5_0 =~ ^[[:digit:]]+$ && $readnrport5_1 =~ ^[[:digit:]]+$ && $readnrport5_2 =~ ^[[:digit:]]+$ && $readnrport5_3 =~ ^[[:digit:]]+$ && $readnrport5_4 =~ ^[[:digit:]]+$ ]]; then
echo "$showinfo The system will use $nrofports ports -> $readnrport5_0, $readnrport5_1, $readnrport5_2, $readnrport5_3 and $readnrport5_4"
for fw_readport in $readnrport5_0 $readnrport5_1 $readnrport5_2 $readnrport5_3 $readnrport5_4;
do
if [[ $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showok Port $fw_readport is already accepted in Firewall!"; elif [[ ! $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showdone Setting Firewall rule for PORT $fw_readport."; sudo iptables -A INPUT -p tcp --dport "$fw_readport" -j ACCEPT; fi # set port firewall rule
done
for readport in $readnrport5_0 $readnrport5_1 $readnrport5_2 $readnrport5_3 $readnrport5_4;
do
if [[ $set_instance == 1 ]]; then start_node_pm2; elif [[ $set_instance == 2 ]]; then start_node_screen; elif [[ $set_instance == * ]]; then echo "$showerror Enter 1 or 2."; fi
cd ..
done
else
echo "$showerror Please enter $nrofports PORT numbers."
f_fiveports
fi
}
f_fiveports # function five ports
elif [[ "$nrofports" == 10 ]];then
function f_tenports(){
read -r -e -p "$showinput We'll use ${green}$nrofports$stand ports. Enter PORT number (e.g.: 8080 8081 8082 8083 8084 8085 etc): " readnrport10_0 readnrport10_1 readnrport10_2 readnrport10_3 readnrport10_4 readnrport10_5 readnrport10_6 readnrport10_7 readnrport10_8 readnrport10_9
#if [[ $readnrport10_0 =~ ^[[:digit:]]+$ && $readnrport10_1 =~ ^[[:digit:]]+$ && $readnrport10_2 =~ ^[[:digit:]]+$ && $readnrport10_3 =~ ^[[:digit:]]+$ && $readnrport10_4 =~ ^[[:digit:]]+$ && $readnrport10_5 =~ ^[[:digit:]]+$ && $readnrport10_6 =~ ^[[:digit:]]+$ && $readnrport10_7 =~ ^[[:digit:]]+$ && $readnrport10_8 =~ ^[[:digit:]]+$ && $readnrport10_9 =~ ^[[:digit:]]+$ ]]; then
echo "$showinfo The system will use $nrofports ports -> $readnrport10_0, $readnrport10_1, $readnrport10_2, $readnrport10_3,$readnrport10_4, $readnrport10_5, $readnrport10_6, $readnrport10_7, $readnrport10_8 and $readnrport10_9"
for fw_readport in $readnrport10_0 $readnrport10_1 $readnrport10_2 $readnrport10_3 $readnrport10_4 $readnrport10_5 $readnrport10_6 $readnrport10_7 $readnrport10_8 $readnrport10_9;
do
if [[ $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showok Port $fw_readport is already accepted in Firewall!"; elif [[ ! $(sudo iptables -nL | grep -w "$fw_readport" | awk 'NR==1{print$7}' | cut -d ':' -f2) == "$fw_readport" ]]; then echo "$showdone Setting Firewall rule for PORT $fw_readport."; sudo iptables -A INPUT -p tcp --dport "$fw_readport" -j ACCEPT; fi # set port firewall rule
done
for readport in $readnrport10_0 $readnrport10_1 $readnrport10_2 $readnrport10_3 $readnrport10_4 $readnrport10_5 $readnrport10_6 $readnrport10_7 $readnrport10_8 $readnrport10_9;
do
if [[ $set_instance == 1 ]]; then start_node_pm2; elif [[ $set_instance == 2 ]]; then start_node_screen; elif [[ $set_instance == * ]]; then echo "$showerror Enter 1 or 2."; fi
cd ..
done
#else
# echo "$showerror Please enter $nrofports PORT numbers."
# f_tenports
#fi
}
f_tenports # function ten ports
elif [[ "$nrofports" -gt 5 ]]; then
echo "$showerror Sorry, max number of ports can be: 1,2,3,4,5 and 10."
echo "$showinfo You can always run the script again with a new set of ports."
exit 1
fi
elif [[ "$nrofports" == "" ]]; then
echo "$showerror No empty space allowed."
exit 1
elif [[ "$nrofports" == abort ]]; then
echo "$showinfo Okay. Bye."
exit 0
elif [[ "$nrofports" == * ]]; then
echo "$showerror Please enter a number from 1 to 5 or 10."
exit 1
fi
if cat /etc/*release | grep -q -o -m 1 Ubuntu; then sudo iptables-save; elif cat /etc/*release | grep -q -o -m 1 Debian; then sudo iptables-save; fi