-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinstaller.sh
executable file
·703 lines (587 loc) · 21.9 KB
/
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
#!/usr/bin/env bash
set -e
# Get the environment/OS
environment=$(uname)
# Function to exit with an error message
exit_with_error() {
echo "Error: $1"
exit 1
}
# Check the operating system and get the processor information
case "$environment" in
Linux)
processor=$(uname -m)
;;
Darwin)
processor=$(uname -m)
;;
*MINGW*)
exit_with_error "$environment (Windows) environment not yet supported. Please use WSL (WSL2 recommended) or a Linux VM. Exiting installer."
;;
*)
processor="Unknown"
;;
esac
# Check for ARM processor or Unknown and exit if true, meaning the installer is not supported by the processor
if [[ "$processor" == *"arm"* || "$processor" == "Unknown" ]]; then
exit_with_error "$processor not yet supported. Exiting installer."
fi
# Print the detected environment and processor
echo "$environment environment with $processor found."
# Check if any hashing command is available
if ! (command -v openssl > /dev/null || command -v shasum > /dev/null || command -v sha256sum > /dev/null); then
echo "No supported hashing commands found."
read -p "Would you like to install openssl? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Detect package manager and install openssl
if command -v apt-get > /dev/null; then
sudo apt-get update && sudo apt-get install -y openssl
elif command -v yum > /dev/null; then
sudo yum install -y openssl
elif command -v dnf > /dev/null; then
sudo dnf install -y openssl
else
echo "Your package manager is not supported. Please install openssl manually."
exit 1
fi
else
echo "Please install openssl, shasum, or sha256sum and try again."
exit 1
fi
fi
read -p "During this early stage of Betanet the Shardeum team will be collecting some performance and debugging info from your node to help improve future versions of the software.
This is only temporary and will be discontinued as we get closer to mainnet.
Thanks for running a node and helping to make Shardeum better.
By running this installer, you agree to allow the Shardeum team to collect this data. (Y/n)?: " WARNING_AGREE
# Echo user's response, or indicate if no response was provided
if [ -z "$WARNING_AGREE" ]; then
echo "No response provided."
echo "Defaulting to y"
WARNING_AGREE=y
else
echo "You entered: $WARNING_AGREE"
fi
WARNING_AGREE=$(echo "$WARNING_AGREE" | tr '[:upper:]' '[:lower:]')
if [ $WARNING_AGREE != "y" ];
then
echo "Diagnostic data collection agreement not accepted. Exiting installer."
exit
fi
read -p "What base directory should the node use (default ~/.shardeum): " input
# Set default value if input is empty
input=${input:-~/.shardeum}
# Reprompt if not alphanumeric characters, tilde, forward slash, underscore, period, hyphen, or contains spaces
while [[ ! $input =~ ^[[:alnum:]_.~/-]+$ || $input =~ [[:space:]] ]]; do
echo "Error: The directory name contains invalid characters or spaces."
echo "Allowed characters are alphanumeric characters, tilde (~), forward slash (/), underscore (_), period (.), and hyphen (-)."
read -p "Please enter a valid base directory (default ~/.shardeum): " input
# Set default if input is empty
input=${input:-~/.shardeum}
done
# Echo the final directory used (with ~ if present)
echo "The base directory is set to: $input"
# Expand the tilde (~) using a subshell
expanded_input=$(bash -c "echo $input")
# Create the directory if it doesn't exist
mkdir -p "$expanded_input"
# Get the real (absolute) path of the directory
NODEHOME=$(realpath "$expanded_input")
# Check if realpath was successful
if [[ $? -ne 0 ]]; then
echo "Error: Unable to resolve the real path for '$expanded_input'."
exit 1
fi
echo "Real path for directory is: $NODEHOME"
# Check all things that will be needed for this script to succeed like access to docker and docker-compose
# If any check fails, attempt to install the missing dependency
command -v git >/dev/null 2>&1 || {
echo >&2 "'git' is not installed. Attempting to install git..."
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y git
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y git
else
echo >&2 "Unable to install git. Please install it manually."
exit 1
fi
}
command -v docker >/dev/null 2>&1 || {
echo >&2 "'docker' is not installed. Attempting to install docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
rm get-docker.sh
}
if ! command -v docker-compose &>/dev/null && ! docker --help | grep -q "compose"; then
echo "docker-compose or docker compose is not installed. Attempting to install docker-compose..."
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
# Verify installations
command -v git >/dev/null 2>&1 || { echo >&2 "Failed to install git. Please install it manually."; exit 1; }
command -v docker >/dev/null 2>&1 || { echo >&2 "Failed to install docker. Please install it manually."; exit 1; }
if command -v docker-compose &>/dev/null; then
echo "docker-compose is installed on this machine"
elif docker --help | grep -q "compose"; then
echo "docker compose subcommand is installed on this machine"
else
echo "Failed to install docker-compose. Please install it manually."
exit 1
fi
export DOCKER_DEFAULT_PLATFORM=linux/amd64
docker-safe() {
if ! command -v docker &>/dev/null; then
echo "docker is not installed on this machine"
exit 1
fi
if ! docker $@; then
echo "Trying again with sudo..." >&2
sudo docker $@
fi
}
docker-compose-safe() {
if command -v docker-compose &>/dev/null; then
cmd="docker-compose"
elif docker --help | grep -q "compose"; then
cmd="docker compose"
else
echo "docker-compose or docker compose is not installed on this machine"
exit 1
fi
if ! $cmd $@; then
echo "Trying again with sudo..."
sudo $cmd $@
fi
}
get_ip() {
local ip
if command -v ip >/dev/null; then
ip=$(ip addr show $(ip route | awk '/default/ {print $5}') | awk '/inet/ {print $2}' | cut -d/ -f1 | head -n1)
elif command -v netstat >/dev/null; then
# Get the default route interface
interface=$(netstat -rn | awk '/default/{print $4}' | head -n1)
# Get the IP address for the default interface
ip=$(ifconfig "$interface" | awk '/inet /{print $2}')
else
echo "Error: neither 'ip' nor 'ifconfig' command found. Submit a bug for your OS."
return 1
fi
echo $ip
}
get_external_ip() {
external_ip=''
external_ip=$(curl -s https://api.ipify.org)
if [[ -z "$external_ip" ]]; then
external_ip=$(curl -s http://checkip.dyndns.org | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
fi
if [[ -z "$external_ip" ]]; then
external_ip=$(curl -s http://ipecho.net/plain)
fi
if [[ -z "$external_ip" ]]; then
external_ip=$(curl -s https://icanhazip.com/)
fi
if [[ -z "$external_ip" ]]; then
external_ip=$(curl --header "Host: icanhazip.com" -s 104.18.114.97)
fi
if [[ -z "$external_ip" ]]; then
external_ip=$(get_ip)
if [ $? -eq 0 ]; then
echo "The IP address is: $IP"
else
external_ip="localhost"
fi
fi
echo $external_ip
}
hash_password() {
local input="$1"
local hashed_password
# Try using openssl
if command -v openssl > /dev/null; then
hashed_password=$(echo -n "$input" | openssl dgst -sha256 -r | awk '{print $1}')
echo "$hashed_password"
return 0
fi
# Try using shasum
if command -v shasum > /dev/null; then
hashed_password=$(echo -n "$input" | shasum -a 256 | awk '{print $1}')
echo "$hashed_password"
return 0
fi
# Try using sha256sum
if command -v sha256sum > /dev/null; then
hashed_password=$(echo -n "$input" | sha256sum | awk '{print $1}')
echo "$hashed_password"
return 0
fi
return 1
}
if [[ $(docker-safe info 2>&1) == *"Cannot connect to the Docker daemon"* ]]; then
echo "Docker daemon is not running"
exit 1
else
echo "Docker daemon is running"
fi
CURRENT_DIRECTORY=$(pwd)
# DEFAULT VALUES FOR USER INPUTS
DASHPORT_DEFAULT=8080
EXTERNALIP_DEFAULT=auto
INTERNALIP_DEFAULT=auto
SHMEXT_DEFAULT=9001
SHMINT_DEFAULT=10001
PREVIOUS_PASSWORD=none
GITLAB_IMAGE_NAME="registry.gitlab.com/shardeum/server:latest"
GITHUB_IMAGE_NAME="ghcr.io/shardeum/server:latest"
# Check if container exists with GitLab image
GITLAB_CONTAINER_ID=$(docker-safe ps -qf "ancestor=$GITLAB_IMAGE_NAME")
# Check if container exists with GitHub image
GITHUB_CONTAINER_ID=$(docker-safe ps -qf "ancestor=$GITHUB_IMAGE_NAME")
# Determine action based on found container
if [ ! -z "$GITLAB_CONTAINER_ID" ]; then
echo "Existing GitLab container found. ID: $GITLAB_CONTAINER_ID"
# Perform actions for GitLab container, e.g., copy settings, upgrade
CONTAINER_ID=$GITLAB_CONTAINER_ID
elif [ ! -z "$GITHUB_CONTAINER_ID" ]; then
echo "Existing GitHub container found. ID: $GITHUB_CONTAINER_ID"
# Perform actions for GitHub container, e.g., copy settings, upgrade
CONTAINER_ID=$GITHUB_CONTAINER_ID
else
echo "No existing containers found. Proceeding with fresh installation."
fi
if [ ! -z "${CONTAINER_ID}" ]; then
echo "CONTAINER_ID: ${CONTAINER_ID}"
echo "Existing container found. Reading settings from container."
# Assign output of read_container_settings to variable
if ! ENV_VARS=$(docker inspect --format="{{range .Config.Env}}{{println .}}{{end}}" "$CONTAINER_ID"); then
ENV_VARS=$(sudo docker inspect --format="{{range .Config.Env}}{{println .}}{{end}}" "$CONTAINER_ID")
fi
if ! docker-safe cp "${CONTAINER_ID}:/home/node/app/cli/build/secrets.json" ./; then
echo "Container does not have secrets.json"
else
echo "Reusing secrets.json from container"
fi
# CHECK IF VALIDATOR IS ALREADY RUNNING
set +e
status=$(docker-safe exec "${CONTAINER_ID}" operator-cli status 2>/dev/null)
check=$?
set -e
if [ $check -eq 0 ]; then
# The command ran successfully
status=$(awk '/state:/ {print $2}' <<< $status)
if [ "$status" = "active" ] || [ "$status" = "syncing" ]; then
read -p "Your node is $status and upgrading will cause the node to leave the network unexpectedly and lose the stake amount.
Do you really want to upgrade now (y/N)?" REALLYUPGRADE
REALLYUPGRADE=$(echo "$REALLYUPGRADE" | tr '[:upper:]' '[:lower:]')
REALLYUPGRADE=${REALLYUPGRADE:-n}
if [ "$REALLYUPGRADE" == "n" ]; then
exit 1
fi
else
echo "Validator process is not online"
fi
else
read -p "The installer was unable to determine if the existing node is active.
An active node unexpectedly leaving the network will lose it's stake amount.
Do you really want to upgrade now (y/N)?" REALLYUPGRADE
REALLYUPGRADE=$(echo "$REALLYUPGRADE" | tr '[:upper:]' '[:lower:]')
REALLYUPGRADE=${REALLYUPGRADE:-n}
if [ "$REALLYUPGRADE" == "n" ]; then
exit 1
fi
fi
docker-safe stop "${CONTAINER_ID}"
docker-safe rm "${CONTAINER_ID}"
# UPDATE DEFAULT VALUES WITH SAVED VALUES
DASHPORT_DEFAULT=$(echo $ENV_VARS | grep -oP 'DASHPORT=\K[^ ]+') || DASHPORT_DEFAULT=8080
EXTERNALIP_DEFAULT=$(echo $ENV_VARS | grep -oP 'EXT_IP=\K[^ ]+') || EXTERNALIP_DEFAULT=auto
INTERNALIP_DEFAULT=$(echo $ENV_VARS | grep -oP 'INT_IP=\K[^ ]+') || INTERNALIP_DEFAULT=auto
SHMEXT_DEFAULT=$(echo $ENV_VARS | grep -oP 'SHMEXT=\K[^ ]+') || SHMEXT_DEFAULT=9001
SHMINT_DEFAULT=$(echo $ENV_VARS | grep -oP 'SHMINT=\K[^ ]+') || SHMINT_DEFAULT=10001
PREVIOUS_PASSWORD=$(echo $ENV_VARS | grep -oP 'DASHPASS=\K[^ ]+') || PREVIOUS_PASSWORD=none
elif [ -f NODEHOME/.env ]; then
echo "Existing NODEHOME/.env file found. Reading settings from file."
# Read the NODEHOME/.env file into a variable. Use default installer directory if it exists.
ENV_VARS=$(cat NODEHOME/.env)
# UPDATE DEFAULT VALUES WITH SAVED VALUES
DASHPORT_DEFAULT=$(echo $ENV_VARS | grep -oP 'DASHPORT=\K[^ ]+') || DASHPORT_DEFAULT=8080
EXTERNALIP_DEFAULT=$(echo $ENV_VARS | grep -oP 'EXT_IP=\K[^ ]+') || EXTERNALIP_DEFAULT=auto
INTERNALIP_DEFAULT=$(echo $ENV_VARS | grep -oP 'INT_IP=\K[^ ]+') || INTERNALIP_DEFAULT=auto
SHMEXT_DEFAULT=$(echo $ENV_VARS | grep -oP 'SHMEXT=\K[^ ]+') || SHMEXT_DEFAULT=9001
SHMINT_DEFAULT=$(echo $ENV_VARS | grep -oP 'SHMINT=\K[^ ]+') || SHMINT_DEFAULT=10001
PREVIOUS_PASSWORD=$(echo $ENV_VARS | grep -oP 'DASHPASS=\K[^ ]+') || PREVIOUS_PASSWORD=none
fi
cat << EOF
#########################
# 0. GET INFO FROM USER #
#########################
EOF
read -p "Do you want to run the web based Dashboard? (Y/n): " RUNDASHBOARD
RUNDASHBOARD=$(echo "$RUNDASHBOARD" | tr '[:upper:]' '[:lower:]')
RUNDASHBOARD=${RUNDASHBOARD:-y}
if [ "$PREVIOUS_PASSWORD" != "none" ]; then
read -p "Do you want to change the password for the Dashboard? (y/N): " CHANGEPASSWORD
CHANGEPASSWORD=$(echo "$CHANGEPASSWORD" | tr '[:upper:]' '[:lower:]')
CHANGEPASSWORD=${CHANGEPASSWORD:-n}
else
CHANGEPASSWORD="y"
fi
read_password() {
local CHARCOUNT=0
local PASSWORD=""
while IFS= read -p "$PROMPT" -r -s -n 1 CHAR
do
# Enter - accept password
if [[ $CHAR == $'\0' ]] ; then
break
fi
# Backspace
if [[ $CHAR == $'\177' ]] ; then
if [ $CHARCOUNT -gt 0 ] ; then
CHARCOUNT=$((CHARCOUNT-1))
PROMPT=$'\b \b'
PASSWORD="${PASSWORD%?}"
else
PROMPT=''
fi
else
CHARCOUNT=$((CHARCOUNT+1))
PROMPT='*'
PASSWORD+="$CHAR"
fi
done
echo $PASSWORD
}
if [ "$CHANGEPASSWORD" = "y" ]; then
valid_pass=false
while [ "$valid_pass" = false ] ;
do
echo -n -e "Password requirements: min 8 characters, max 128 characters, at least 1 lower case letter, at least 1 upper case letter, at least 1 number, at least 1 special character !@#$%^&*()_+$ \nSet the password to access the Dashboard:"
DASHPASS=$(read_password)
# Check password length
if (( ${#DASHPASS} < 8 )); then
echo -e "\nInvalid password! Too short.\n"
elif (( ${#DASHPASS} > 128 )); then
echo -e "\nInvalid password! Too long.\n"
# Check for at least one lowercase letter
elif ! [[ "$DASHPASS" =~ [a-z] ]]; then
echo -e "\nInvalid password! Must contain at least one lowercase letter.\n"
# Check for at least one uppercase letter
elif ! [[ "$DASHPASS" =~ [A-Z] ]]; then
echo -e "\nInvalid password! Must contain at least one uppercase letter.\n"
# Check for at least one number
elif ! [[ "$DASHPASS" =~ [0-9] ]]; then
echo -e "\nInvalid password! Must contain at least one number.\n"
# Check for at least one special character
elif ! [[ "$DASHPASS" =~ [!@#$%^\&*()_+$] ]]; then
echo -e "\nInvalid password! Must contain at least one special character !@#$%^&*()_+$.\n"
# Password is valid
else
valid_pass=true
echo "\nPassword set successfully."
fi
done
# Hash the password using the fallback mechanism
DASHPASS=$(hash_password "$DASHPASS")
else
DASHPASS=$PREVIOUS_PASSWORD
if ! [[ $DASHPASS =~ ^[0-9a-f]{64}$ ]]; then
DASHPASS=$(hash_password "$DASHPASS")
fi
fi
if [ -z "$DASHPASS" ]; then
echo -e "\nFailed to hash the password. Please ensure you have openssl"
exit 1
fi
echo # New line after inputs.
# echo "Password saved as:" $DASHPASS #DEBUG: TEST PASSWORD WAS RECORDED AFTER ENTERED.
while :; do
read -p "Enter the port (1025-65536) to access the web based Dashboard (default $DASHPORT_DEFAULT): " DASHPORT
DASHPORT=${DASHPORT:-$DASHPORT_DEFAULT}
[[ $DASHPORT =~ ^[0-9]+$ ]] || { echo "Enter a valid port"; continue; }
if ((DASHPORT >= 1025 && DASHPORT <= 65536)); then
DASHPORT=${DASHPORT:-$DASHPORT_DEFAULT}
break
else
echo "Port out of range, try again"
fi
done
while :; do
read -p "If you wish to set an explicit external IP, enter an IPv4 address (default=$EXTERNALIP_DEFAULT): " EXTERNALIP
EXTERNALIP=${EXTERNALIP:-$EXTERNALIP_DEFAULT}
if [ "$EXTERNALIP" == "auto" ]; then
break
fi
# Use regex to check if the input is a valid IPv4 address
if [[ $EXTERNALIP =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
# Check that each number in the IP address is between 0-255
valid_ip=true
IFS='.' read -ra ip_nums <<< "$EXTERNALIP"
for num in "${ip_nums[@]}"
do
if (( num < 0 || num > 255 )); then
valid_ip=false
fi
done
if [ $valid_ip == true ]; then
break
else
echo "Invalid IPv4 address. Please try again."
fi
else
echo "Invalid IPv4 address. Please try again."
fi
done
while :; do
read -p "If you wish to set an explicit internal IP, enter an IPv4 address (default=$INTERNALIP_DEFAULT): " INTERNALIP
INTERNALIP=${INTERNALIP:-$INTERNALIP_DEFAULT}
if [ "$INTERNALIP" == "auto" ]; then
break
fi
# Use regex to check if the input is a valid IPv4 address
if [[ $INTERNALIP =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
# Check that each number in the IP address is between 0-255
valid_ip=true
IFS='.' read -ra ip_nums <<< "$INTERNALIP"
for num in "${ip_nums[@]}"
do
if (( num < 0 || num > 255 )); then
valid_ip=false
fi
done
if [ $valid_ip == true ]; then
break
else
echo "Invalid IPv4 address. Please try again."
fi
else
echo "Invalid IPv4 address. Please try again."
fi
done
while :; do
echo "To run a validator on the Sphinx network, you will need to open two ports in your firewall."
read -p "This allows p2p communication between nodes. Enter the first port (1025-65536) for p2p communication (default $SHMEXT_DEFAULT): " SHMEXT
SHMEXT=${SHMEXT:-$SHMEXT_DEFAULT}
[[ $SHMEXT =~ ^[0-9]+$ ]] || { echo "Enter a valid port"; continue; }
if ((SHMEXT >= 1025 && SHMEXT <= 65536)); then
SHMEXT=${SHMEXT:-9001}
else
echo "Port out of range, try again"
fi
read -p "Enter the second port (1025-65536) for p2p communication (default $SHMINT_DEFAULT): " SHMINT
SHMINT=${SHMINT:-$SHMINT_DEFAULT}
[[ $SHMINT =~ ^[0-9]+$ ]] || { echo "Enter a valid port"; continue; }
if ((SHMINT >= 1025 && SHMINT <= 65536)); then
SHMINT=${SHMINT:-10001}
break
else
echo "Port out of range, try again"
fi
done
#APPSEEDLIST="archiver-sphinx.shardeum.org"
#APPMONITOR="monitor-sphinx.shardeum.org"
APPMONITOR="34.28.123.3"
RPC_SERVER_URL="https://atomium.shardeum.org"
cat <<EOF
###########################
# 1. Pull Compose Project #
###########################
EOF
if [ -d "$NODEHOME" ]; then
if [ "$NODEHOME" != "$(pwd)" ]; then
echo "Removing existing directory $NODEHOME..."
rm -rf "$NODEHOME"
else
echo "Cannot delete current working directory. Please move to another directory and try again."
fi
fi
git clone https://github.com/shardeum/validator-dashboard.git ${NODEHOME} || { echo "Error: Permission denied. Exiting script."; exit 1; }
cd ${NODEHOME}
chmod a+x ./*.sh
cat <<EOF
###############################
# 2. Create and Set .env File #
###############################
EOF
SERVERIP=$(get_external_ip)
LOCALLANIP=$(get_ip)
cd ${NODEHOME} &&
touch ./.env
cat >./.env <<EOL
EXT_IP=${EXTERNALIP}
INT_IP=${INTERNALIP}
EXISTING_ARCHIVERS=[{"ip":"35.193.191.159","port":4000,"publicKey":"1c63734aedef5665d6cf02d3a79ae30aedcbd27eae3b76fff05d587a6ac62981"},{"ip":"34.73.94.45","port":4000,"publicKey":"11086314ccf8642906b99f09cf3ae9a13370c57106653cd28fc1a9eee2560b64"},{"ip":"34.19.93.147","port":4000,"publicKey":"b09a8792593682cbffbbf2fc3bd812d8143740197a5f435c77a38740397088ac"}]
APP_MONITOR=${APPMONITOR}
DASHPASS=${DASHPASS}
DASHPORT=${DASHPORT}
SERVERIP=${SERVERIP}
LOCALLANIP=${LOCALLANIP}
SHMEXT=${SHMEXT}
SHMINT=${SHMINT}
RPC_SERVER_URL=${RPC_SERVER_URL}
NEXT_PUBLIC_RPC_URL=${RPC_SERVER_URL}
NEXT_EXPLORER_URL=https://explorer-atomium.shardeum.org
minNodes=640
baselineNodes=640
maxNodes=1200
nodesPerConsensusGroup=128
EOL
cat <<EOF
##########################
# 3. Clearing Old Images #
##########################
EOF
./cleanup.sh
cat <<EOF
##########################
# 4. Building base image #
##########################
EOF
cd ${NODEHOME} &&
docker-safe build --no-cache -t local-dashboard -f Dockerfile --build-arg RUNDASHBOARD=${RUNDASHBOARD} .
cat <<EOF
############################
# 5. Start Compose Project #
############################
EOF
cd ${NODEHOME}
if [[ "$(uname)" == "Darwin" ]]; then
sed "s/- '8080:8080'/- '$DASHPORT:$DASHPORT'/" docker-compose.tmpl > docker-compose.yml
sed -i '' "s/- '9001-9010:9001-9010'/- '$SHMEXT:$SHMEXT'/" docker-compose.yml
sed -i '' "s/- '10001-10010:10001-10010'/- '$SHMINT:$SHMINT'/" docker-compose.yml
else
sed "s/- '8080:8080'/- '$DASHPORT:$DASHPORT'/" docker-compose.tmpl > docker-compose.yml
sed -i "s/- '9001-9010:9001-9010'/- '$SHMEXT:$SHMEXT'/" docker-compose.yml
sed -i "s/- '10001-10010:10001-10010'/- '$SHMINT:$SHMINT'/" docker-compose.yml
fi
./docker-up.sh
echo "Starting image. This could take a while..."
(docker-safe logs -f shardeum-dashboard &) | grep -q 'done'
# Check if secrets.json exists and copy it inside container
cd ${CURRENT_DIRECTORY}
if [ -f secrets.json ]; then
echo "Reusing old node"
CONTAINER_ID=$(docker-safe ps -qf "ancestor=local-dashboard")
echo "New container id is : $CONTAINER_ID"
docker-safe cp ./secrets.json "${CONTAINER_ID}:/home/node/app/cli/build/secrets.json"
rm -f secrets.json
fi
#Do not indent
if [ $RUNDASHBOARD = "y" ]
then
cat <<EOF
To use the Web Dashboard:
1. Note the IP address that you used to connect to the node. This could be an external IP, LAN IP or localhost.
2. Open a web browser and navigate to the web dashboard at https://<Node IP address>:$DASHPORT
3. Go to the Settings tab and connect a wallet.
4. Go to the Maintenance tab and click the Start Node button.
If this validator is on the cloud and you need to reach the dashboard over the internet,
please set a strong password and use the external IP instead of localhost.
EOF
fi
cat <<EOF
To use the Command Line Interface:
1. Navigate to the Shardeum home directory ($NODEHOME).
2. Enter the validator container with ./shell.sh.
3. Run "operator-cli --help" for commands
EOF