-
Notifications
You must be signed in to change notification settings - Fork 13
/
etny-node-installer.sh
executable file
·488 lines (454 loc) · 18.8 KB
/
etny-node-installer.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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#!/bin/bash
requiredkernelversion="5.13.0-40"
nodefolder=$(pwd)
configfile="config"
rebootfile="/tmp/reboot"
service="etny-vagrant.service"
os=""
if [ "$1" == "-v" ]
then
ansible_cmd="ansible-playbook -v"
else
ansible_cmd="ansible-playbook"
fi
choose_network() {
echo "#############################################"
echo "Please select the network:"
echo "1. Automatic"
echo " The node will run only on one of the network where it has gas."
echo " The priority order of the networks are: Polygon Mainnet, bloxberg Mainnet"
echo "2. Polygon Mainnet (ECLD)"
echo "3. Polygon Testnet (tECLD)"
echo "4. bloxberg Mainnet (ETNY)"
echo "5. bloxberg Testnet (tETNY)"
echo "6. Quit"
echo "#############################################"
while true; do
read -p "Enter your choice: " choice
case $choice in
1) # Check Ubuntu kernel version
if [ "$os" != 'Ubuntu 20.04' ] && [ "$os" != 'Ubuntu 22.04' ]; then
echo "You need to upgrade your Ubuntu OS to at least version 20.04 or 22.04 to proceed with the installation."
exit 1
fi
echo "You selected Automatic. This option will set polygon Mainnet if your wallet has MATIC, otherwise will set bloxberg Mainnet."
export NETWORK=AUTO
read -p "Do you want to use the default RPC? [Y/n]: " use_default_rpc
use_default_rpc=${use_default_rpc:-Y}
if [[ "$use_default_rpc" =~ ^[Nn]$ ]]; then
read -p "Enter your custom RPC for Bloxberg: " custom_bloxberg_rpc
export BLOXBERG_RPC_URL=$custom_bloxberg_rpc
read -p "Enter your custom RPC for Polygon: " custom_polygon_rpc
export POLYGON_RPC_URL=$custom_polygon_rpc
else
echo "Using default RPC settings."
export BLOXBERG_RPC_URL=https://bloxberg.ethernity.cloud
export POLYGON_RPC_URL=https://polygon-rpc.com
fi
break
;;
2) # Check Ubuntu kernel version
if [ "$os" != 'Ubuntu 20.04' ] && [ "$os" != 'Ubuntu 22.04' ]; then
echo "You need to upgrade your Ubuntu OS to at least version 20.04 or 22.04 to proceed with the installation."
exit 1
fi
echo "You selected Mainnet on POLYGON."
export NETWORK=POLYGON
read -p "Do you want to use the default POLYGON RPC? [Y/n]: " use_default_rpc
use_default_rpc=${use_default_rpc:-Y}
if [[ "$use_default_rpc" =~ ^[Nn]$ ]]; then
read -p "Enter your custom RPC for Polygon: " custom_polygon_rpc
export POLYGON_RPC_URL=$custom_polygon_rpc
else
echo "Using default RPC settings."
export POLYGON_RPC_URL=https://polygon-rpc.com
fi
break
;;
3) # Check Ubuntu kernel version
if [ "$os" != 'Ubuntu 20.04' ] && [ "$os" != 'Ubuntu 22.04' ]; then
echo "You need to upgrade your Ubuntu OS to at least version 20.04 or 22.04 to proceed with the installation."
exit 1
fi
echo "You selected Open Beta."
export NETWORK=AMOY
read -p "Do you want to use the default AMOY RPC? [Y/n]: " use_default_rpc
use_default_rpc=${use_default_rpc:-Y}
if [[ "$use_default_rpc" =~ ^[Nn]$ ]]; then
read -p "Enter your custom RPC for Polygon: " custom_amoy_rpc
export AMOY_RPC_URL=$custom_amoy_rpc
else
echo "Using default RPC settings."
export AMOY_RPC_URL=https://rpc-amoy.polygon.technology
fi
break
;;
4) # Check Ubuntu kernel version
if [ "$os" != 'Ubuntu 20.04' ] && [ "$os" != 'Ubuntu 22.04' ]; then
echo "You need to upgrade your Ubuntu OS to at least version 20.04 or 22.04 to proceed with the installation."
exit 1
fi
echo "You selected Open Beta."
export NETWORK=BLOXBERG
read -p "Do you want to use the default Bloxberg RPC? [Y/n]: " use_default_rpc
use_default_rpc=${use_default_rpc:-Y}
if [[ "$use_default_rpc" =~ ^[Nn]$ ]]; then
read -p "Enter your custom RPC for Bloxberg: " custom_bloxberg_rpc
export BLOXBERG_RPC_URL=$custom_bloxberg_rpc
else
echo "Using default RPC settings."
export BLOXBERG_RPC_URL=https://bloxberg.ethernity.cloud
fi
break
;;
5)
echo "You selected Testnet."
export NETWORK=TESTNET
read -p "Do you want to use the default TESTNET RPC? [Y/n]: " use_default_rpc
use_default_rpc=${use_default_rpc:-Y}
if [[ "$use_default_rpc" =~ ^[Nn]$ ]]; then
read -p "Enter your custom RPC for TESTNET: " custom_testnet_rpc
export TESTNET_RPC_URL=$custom_testnet_rpc
else
echo "Using default RPC settings."
export TESTNET_RPC_URL=https://bloxberg.ethernity.cloud
fi
break
;;
6)
echo "Quitting..."
exit 0
;;
*)
echo "Invalid choice. Please select a valid option."
;;
esac
done
}
task_price_check() {
current_price=$(grep "TASK_EXECUTION_PRICE" "$nodefolder/$configfile" | cut -d'=' -f2)
if [ "$current_price" != "" ];
then
echo "Task execution price already exists in the config file and is currently set to $current_price ETNY/hour."
export TASK_EXECUTION_PRICE=$current_price
echo "Would you like to modify it? (y/N)"
read modify
if [[ "$modify" =~ ^[Yy]$ ]]; then
set_task_price
fi
else
echo "The TASK_EXECUTION_PRICE is not set in the config file."
echo "Do you want to use the default value of 3 ETNY/hour? (Y/n)"
read -r use_default
if [[ -z "$use_default" ]] || [[ "$use_default" =~ ^[Yy]$ ]]; then
default_price=3
export TASK_EXECUTION_PRICE=$default_price
else
set_task_price
fi
fi
}
set_task_price() {
while true; do
echo -n "Enter the Task Execution Price (Recommended price for executing a task/hour: 1 - 10 ETNY): "
read taskprice
if [[ $taskprice =~ ^[1-9]$|^10$ ]]; then
break
else
echo "Invalid task execution price. Please enter a valid integer price within the recommended range (1 - 10 ETNY)..."
fi
done
export TASK_EXECUTION_PRICE=$taskprice
}
ubuntu_20_04() {
# Determining if the etny-vagrant service is running
echo "$os found. Continuing..."
choose_network
task_price_check
echo "#############################################"
echo "Finding out if etny-vagrant service is already running..."
systemctl status "$service" 2>/dev/null | grep "active (running)" >/dev/null
if [ $? -eq 0 ]; then
echo "The service is currently running."
read -p "Would you like to stop the service? (Y/n) " choice
choice="${choice:-Y}" # Set the default value to "Y" if the input is empty
if [[ "$choice" =~ ^[Yy]$ ]]; then
echo "Stopping the service..."
# Stop the service here
systemctl stop "$service"
ubuntu_20_04_kernel_check
else
echo "The service is currently running. Setup aborted."
exit 1
fi
else
echo "The service is not running."
ubuntu_20_04_kernel_check
fi
}
qemu_hold(){
apt-mark hold qemu-system-common
apt-mark hold qemu-system-data
apt-mark hold qemu-system-x86
apt-mark hold qemu-utils
}
qemu_unhold(){
apt-mark unhold qemu-system-common
apt-mark unhold qemu-system-data
apt-mark unhold qemu-system-x86
apt-mark unhold qemu-utils
}
check_config_file() {
if [ -f "$configfile" ]; then
echo "Config file found. Checking configuration"
missing_informations=()
if ! grep -q "^ADDRESS=0x[[:xdigit:]]\{40\}$" "$configfile"; then
missing_informations+=("ADDRESS")
fi
if ! grep -q "^PRIVATE_KEY=.\{64\}$" "$configfile"; then
missing_informations+=("PRIVATE_KEY")
fi
if ! grep -q "^RESULT_PRIVATE_KEY=.\{64\}$" "$configfile"; then
missing_informations+=("RESULT_PRIVATE_KEY")
fi
if ! grep -q "^RESULT_ADDRESS=0x[[:xdigit:]]\{40\}$" "$configfile"; then
missing_informations+=("RESULT_ADDRESS")
fi
if [ ${#missing_informations[@]} -eq 0 ]; then
address=$(grep "^ADDRESS=" "$configfile" | cut -d'=' -f2)
private_key=$(grep "^PRIVATE_KEY=" "$configfile" | cut -d'=' -f2)
result_private_key=$(grep "^RESULT_PRIVATE_KEY=" "$configfile" | cut -d'=' -f2)
result_address=$(grep "^RESULT_ADDRESS=" "$configfile" | cut -d'=' -f2)
if [[ $address =~ ^0x[[:xdigit:]]{40}$ && $result_address =~ ^0x[[:xdigit:]]{40}$ && ${#private_key} -eq 64 && ${#result_private_key} -eq 64 ]]; then
echo "Configuration check succesful!"
else
echo "Invalid ADDRESS, RESULT_ADDRESS, PRIVATE_KEY, or RESULT_PRIVATE_KEY format or length in the config file."
echo "Please update the config file with valid information."
exit 1
fi
else
echo "The following informations are missing or not valid in the config file:"
for info in "${missing_informations[@]}"; do
echo "$info"
done
echo "Please update or check the config file."
exit 1
fi
echo "Writing network and price to the config file"
sed -i "/NETWORK/d" "$nodefolder/$configfile"
echo "NETWORK="$NETWORK >> "$nodefolder/$configfile"
sed -i "/TASK_EXECUTION_PRICE/d" "$nodefolder/$configfile"
echo "TASK_EXECUTION_PRICE="$TASK_EXECUTION_PRICE >> "$nodefolder/$configfile"
if [[ ! -z $BLOXBERG_RPC_URL ]]; then
sed -i "/BLOXBERG_RPC_URL/d" "$nodefolder/$configfile"
echo "BLOXBERG_RPC_URL="$BLOXBERG_RPC_URL >> "$nodefolder/$configfile"
fi
if [[ ! -z $TESTNET_RPC_URL ]]; then
sed -i "/TESTNET_RPC_URL/d" "$nodefolder/$configfile"
echo "TESTNET_RPC_URL="$TESTNET_RPC_URL >> "$nodefolder/$configfile"
fi
if [[ ! -z $POLYGON_RPC_URL ]]; then
sed -i "/POLYGON_RPC_URL/d" "$nodefolder/$configfile"
echo "POLYGON_RPC_URL="$POLYGON_RPC_URL >> "$nodefolder/$configfile"
fi
if [[ ! -z $AMOY_RPC_URL ]]; then
sed -i "/AMOY_RPC_URL/d" "$nodefolder/$configfile"
echo "AMOY_RPC_URL="$AMOY_RPC_URL >> "$nodefolder/$configfile"
fi
else
echo "Config file not found. How would you like to continue?"
ubuntu_20_04_config_file_choice
fi
}
check_ansible(){
echo "Check ansible version..."
ANSIBLE_VERSION=`ansible --version 2> /dev/null || echo ""`
if [[ $ANSIBLE_VERSION = "" ]]; then echo "Installing latest ansible version..." && sudo apt-add-repository --yes --update ppa:ansible/ansible && sudo apt update && sudo apt -y install software-properties-common ansible; fi
}
is_miminum_kernel_version(){
#returning true or false if we have the minimum required kernel version for Ubuntu 20.04
version=`uname -r` && currentver=${version%-*}
if [ "$(printf '%s\n' "$requiredkernelversion" "$currentver" | sort -V | head -n1)" = "$requiredkernelversion" ]; then echo true ; else echo false; fi
}
ubuntu_20_04_kernel_check(){
#if we have the right kernel then we run the ansible-playbook and finish installation
echo "Determining if the right kernel is running..."
if [[ ( "$(is_miminum_kernel_version)" = true && $os = "Ubuntu 20.04" ) || ( $(uname -r) = "5.0.0-050000-generic" && $os = "Ubuntu 18.04") || ( "$(is_miminum_kernel_version)" = true && $os = "Ubuntu 22.04" )]]
then
echo "The right kernel is running. Continuing setup..."
## check ansible
check_ansible
check_config_file
echo "Running ansible-playbook script..."
HOME=/root
qemu_unhold
sudo -E $ansible_cmd -i localhost, playbook.yml -e "ansible_python_interpreter=/usr/bin/python3"
install_result=$?
if [ -f $rebootfile ]
then
echo "Restarting system. Please run the installer script afterwards to continue the setup."
sec=30
while [ $sec -ge 0 ]; do echo -n "Restarting system in [CTRL+C to cancel]: " && echo -ne "$sec\033[0K\r" && let "sec=sec-1" && sleep 1; done
sudo reboot
else
if [ $install_result == 0 ]
then
qemu_hold
echo "Node installation completed successfully. Please allow up to 24h to see transactions on the blockchain. " && exit
else
echo "Node installation failed! Please check error messages above." && exit
fi
fi
else
check_config_file
ubuntu_20_04_update_ansible
fi
}
ubuntu_20_04_config_file_choice(){
#if the config file doesn't exist we offer the either generate one with random wallets or we get the wallets from input
echo "1) Type wallets. "
echo "2) Generate random wallets... "
echo "3) Exit. Rerun the script when config file exists..."
echo -n "[Type your choice to continue]:" && read choice
case "$choice" in
1)
echo "Type/Paste wallet details below..."
nodeaddr=("Node Address: " "Node Private Key: " "Result Address: " "Result Private Key: ")
IFS=""
for address in ${nodeaddr[@]}; do
case $address in
${nodeaddr[0]})
while true
do
echo -n $address && read nodeaddress
if [[ $nodeaddress = "" ]]; then echo "Node address cannot be empty."; else break; fi
done;;
${nodeaddr[2]})
while true
do
echo -n $address && read resultaddress
if [[ $nodeaddress = $resultaddress ]]
then
echo "Result address must be different than the node address. Try a different address..."
else break
fi
done;;
${nodeaddr[1]})
while true
do
echo -n $address && read nodeprivatekey
if [[ ${#nodeprivatekey} = 64 && $nodeprivatekey =~ ^[a-zA-Z0-9]*$ ]]
then
break
else echo "Invalid result private key. Please try again..."
fi
done;;
${nodeaddr[3]})
while true
do
echo -n $address && read resultprivatekey
if [[ ${#resultprivatekey} = 64 && $resultprivatekey =~ ^[a-zA-Z0-9]*$ ]]
then
if [[ $nodeprivatekey = $resultprivatekey ]]
then
echo "Result private key must be different than the node private key. Try a different private key..."
else
break
fi
else echo "Invalid result private key. Please try again..."
fi
done;;
esac
done
echo "ADDRESS="$nodeaddress >> $nodefolder/$configfile
echo "PRIVATE_KEY="$nodeprivatekey >> $nodefolder/$configfile
echo "RESULT_ADDRESS="$resultaddress >> $nodefolder/$configfile
echo "RESULT_PRIVATE_KEY="$resultprivatekey >> $nodefolder/$configfile
echo "NETWORK="$NETWORK >> $nodefolder/$configfile
echo "TASK_EXECUTION_PRICE="$TASK_EXECUTION_PRICE >> $nodefolder/$configfile
if [[ ! -z $BLOXBERG_RPC_URL ]]; then
echo "BLOXBERG_RPC_URL=$BLOXBERG_RPC_URL" >> $nodefolder/$configfile
fi
if [[ ! -z $POLYGON_RPC_URL ]]; then
echo "POLYGON_RPC_URL=$POLYGON_RPC_URL" >> $nodefolder/$configfile
fi
if [[ ! -z $TESTNET_RPC_URL ]]; then
echo "TESTNET_RPC_URL=$TESTNET_RPC_URL" >> $nodefolder/$configfile
fi
if [[ ! -z $AMOY_RPC_URL ]]; then
echo "AMOY_RPC_URL=$AMOY_RPC_URL" >> $nodefolder/$configfile
fi
if [ -f $nodefolder/$configfile ]; then echo "Config file generated successfully. Continuing..."; else echo "Something went wrong. Seek Help!" && exit; fi
;;
2)
export FILE=generate
check_ansible
ubuntu_20_04_ansible_playbook;;
3) echo "Exiting..." && exit;;
*) echo "Invalid choice. Please choose an option below..." && ubuntu_20_04_config_file_choice;;
esac
}
ubuntu_20_04_ansible_playbook(){
#running the ansible-playbook command and restart system automatically
echo "Running ansible-playbook..."
cd && cd $nodefolder
HOME=/root
sudo -E $ansible_cmd -i localhost, playbook.yml -e "ansible_python_interpreter=/usr/bin/python3"
install_result=$?
if [ -f $rebootfile ]
then
echo "Restarting system. Please run the installer script afterwards to continue the setup."
sec=30
while [ $sec -ge 0 ]; do echo -n "Restarting system in [CTRL+C to cancel]: " && echo -ne "$sec\033[0K\r" && let "sec=sec-1" && sleep 1; done
sudo reboot
else
if [ $install_result == 0 ]
then
echo "Node installation completed successfully. Please allow up to 24h to see transactions on the blockchain. " && exit
else
echo "Node installation failed! Please check error messages above." && exit
fi
fi
}
ubuntu_20_04_update_ansible(){
#If we don't have the right kernel running that means we didn't update the system
echo "We don't have the right kernel running."
echo "Updating system, kernel and installing ansible..."
sudo sudo apt-add-repository --yes --update ppa:ansible/ansible && sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt -y install software-properties-common ansible
if [ $? -eq 0 ]
then
echo "Update successfull. Continuing..."
ubuntu_20_04_ansible_playbook
fi
}
ubuntu(){
#Getting which version of Ubuntu is instaled
echo "Ubuntu OS found. Determining version..."
case $(awk '/^VERSION_ID=/' /etc/*-release 2>/dev/null | awk -F'=' '{ print tolower($2) }' | tr -d '"') in
20.04)
os='Ubuntu 20.04'
ubuntu_20_04;;
18.04)
os='Ubuntu 18.04'
ubuntu_20_04;;
22.04)
os='Ubuntu 22.04'
ubuntu_20_04;;
*) echo "Version not supported. Exiting..."
esac
}
start(){
#getting which Linux distribution is installed
echo "Getting distro..."
case $(awk '/^ID=/' /etc/*-release 2>/dev/null | awk -F'=' '{ print tolower($2) }' | tr -d '"') in
ubuntu) ubuntu;;
# debian) echo "debian distro Found. Not Supported. Exiting...";;
# centos) echo "centos distro Found. Not Supported. Exiting...";;
# manjaro) echo "manjaro distro Found. Not Supported. Exiting...";;
# arch) echo "arch distro Found. Not Supported. Exiting...";;
# rhel) echo "red hat distro Found. Not Supported. Exiting...";;
# fedora) echo "fedora distro Found. Not Supported. Exiting...";;
*) echo "Could not determine Distro. Exiting..."
esac
}
start