forked from eth-educators/eth-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethd
executable file
·910 lines (831 loc) · 30.9 KB
/
ethd
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
#!/bin/bash
#set -euo pipefail
set -uo pipefail
cmd() {
docker-compose "$@"
}
determine_distro() {
# Determine OS platform
__uname=$(uname | tr "[:upper:]" "[:lower:]")
# If Linux, try to determine specific distribution
if [ "$__uname" == "linux" ]; then
# If available, use LSB to identify distribution
if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then
__distro=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//)
# Otherwise, use release info file
else
__distro=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1)
fi
fi
# For everything else (or if above failed), just use generic identifier
[ "$__distro" == "" ] && __distro=$__uname
unset __uname
__distro=$(echo $__distro | tr "[:upper:]" "[:lower:]")
}
update() {
__keeptargets=0
while :
do
if [ -z ${1+x} ]; then
break
fi
case "$1" in
--keep-targets)
__keeptargets=1
shift
;;
*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
esac
done
if git branch | grep -q master; then
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
fi
if [ "${EUID}" -eq 0 ]; then
sudo -u "${OWNER}" git pull
else
git pull
fi
# BASH_SOURCE so newer code gets to do the migration, env so I have a way to
# communicate with it
export KEEPTARGETS=$__keeptargets
"${BASH_SOURCE}" envmigrate
unset KEEPTARGETS
cmd build --pull
exec 3>&1
exec 4>&2
exec 1> /dev/null
exec 2> /dev/null
cmd pull || true
exec 1>&3
exec 2>&4
echo
echo "Your ${ENV_FILE} configuration settings have been migrated to a fresh copy. You can \
find the original contents in ${ENV_FILE}.bak."
if [ $__keeptargets = "0" ]; then
echo "NB: If you made changes to the source or binary build targets, these have NOT \
been migrated, please recreate these changes yourself."
fi
echo
cmp -s "${ENV_FILE}" "${ENV_FILE}".bak
if [ $? -ne 0 ]; then
echo "List of changes made to ${ENV_FILE} during migration - current on left, original on right:"
echo
diff -y --suppress-common-lines "${ENV_FILE}" "${ENV_FILE}".bak
else
echo "No changes made to ${ENV_FILE} during migration"
fi
if [[ "$__distro" = "ubuntu" && -n $(which snap) && -n $(snap list | grep -w "docker") ]]; then
echo
echo "WARNING! Snap docker package detected. This WILL result in issues."
echo "Removing the package will delete volumes and require a resync,"
echo "as well as re-import of all validator keys."
echo
echo "Doing so is still highly recommended however."
echo
echo "The exact steps depend a little on whether there already is"
echo "an apt version of docker installed as well, but in a nutshell"
echo '"./ethd stop" followed by "sudo snap remove --purge docker"'
echo "and then reinstall docker.io or docker-ce with apt,"
echo "re-import keys and restart eth-docker."
echo
echo "Do join us on EthStaker Discord to work through this emergency."
fi
}
prune-geth() {
__non_interactive=0
while :
do
if [ -z ${1+x} ]; then
break
fi
case "$1" in
--non-interactive)
__non_interactive=1
shift
;;
*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
esac
done
if [ ! -f "./${ENV_FILE}" ]; then
echo "${ENV_FILE} configuration file not found, aborting."
exit 1
fi
if ! grep -q '^COMPOSE_FILE=.*geth\.yml' "${ENV_FILE}" 2>/dev/null ; then
echo "You do not appear to be using Geth, aborting."
exit 1
fi
if [ $(df -P /var/lib/docker | awk '/[0-9]%/{print $(NF-2)}') -lt 41943040 ]; then
echo "You do not have enough free disk space. Make sure this reads at least 40G free (Avail):"
df -h /var/lib/docker
echo ""
echo "Aborting."
exit 1
fi
rpc_line=$(grep '^EC_RPC_PORT=' "${ENV_FILE}")
regex='^EC_RPC_PORT=([0-9]+)'
if [[ ! "${rpc_line}" =~ ${regex} ]]; then
echo "Unable to determine EC_RPC_PORT, aborting."
exit 1
else
rpc_port="${BASH_REMATCH[1]}"
fi
sync_status=$(cmd exec -T execution wget -qO- "http://localhost:$rpc_port" --header 'Content-Type: application/json' --post-data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}')
exitstatus=$?
if [ $exitstatus -ne 0 ]; then
echo "Geth is not running, aborting."
exit 1
fi
if [[ ! "${sync_status}" =~ "false" ]]; then
echo "Geth is not done syncing yet. Sync status:"
echo "${sync_status}"
echo ""
echo "Aborting."
exit 1
fi
node_logs=$(cmd logs --no-color --tail 1000 execution)
if [[ "${node_logs}" =~ "snapshot generation" && ! "${node_logs}" =~ "Generated state" ]]; then
echo "Geth has not finished generating a state snapshot yet, aborting."
exit 1
fi
regex='\[([0-9][0-9]-[0-9][0-9])\|([0-9][0-9]:[0-9][0-9]):[0-9.]*\][[:space:]]*Generated state'
if [[ "${node_logs}" =~ $regex ]]; then
snap_time=$(date -d "1970-${BASH_REMATCH[1]} ${BASH_REMATCH[2]}" +"%s")
now_time=$(date +"%s")
if [ $(($snap_time+2100)) -gt $now_time ]; then
echo "Please wait 35 minutes after snapshot generation finished. Aborting."
exit 1
fi
fi
if [ __non_interactive = 0 ]; then
while true; do
read -rp "WARNING - this will stop Geth and prune its database. Do you wish to continue? (No/Yes) " yn
case $yn in
[Yy]es ) break;;
* ) echo "Aborting, no changes made"; exit 1;;
esac
done
fi
echo ""
echo "Starting Geth prune"
echo ""
cmd run --rm set-prune-marker "touch /var/lib/goethereum/prune-marker"
cmd stop execution && cmd rm -f execution
start
echo ""
echo "Prune is running, you can observe it with 'sudo ./ethd logs -f execution'"
echo ""
echo "There should be three stages: \"Iterating state snapshot\", \"Pruning state data\", and \"Compacting database\". During \
the \"Compacting database\" stage it may not output logs for an hour or so, that is normal."
echo ""
echo "When prune is done, which takes 4-5 hours, Geth will automatically start again."
echo "NB: 'sudo' can be left off the './ethd logs' command if your user is part of the 'docker' group."
echo ""
}
keyimport() {
set -Eeuo pipefail
if [ ! -f "./${ENV_FILE}" ]; then
echo "${ENV_FILE} configuration file not found, aborting."
exit 1
fi
if grep -q '^COMPOSE_FILE=.*consensus\.yml' "${ENV_FILE}" 2>/dev/null ; then
echo "eth-docker is configured to run consensus client only, key import not possible"
exit 1
fi
__prysm=0
__path=''
__non_interactive=0
if grep -q '^COMPOSE_FILE=.*prysm.*\.yml' "${ENV_FILE}" 2>/dev/null ; then
__prysm=1
fi
while :
do
if [ -z ${1+x} ]; then
break
fi
case "$1" in
--path)
if [ -z ${2+x} ]; then
echo "--path requires a directory path, aborting"
exit 1
fi
if [ ! -d $2 ]; then
echo "$2 is not a directory"
exit 1
fi
IFS=$'\n'
files=$(find $2 -name '*.json')
unset IFS
if [ -z "$files" ]; then
echo "No .json files found in $2, aborting"
exit 1
fi
rm -f ./.eth/validator_keys/*
cp $2/*.json .eth/validator_keys/
shift 2
;;
--non-interactive)
if [ -z ${KEYSTORE_PASSWORD+x} ]; then
echo "KEYSTORE_PASSWORD not set, aborting"
exit 1
fi
if [ ${__prysm} = 1 ]; then
if [ -z ${WALLET_PASSWORD+x} ]; then
echo "Using Prysm and WALLET_PASSWORD not set, aborting"
exit 1
fi
fi
__non_interactive=1
shift
;;
*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
esac
done
if [ ${__non_interactive} = 1 ]; then
cmd run --rm validator-import --non-interactive
else
cmd run --rm validator-import
fi
}
upgrade() {
update
}
start() {
cmd up -d eth
}
up() {
start
}
run() {
start
}
stop() {
cmd down --remove-orphans
}
down() {
stop
}
terminate() {
while true; do
read -rp "WARNING - this action will destroy all data stores for this Ethereum node. Do you wish to continue? (No/Yes) " yn
case $yn in
[Yy]es ) break;;
* ) echo "Aborting, no changes made"; exit 1;;
esac
done
down
docker volume rm $(docker volume ls -q | grep $(basename $(realpath .)))
echo ""
echo "All containers stopped and all volumes deleted"
echo ""
}
restart() {
stop
start
}
logs() {
cmd logs "$@"
}
envmigrate() {
if [ ! -f "./${ENV_FILE}" ]; then
return
fi
ALL_VARS=( COMPOSE_FILE EC_NODE EC_FALLBACK_NODE1 EC_FALLBACK_NODE2 GRAFFITI NETWORK EC_NETWORK \
PRYSM_PEER_COUNT LH_PEER_COUNT TEKU_PEER_COUNT NIM_PEER_COUNT DOMAIN ACME_EMAIL \
CF_EMAIL CF_API_TOKEN AWS_PROFILE AWS_HOSTED_ZONE_ID GRAFANA_HOST PROM_HOST PRYSM_HOST \
EC_HOST EC_WS_HOST CC_HOST DDNS_SUBDOMAIN DDNS_PROXY TEKU_RAPID_SYNC LH_RAPID_SYNC LS_RAPID_SYNC \
NIMBUS_RAPID_SYNC CC_NODE BEACON_STATS_API BEACON_STATS_MACHINE EC_P2P_PORT CC_P2P_PORT PRYSM_PORT \
PRYSM_UDP_PORT GRAFANA_PORT KEY_API_PORT TRAEFIK_WEB_PORT TRAEFIK_WEB_HTTP_PORT \
EC_RPC_PORT EC_WS_PORT RESTART LOG_LEVEL GETH_CACHE SSV_P2P_PORT SSV_P2P_PORT_UDP )
TARGET_VARS=( NIM_SRC_BUILD_TARGET NIM_DOCKER_TAG NIM_DOCKERFILE TEKU_SRC_BUILD_TARGET TEKU_DOCKER_TAG \
TEKU_DOCKERFILE LH_SRC_BUILD_TARGET LH_DOCKER_TAG LH_DOCKERFILE PRYSM_SRC_BUILD_TARGET \
PRYSM_DOCKER_TAG PRYSM_DOCKERFILE ERIGON_SRC_BUILD_TARGET ERIGON_DOCKER_TAG ERIGON_DOCKERFILE \
OE_SRC_BUILD_TARGET OE_DOCKER_TAG OE_DOCKERFILE GETH_SRC_BUILD_TARGET GETH_DOCKER_TAG \
GETH_DOCKERFILE NM_SRC_BUILD_TARGET NM_DOCKER_TAG NM_DOCKERFILE BESU_SRC_BUILD_TARGET \
BESU_DOCKER_TAG BESU_DOCKERFILE SSV_NODE_TAG DEPCLI_SRC_BUILD_TARGET DEPCLI_DOCKER_TAG DEPCLI_LOCALDIR \
NODE_EXPORTER_IGNORE_MOUNT_REGEX )
OLD_VARS=( LH_PORT PRYSM_WEB_PORT )
NEW_VARS=( CC_P2P_PORT KEY_API_PORT )
# I had a "${BASH_SOURCE} envmigrate $@" so that new code would do the migration,
# then dropped that way of doing things with the parameter and used an ENV
# variable instead. This checks for that old->new behavior and looks for the parameter
if [ -z "${KEEPTARGETS-}" ]; then
__keeptargets=0
for var in "$@"; do
if [ "$var" = "--keep-targets" ]; then
__keeptargets=1
fi
done
else
__keeptargets=${KEEPTARGETS}
fi
if [ "${EUID}" -eq 0 ]; then
# Previous version of this tool when run as root may have created a root-owned .env.bak
if [ -f ./"${ENV_FILE}".bak ]; then
rm "${ENV_FILE}".bak
fi
sudo -u "${OWNER}" cp "${ENV_FILE}" "${ENV_FILE}".bak
sudo -u "${OWNER}" cp default.env "${ENV_FILE}"
sudo -u "${OWNER}" cp "${ENV_FILE}".bak .env.source
else
cp "${ENV_FILE}" "${ENV_FILE}".bak
cp default.env "${ENV_FILE}"
cp "${ENV_FILE}".bak .env.source
fi
# Migrate over user settings
for var in "${ALL_VARS[@]}"; do
value=$(grep --color=never -Po "^${var}=\K.*" ".env.source" || true)
if [ -n "${value}" -o ${var} = "GRAFFITI" ]; then
sed -i'.original' -e "s~^\(${var}\s*=\s*\).*$~\1${value}~" "${ENV_FILE}"
fi
done
if [ $__keeptargets = "1" ]; then
# Migrate over build targets
for var in "${TARGET_VARS[@]}"; do
value=$(grep --color=never -Po "^${var}=\K.*" ".env.source" || true)
if [ -n "${value}" ]; then
sed -i'.original' -e "s~^\(${var}\s*=\s*\).*$~\1${value}~" "${ENV_FILE}"
fi
done
fi
# Move value from old variable name(s) to new one(s)
for index in "${!OLD_VARS[@]}"; do
var=${OLD_VARS[index]}
value=$(grep --color=never -Po "^${var}=\K.*" ".env.source" || true)
if [ -n "${value}" ]; then
sed -i'.original' -e "s~^\(${NEW_VARS[index]}\s*=\s*\).*$~\1${value}~" "${ENV_FILE}"
fi
done
rm .env.source
}
query_network() {
# Mainnet or Testnet network
NETWORK=$(whiptail --notags --title "Select Network" --menu \
"Which network do you want to run on?" 9 60 2 \
"prater" "Prater Testnet" \
"mainnet" "Ethereum Mainnet" 3>&1 1>&2 2>&3)
if [ "${NETWORK}" == "mainnet" ]; then
EC_NETWORK=mainnet
echo "You chose to run on Ethereum mainnet"
elif [ "${NETWORK}" == "prater" ]; then
EC_NETWORK=goerli
echo "You chose to run on Prater testnet"
else
echo "You chose Cancel."
exit 0
fi
}
query_deployment() {
if uname -a | grep -q aarch64; then
__deployment=$(whiptail --notags --title "Select deployment type" --menu \
"What kind of deployment do you want to run?" 11 80 4 \
"node" "Ethereum node - consensus, execution and validator client" \
"rocket" "Validator client only - integrate with RocketPool" \
"validator" "Validator client only - integrate with other consensus layer" \
"rpc" "Ethereum RPC node - consensus and execution client" 3>&1 1>&2 2>&3)
else
__deployment=$(whiptail --notags --title "Select deployment type" --menu \
"What kind of deployment do you want to run?" 12 80 5 \
"node" "Ethereum node - consensus, execution and validator client" \
"rocket" "Validator client only - integrate with RocketPool" \
"validator" "Validator client only - integrate with other consensus layer" \
"blox" "Blox SSV node - consensus, execution and ssv-node" \
"rpc" "Ethereum RPC node - consensus and execution client" 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "Your deployment choice is:" "${__deployment}"
else
echo "You chose Cancel."
exit 0
fi
}
query_validator_client() {
if uname -a | grep -q aarch64; then
CONSENSUS_CLIENT=$(whiptail --notags --title "Select validator client" --menu \
"Which validator client do you want to run?" 9 65 2 \
"lh-validator.yml" "Lighthouse validator client" \
"teku-validator.yml" "Teku validator client" 3>&1 1>&2 2>&3)
else
CONSENSUS_CLIENT=$(whiptail --notags --title "Select validator client" --menu \
"Which validator client do you want to run?" 11 65 4 \
"teku-validator.yml" "Teku validator client" \
"lh-validator.yml" "Lighthouse validator client" \
"lodestar-validator.yml" "Lodestar validator client" \
"prysm-validator.yml" "Prysm validator client" 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "Your validator client file is:" "${CONSENSUS_CLIENT}"
else
echo "You chose Cancel."
exit 0
fi
}
query_validator_client_rocket() {
if uname -a | grep -q aarch64; then
CONSENSUS_CLIENT=$(whiptail --notags --title "Select validator client" --menu \
"Which validator client do you want to run?" 9 65 2 \
"lh-validator.yml" "Lighthouse validator client" \
"teku-validator.yml" "Teku validator client" 3>&1 1>&2 2>&3)
else
CONSENSUS_CLIENT=$(whiptail --notags --title "Select validator client" --menu \
"Which validator client do you want to run?" 9 65 2 \
"teku-validator.yml" "Teku validator client" \
"lh-validator.yml" "Lighthouse validator client" 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "Your validator client file is:" "${CONSENSUS_CLIENT}"
else
echo "You chose Cancel."
exit 0
fi
}
query_consensus_client() {
if uname -a | grep -q aarch64; then
CONSENSUS_CLIENT=$(whiptail --notags --title "Select consensus client" --menu \
"Which consensus client do you want to run?" 10 65 3 \
"lh-base.yml" "Lighthouse (Rust) - consensus and validator client" \
"nimbus-base.yml" "Nimbus (Nim) - consensus and validator client" \
"teku-base.yml" "Teku (Java) - consensus and validator client" 3>&1 1>&2 2>&3)
else
CONSENSUS_CLIENT=$(whiptail --notags --title "Select consensus client" --menu \
"Which consensus client do you want to run?" 12 65 5 \
"teku-base.yml" "Teku (Java) - consensus and validator client" \
"lh-base.yml" "Lighthouse (Rust) - consensus and validator client" \
"nimbus-base.yml" "Nimbus (Nim) - consensus and validator client" \
"lodestar-base.yml" "Lodestar (Javascript) - consensus and validator client" \
"prysm-base.yml" "Prysm (Go) - consensus and validator client" 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "Your consensus client file is:" "${CONSENSUS_CLIENT}"
else
echo "You chose Cancel."
exit 0
fi
}
query_consensus_only_client() {
if uname -a | grep -q aarch64; then
CONSENSUS_CLIENT=$(whiptail --notags --title "Select consensus client" --menu \
"Which consensus client do you want to run?" 10 65 3 \
"lh-consensus.yml" "Lighthouse (Rust) - consensus client" \
"nimbus-consensus.yml" "Nimbus (Nim) - consensus client" \
"teku-consensus.yml" "Teku (Java) - consensus client" 3>&1 1>&2 2>&3)
else
CONSENSUS_CLIENT=$(whiptail --notags --title "Select consensus client" --menu \
"Which consensus client do you want to run?" 12 65 5 \
"teku-consensus.yml" "Teku (Java) - consensus client" \
"lh-consensus.yml" "Lighthouse (Rust) - consensus client" \
"nimbus-consensus.yml" "Nimbus (Nim) - consensus client" \
"lodestar-consensus.yml" "Lodestar (Javascript) - consensus client" \
"prysm-consensus.yml" "Prysm (Go) - consensus client" 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "Your consensus client file is:" "${CONSENSUS_CLIENT}"
else
echo "You chose Cancel."
exit 0
fi
}
query_custom_execution_client() {
EC_CUSTOM_NODE=$(whiptail --title "Configure custom execution client" --inputbox "What is the URL for your custom execution client? (right-click to paste)" 10 60 https://${EC_NETWORK}.infura.io/v3/... 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "your custom execution client is:" $EC_CUSTOM_NODE
else
echo "You chose Cancel."
exit 0
fi
}
query_fallback_execution_client() {
if [ "${CONSENSUS_CLIENT}" == "nimbus-base.yml" -o "${CONSENSUS_CLIENT}" == "nimbus-consensus.yml" ]; then
EC_FALLBACK_NODE1=$(whiptail --title "Configure fallback execution client" --inputbox "What is the URL for your fallback execution client? (right-click to paste)" 10 60 "wss://${EC_NETWORK}.infura.io/v3/..." 3>&1 1>&2 2>&3)
else
EC_FALLBACK_NODE1=$(whiptail --title "Configure fallback execution client" --inputbox "What is the URL for your fallback execution client? (right-click to paste)" 10 60 "https://${EC_NETWORK}.infura.io/v3/..." 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "your fallback execution client is:" "${EC_FALLBACK_NODE1}"
else
echo "You chose Cancel."
exit 0
fi
}
query_execution_client() {
if uname -a | grep -q aarch64; then
EXECUTION_CLIENT=$(whiptail --notags --title "Select execution client" --menu \
"Which execution client do you want to run? Choose Custom for 3rd parties like Infura" 9 60 2 \
"nm.yml" "Nethermind (.NET)" \
"geth.yml" "Geth (Go)" \
"NONE" "Custom" 3>&1 1>&2 2>&3)
else
EXECUTION_CLIENT=$(whiptail --notags --title "Select execution client" --menu \
"Which execution client do you want to run? Choose Custom for 3rd parties like Infura" 12 60 5 \
"geth.yml" "Geth (Go)" \
"nm.yml" "Nethermind (.NET)" \
"besu.yml" "Besu (Java)" \
"erigon.yml" "Erigon (Go)" \
"NONE" "Custom" 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -ne 0 ]; then
echo "You chose Cancel."
exit 0
fi
if [ "${EXECUTION_CLIENT}" == "NONE" ]; then
unset EXECUTION_CLIENT
query_custom_execution_client
EC_NODE="${EC_CUSTOM_NODE}"
else
echo "Your execution client file is:" "${EXECUTION_CLIENT}"
if [ "${CONSENSUS_CLIENT}" == "nimbus-base.yml" -o "${CONSENSUS_CLIENT}" == "nimbus-consensus.yml" ]; then
EC_NODE="ws://execution:8546"
else
EC_NODE="http://execution:8545"
fi
fi
EC_FALLBACK_NODE1="${EC_NODE}"
EC_FALLBACK_NODE2="${EC_NODE}"
if (whiptail --title "Select Option" --yesno "Do you want to use a fallback execution client?" 10 60) then
query_fallback_execution_client
if [[ "${CONSENSUS_CLIENT}" != "prysm-base.yml" && "${CONSENSUS_CLIENT}" != "nimbus-base.yml" && "${CONSENSUS_CLIENT}" != "prysm-consensus.yml" && "${CONSENSUS_CLIENT}" != "nimbus-consensus.yml" ]]; then
EC_NODE="${EC_NODE}"",""${EC_FALLBACK_NODE1}"
fi
fi
}
query_grafana() {
if (whiptail --title "Select Option" --yesno "Do you want to use Grafana dashboards?" 10 60) then
GRAFANA_CLIENT="grafana.yml:grafana-shared.yml"
else
unset GRAFANA_CLIENT
fi
}
query_remote_beacon() {
if [ "${__deployment}" = "rocket" ]; then
REMOTE_BEACON=$(whiptail --title "Configure remote consensus client" --inputbox "What is the URL for your remote consensus client? (right-click to paste)" 10 60 "http://eth2:5052" 3>&1 1>&2 2>&3)
else
REMOTE_BEACON=$(whiptail --title "Configure remote consensus client" --inputbox "What is the URL for your remote consensus client? (right-click to paste)" 10 60 3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "your remote consensus client is:" "${REMOTE_BEACON}"
else
echo "You chose Cancel."
exit 0
fi
}
query_graffiti() {
GRAFFITI=$(whiptail --title "Configure Graffiti" --inputbox "What Graffiti do you want to send with your blocks? (up to 32 characters)" 10 37 "eth-docker" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus -eq 0 ]; then
echo "your Graffiti is:" "${GRAFFITI}"
else
echo "You chose Cancel."
exit 0
fi
}
query_rapid_sync() {
# Assume no to start
TEKU_RAPID_SYNC=""
LH_RAPID_SYNC=""
LS_RAPID_SYNC=""
NIMBUS_RAPID_SYNC=""
PRYSM_RAPID_SYNC=""
case "${CONSENSUS_CLIENT}" in
"teku-base.yml" | "teku-consensus.yml")
if (whiptail --title "Select Option" --yesno "Do you want to use Teku rapid sync with remote checkpoint, e.g. Infura?" 10 60) then
query_remote_beacon
TEKU_RAPID_SYNC="--initial-state=${REMOTE_BEACON}/eth/v1/debug/beacon/states/finalized"
fi
;;
"lh-base.yml" | "lh-consensus.yml")
if (whiptail --title "Select Option" --yesno "Do you want to use Lighthouse rapid sync with remote checkpoint, e.g. Infura?" 10 60) then
query_remote_beacon
LH_RAPID_SYNC="--checkpoint-sync-url=${REMOTE_BEACON}"
fi
;;
"nimbus-base.yml" | "nimbus-consensus.yml")
if (whiptail --title "Select Option" --yesno "Do you want to use Nimbus rapid sync with remote checkpoint, e.g. Infura?" 10 60) then
query_remote_beacon
NIMBUS_RAPID_SYNC="${REMOTE_BEACON}"
fi
;;
"lodestar-base.yml" | "lodestar-consensus.yml")
if (whiptail --title "Select Option" --yesno "Do you want to use Lodestar rapid sync with remote checkpoint, e.g. Infura?" 10 60) then
query_remote_beacon
LS_RAPID_SYNC="--weakSubjectivitySyncLatest=true --weakSubjectivityServerUrl=${REMOTE_BEACON}"
fi
;;
"prysm-base.yml" | "prysm-consensus.yml")
;;
*)
;;
esac
}
set_value_in_env() {
# Assumes that "var" has been set to the name of the variable to be changed
if [ "${!var+x}" ]; then
if ! grep -qF "${var}" "${ENV_FILE}" 2>/dev/null ; then
echo "${var}=${!var}" >> "${ENV_FILE}"
else
sed -i'.original' -e "s~^\(${var}\s*=\s*\).*$~\1${!var}~" "${ENV_FILE}"
fi
fi
}
config () {
if [[ "$__distro" = "ubuntu" && -n $(which snap) && -n $(snap list | grep -w "docker") ]]; then
echo
echo "WARNING! Snap docker package detected. This WILL result in issues."
echo "Removing the package will delete volumes and require a resync,"
echo "as well as re-import of all validator keys."
echo
echo "Doing so is still highly recommended however."
echo
echo "The exact steps depend a little on whether there already is"
echo "an apt version of docker installed as well, but in a nutshell"
echo '"sudo snap remove --purge docker" and then reinstall docker.io"'
echo "or docker-ce with apt, re-import keys and restart eth-docker."
echo
echo "Do join us on EthStaker Discord to work through this emergency."
echo
echo "Aborting, this is not safe."
exit 1
fi
# Create ENV file if needed
if ! [[ -f "${ENV_FILE}" ]]; then
ENV_TEMPLATE="default.env"
echo "Your configuration file template is:" "${ENV_TEMPLATE}"
if [ "${EUID}" -eq 0 ]; then
sudo -u "${OWNER}" cp "${ENV_TEMPLATE}" "${ENV_FILE}"
else
cp "${ENV_TEMPLATE}" "${ENV_FILE}"
fi
fi
query_network
query_deployment
case "${__deployment}" in
"node")
query_consensus_client
;;
"validator")
query_validator_client
;;
"rocket")
query_validator_client_rocket
;;
"blox" | "rpc")
query_consensus_only_client
;;
*)
echo "Unknown deployment ${__deployment}, this is a bug."
exit 1
;;
esac
if [[ ! "${CONSENSUS_CLIENT}" =~ "-validator.yml" ]]; then
CC_NODE="http://consensus:5052"
if [ ${__deployment} = "node" ]; then
query_graffiti
fi
query_execution_client
query_rapid_sync
query_grafana
else
unset EXECUTION_CLIENT
unset GRAFANA_CLIENT
query_graffiti
query_remote_beacon
CC_NODE="${REMOTE_BEACON}"
fi
COMPOSE_FILE="${CONSENSUS_CLIENT}"
if [ "${EXECUTION_CLIENT+x}" ]; then
COMPOSE_FILE="${COMPOSE_FILE}:${EXECUTION_CLIENT}"
fi
if [ "${__deployment}" = "blox" ]; then
COMPOSE_FILE="${COMPOSE_FILE}:blox-ssv.yml"
fi
if [ "${__deployment}" = "rocket" ]; then
COMPOSE_FILE="${COMPOSE_FILE}:ext-network.yml"
sed -i'.original' -e "s~name: traefik_default~name: rocketpool_net~" ext-network.yml
fi
if [ "${GRAFANA_CLIENT+x}" ]; then
COMPOSE_FILE="${COMPOSE_FILE}:${GRAFANA_CLIENT}"
fi
echo "Your COMPOSE_FILE is:" "${COMPOSE_FILE}"
var=GRAFFITI
set_value_in_env
var=CC_NODE
set_value_in_env
var=TEKU_RAPID_SYNC
set_value_in_env
var=LH_RAPID_SYNC
set_value_in_env
var=LS_RAPID_SYNC
set_value_in_env
var=NIMBUS_RAPID_SYNC
set_value_in_env
# var=PRYSM_RAPID_SYNC
# set_value_in_env
var=COMPOSE_FILE
set_value_in_env
var=EC_NODE
set_value_in_env
var=EC_FALLBACK_NODE1
set_value_in_env
var=EC_FALLBACK_NODE2
set_value_in_env
var=NETWORK
set_value_in_env
var=EC_NETWORK
set_value_in_env
if [[ "${EUID}" -eq 0 || -n $(id -nG $(id -u) | grep -w "docker") ]]; then
cmd build --pull
exec 3>&1
exec 4>&2
exec 1> /dev/null
exec 2> /dev/null
cmd pull || true
exec 1>&3
exec 2>&4
fi
}
printhelp() {
me=$(basename "${BASH_SOURCE}")
echo "usage: ${me} [help|-h|--help] <subcommand>"
echo ""
echo "optional arguments:"
echo " help | -h | --help"
echo " print this message and exit"
echo ""
echo "subcommands:"
echo " config "
echo " configures eth-docker with your choice of Ethereum clients"
echo " keyimport [--non-interactive | --path ] "
echo " import validator keys from .eth/validator_keys "
echo " --path specifies an alternate import path "
echo " --non-interactive is for use from another script, "
echo " in which case KEYSTORE_PASSWORD must be set to the password "
echo " shared by all keystore-m json files, and in the case of Prysm, "
echo " WALLET_PASSWORD must be set to the password for Prysm's wallet "
echo " update [--keep-targets] "
echo " updates all client versions and eth-docker itself"
echo " --keep-targets will keep your custom build targets in .env"
echo " start"
echo " starts the Ethereum node software"
echo " stop"
echo " stops the Ethereum node software"
echo " restart"
echo " restarts the Ethereum node software, a combination of stop and start"
echo " logs"
echo " shows logs"
echo " cmd <command>"
echo " executes an arbitrary docker-compose command. Use \"cmd help\" to list them"
echo " terminate"
echo " stops the Ethereum node software and destroys all data stores"
echo " prune-geth"
echo " stops the Geth execution client and prunes its DB. This takes about 4-5 hours"
echo ""
echo ""
echo "The logs subcommand can be appended by flags and specify the container(s). example: "
echo ""
echo " $me logs -f --tail 500 execution"
echo " shows logs only for execution service"
echo ""
echo ""
echo "Be sure to run the config command as a non-root user, and all other commands"
echo "either with sudo, or as a user who is part of the \"docker\" group"
echo ""
exit 0
}
if [[ "$#" -eq 0 || "$1" == "help" || "$1" == "-h" || "$1" == "--help" ]]; then
printhelp
fi
cd $(dirname $(realpath ${BASH_SOURCE}))
# Use this to make sure root doesn't end up owning files
if [[ "$OSTYPE" == "darwin"* ]]; then
OWNER=$(stat -f '$Su' .)
else
OWNER=$(stat -c '%U' .)
fi
if [ "${OWNER}" == "root" ]; then
echo "Please install eth-docker as a non-root user."
exit 1
fi
ENV_FILE=.env
command="$1"
shift
determine_distro
"$command" $@