forked from eth-educators/eth-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethd
executable file
·3473 lines (3157 loc) · 120 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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -Eeuo pipefail
__project_name="Eth Docker"
__app_name="Ethereum node"
__sample_service="consensus"
__docker_exe="docker"
__compose_exe="docker compose"
__compose_upgraded=0
dodocker() {
$__docker_sudo $__docker_exe "$@"
}
docompose() {
# I want word splitting here
# shellcheck disable=SC2086
$__docker_sudo $__compose_exe "$@"
}
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 [ -n "$(command -v lsb_release 2>/dev/null)" ]; then
__distro=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//)
# Otherwise, use release info file
else
__distro=$(find /etc -maxdepth 1 -type f -name '[A-Za-z]*[_-][rv]e[lr]*' \
| grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1)
fi
else
__distro=""
fi
# For everything else (or if above failed), just use generic identifier
[ "$__distro" == "" ] && __distro=$__uname
unset __uname
__distro=$(echo "$__distro" | tr "[:upper:]" "[:lower:]")
if [[ "$__distro" = "ubuntu" ]]; then
if ! dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -q "ok installed"; then
${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install lsb-release
fi
__os_major_version=$(lsb_release -r | cut -d: -f2 | sed s/'^\t'// | cut -d. -f1)
elif [[ "$__distro" =~ "debian" ]]; then
if ! dpkg-query -W -f='${Status}' lsb-release 2>/dev/null | grep -q "ok installed"; then
${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install lsb-release
fi
__os_major_version=$(lsb_release -r | cut -f2)
fi
}
handle_docker_sudo() {
set +e
if [[ "$__distro" =~ "debian" || "$__distro" = "ubuntu" ]]; then
systemctl status docker >/dev/null
result=$?
if [ ! "${result}" -eq 0 ]; then
echo "The Docker daemon is not running. Please check Docker installation."
echo "\"sudo systemctl status docker\" and \"sudo journalctl -fu docker\" will be helpful."
echo "Aborting."
exit 1
fi
fi
set -e
__docker_version=$(docker --version | awk '{ gsub(/,/, "", $3); print $3 }')
__docker_major_version=$(docker --version | awk '{ split($3, version, "."); print version[1]; }')
if [ "${__docker_major_version}" -lt 23 ]; then
__old_docker=1
echo "Docker ${__docker_version} detected"
else
__old_docker=0
fi
__docker_sudo=""
if ! docker images >/dev/null 2>&1; then
echo "Will use sudo to access Docker"
__docker_sudo="sudo"
fi
}
handle_root() {
if [ "${EUID}" -eq 0 ]; then
__as_owner="sudo -u ${OWNER}"
__auto_sudo=""
else
__as_owner=""
__auto_sudo="sudo"
fi
}
upgrade_compose() {
if ! type -P docker-compose >/dev/null 2>&1; then
echo "Docker Compose has already been updated to V2"
return
fi
echo "Updating Docker Compose to V2"
if [[ "$__distro" = "ubuntu" ]]; then
if [ "${__os_major_version}" -lt 22 ]; then
echo "${__project_name} cannot update Docker Compose on Ubuntu ${__os_major_version}."
echo "Consider upgrading to 22.04 and then 24.04."
exit 1
fi
${__auto_sudo} apt-get update
${__auto_sudo} apt-get install -y docker-compose-v2 docker-buildx
echo "Installed docker-compose-v2"
__old_compose=0
__compose_upgraded=1
if dpkg-query -W -f='${Status}' docker.io 2>/dev/null | grep -q "ok installed"; then
${__auto_sudo} apt-mark manual docker.io
elif dpkg-query -W -f='${Status}' docker-ce 2>/dev/null | grep -q "ok installed"; then
${__auto_sudo} apt-mark manual docker-ce
fi
${__auto_sudo} apt-get remove -y docker-compose
echo "Removed docker-compose"
elif [[ "$__distro" =~ "debian" ]]; then
${__auto_sudo} apt-get update && ${__auto_sudo} apt-get -y install ca-certificates curl gnupg
if [ "${__os_major_version}" -lt 11 ]; then
echo "${__project_name} cannot update Docker Compose on Debian ${__os_major_version}."
echo "Consider upgrading to 11 and then 12."
exit 1
fi
${__auto_sudo} mkdir -p /etc/apt/keyrings
${__auto_sudo} curl -fsSL https://download.docker.com/linux/debian/gpg | ${__auto_sudo} gpg --dearmor --yes \
-o /etc/apt/keyrings/docker.gpg
${__auto_sudo} echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
| ${__auto_sudo} tee /etc/apt/sources.list.d/docker.list > /dev/null
${__auto_sudo} apt-get update
${__auto_sudo} apt-get install -y docker-compose-plugin docker-buildx-plugin
echo "Installed docker-compose-plugin"
__old_compose=0
__compose_upgraded=1
if dpkg-query -W -f='${Status}' docker.io 2>/dev/null | grep -q "ok installed"; then
${__auto_sudo} apt-mark manual docker.io
elif dpkg-query -W -f='${Status}' docker-ce 2>/dev/null | grep -q "ok installed"; then
${__auto_sudo} apt-mark manual docker-ce
fi
${__auto_sudo} apt-get remove -y docker-compose
echo "Removed docker-compose"
else
echo "${__project_name} does not know how to update Docker Compose on $__distro"
fi
}
check_compose_version() {
# Check for Compose V2 (docker compose) vs Compose V1 (docker-compose)
if docker compose version >/dev/null 2>&1; then
__compose_version=$($__docker_sudo docker compose version | sed -n -E -e "s/.*version [v]?([0-9.-]*).*/\1/ip")
__compose_major=${__compose_version%%.*}
if [[ "${__compose_major}" -eq 1 ]]; then
__old_compose=1
else
__old_compose=0
fi
else
__old_compose=1
__compose_version=$($__docker_sudo docker-compose --version | sed -n -E -e "s/.*version [v]?([0-9.-]*).*/\1/ip")
fi
if [ "${__old_compose}" -eq 1 ]; then
if [ -n "${ETHDSECUNDO-}" ] || [ ! "${__command}" = "update" ]; then # Don't run this twice
echo
echo "You are using docker-compose ${__compose_version}, which is unsupported by Docker, Inc."
echo "${__project_name} only supports Compose V2."
echo
echo "It is recommended that you replace Compose V1 with Compose V2."
while true; do
read -rp "Do you want to update Docker Compose to V2? (yes/no) " yn
case $yn in
[Nn]* ) echo "Please be sure to update Docker Compose yourself!"; break;;
* ) upgrade_compose; break;;
esac
done
fi
fi
}
prep_conffiles() {
# Create custom-prom.yml if it doesn't exist
if [ ! -f "./prometheus/custom-prom.yml" ]; then
${__as_owner} touch "./prometheus/custom-prom.yml"
fi
# Move ssv-config.yaml
if [ -f "./ssv-config.yaml" ]; then
${__as_owner} mv ./ssv-config.yaml ssv-config/config.yaml
fi
# Create config.yaml if it doesn't exist
if [ ! -f "ssv-config/config.yaml" ]; then
${__as_owner} cp ssv-config/config-sample.yaml ssv-config/config.yaml
fi
if [ ! -f "ssv-config/dkg-config.yaml" ]; then
${__as_owner} cp ssv-config/dkg-config-sample.yaml ssv-config/dkg-config.yaml
fi
# Make sure local user owns the dkg output dir and everything in it
if find .eth/dkg_output \! -user "${OWNER}" -o \! -group "${OWNER_GROUP}" -o \! -perm 755 | grep -q .; then
${__auto_sudo} chown -R "${OWNER}:${OWNER_GROUP}" .eth/dkg_output
${__auto_sudo} chmod -R 755 .eth/dkg_output
fi
# Create ext-network.yml if it doesn't exist
if [ ! -f "ext-network.yml" ]; then
${__as_owner} cp ext-network.yml.sample ext-network.yml
fi
}
check_for_snap() {
if [[ "$__distro" = "ubuntu" && -n "$(command -v snap)" ]] && snap list 2>/dev/null | grep -qw '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
echo "Doing so is still highly recommended however."
echo
echo "The exact steps depend a little on whether there already is an apt version of Docker installed as well,"
echo "but in a nutshell \"$__me stop\" followed by \"sudo snap remove --purge docker\" followed by a reboot,"
echo "and as needed install docker-ce or docker.io with apt."
echo
echo "Do join us on EthStaker Discord to work through this issue."
echo
echo "Aborting, this is not safe"
exit 1
fi
}
install-bash-completions() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Skipping installation of tab completions (not supported on macOS)"
else
if [ ! -f "$(pkg-config --variable=completionsdir bash-completion)/ethd" ]; then
echo "Installing bash completions for ethd"
${__auto_sudo} ln -s "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/bash-completion" \
"$(pkg-config --variable=completionsdir bash-completion)/ethd" || true
fi
fi
}
install() {
if [[ "$__distro" = "ubuntu" ]]; then
${__auto_sudo} apt-get update
${__auto_sudo} apt-get install -y ca-certificates curl gnupg whiptail chrony pkg-config
echo
echo
if [ -z "$(command -v docker)" ]; then
if [ "${__os_major_version}" -lt 22 ]; then
echo "${__project_name} cannot install Docker on Ubuntu ${__os_major_version}."
echo "Consider upgrading to 22.04 and then 24.04."
exit 1
fi
read -rp "This will attempt to install Docker and make your user part of the docker group. Do you wish to \
continue? (no/yes) " yn
case $yn in
[Yy]* ) ;;
* ) echo "Aborting, no changes made"; return 0;;
esac
${__auto_sudo} mkdir -p /etc/apt/keyrings
${__auto_sudo} curl -fsSL https://download.docker.com/linux/ubuntu/gpg | ${__auto_sudo} gpg --dearmor \
--yes -o /etc/apt/keyrings/docker.gpg
${__auto_sudo} echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
| ${__auto_sudo} tee /etc/apt/sources.list.d/docker.list > /dev/null
${__auto_sudo} apt-get update
${__auto_sudo} apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin \
docker-buildx-plugin
echo "Installed docker-ce and docker-compose-plugin"
else
echo "Docker is already installed"
fi
__groups=$(${__as_owner} groups)
if [[ ! "$__groups" =~ "docker" ]]; then
echo "Making your user part of the docker group"
${__auto_sudo} usermod -aG docker "${OWNER}"
echo "Please run newgrp docker or log out and back in"
else
echo "Your user is already part of the docker group"
fi
elif [[ "$__distro" =~ "debian" ]]; then
${__auto_sudo} apt-get update
${__auto_sudo} apt-get -y install ca-certificates curl gnupg whiptail chrony pkg-config
echo
echo
if [ -z "$(command -v docker)" ]; then
if [ "${__os_major_version}" -lt 11 ]; then
echo "${__project_name} cannot install Docker on Debian ${__os_major_version}."
echo "Consider upgrading to 11 and then 12."
exit 1
fi
read -rp "This will attempt to install Docker and make your user part of the docker group. Do you wish to \
continue? (no/yes) " yn
case $yn in
[Yy]* ) ;;
* ) echo "Aborting, no changes made"; return 0;;
esac
${__auto_sudo} mkdir -p /etc/apt/keyrings
${__auto_sudo} curl -fsSL https://download.docker.com/linux/debian/gpg | ${__auto_sudo} gpg --dearmor \
--yes -o /etc/apt/keyrings/docker.gpg
${__auto_sudo} echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
| ${__auto_sudo} tee /etc/apt/sources.list.d/docker.list > /dev/null
${__auto_sudo} apt-get update
${__auto_sudo} apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin \
docker-buildx-plugin
echo "Installed docker-ce and docker-compose-plugin"
else
echo "Docker is already installed"
fi
__groups=$(${__as_owner} groups)
if [[ ! "$__groups" =~ "docker" ]]; then
echo "Making your user part of the docker group"
${__auto_sudo} usermod -aG docker "${OWNER}"
echo "Please run newgrp docker or log out and back in"
else
echo "Your user is already part of the docker group"
fi
else
echo "${__project_name} does not know how to install Docker on $__distro"
fi
if ! [[ "$__distro" = "ubuntu" ]] || [[ "$__distro" =~ "debian" ]]; then
return 0
fi
# We only get here on Ubuntu or Debian
install-bash-completions
__install_base=$(basename "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
if [ "${__install_base}" = "eth-docker" ]; then
read -rp "Do you want to be able to call 'ethd' from anywhere? (yes/no) " yn
case $yn in
[Nn]* ) return 0;;
* ) ;;
esac
if grep -q "alias ethd" ~/.profile; then
sed -i'.original' -e "/alias ethd/d" ~/.profile
fi
echo "alias ethd=$(realpath "${BASH_SOURCE[0]}")" >>~/.profile
if grep -q "cat.*\.motd" ~/.profile; then
sed -i'.original' -e "/cat.*\.motd/d" ~/.profile
fi
echo "cat $(dirname "$(realpath "${BASH_SOURCE[0]}")")/.motd" >>~/.profile
echo "Go ahead and 'source ~/.profile' or log out and back in."
echo "After that, you can use the command 'ethd'."
fi
return 0
}
__get_docker_free_space() { # set __free_space to what's available to Docker
if [[ "$OSTYPE" == "darwin"* ]]; then # macOS doesn't expose docker root dir to the OS
__free_space=$(dodocker run --rm -v macos-space-check:/dummy busybox df -P /dummy | awk '/[0-9]%/{print $(NF-2)}')
else
__docker_dir=$(dodocker system info --format '{{.DockerRootDir}}')
__free_space=$(df -P "${__docker_dir}" | awk '/[0-9]%/{print $(NF-2)}')
fi
re='^[0-9]+$'
if ! [[ "${__free_space}" =~ $re ]] ; then
echo "Unable to determine free disk space. This is likely a bug."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "df reports $(dodocker run --rm -v macos-space-check:/dummy busybox df -P /dummy) and __free_space is ${__free_space}"
else
echo "df reports $(df -P "${__docker_dir}") and __free_space is ${__free_space}"
fi
exit 70
fi
}
__display_docker_dir() {
if [[ "$OSTYPE" == "darwin"* ]]; then # macOS doesn't expose docker root dir to the OS
echo "Here's total and used space on Docker's virtual volume"
dodocker run --rm -v macos-space-check:/dummy busybox df -h /dummy
else
echo "Here's total and used space on ${__docker_dir}"
df -h "${__docker_dir}"
fi
}
__display_docker_volumes() {
echo
if [ -z "$(dodocker volume ls -q -f "name=^$(basename "$(realpath .)")_[^_]+")" ]; then
echo "There are no Docker volumes for this copy of ${__project_name}"
echo
else
echo "Here are the Docker volumes used by this copy of ${__project_name} and their space usage:"
dodocker system df -v | grep -A 50 "VOLUME NAME" | grep "^$(basename "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")"
echo
echo "If your Consensus Layer client takes more than 300 GiB, you can resync it with"
echo "\"${__me} resync-consensus\"."
echo
fi
echo "If there is some mystery space being taken up, try \"sudo ncdu /\"."
echo
}
space() {
__get_docker_free_space
echo
if [[ "$OSTYPE" == "darwin"* ]]; then # macOS doesn't expose docker root dir to the OS
echo "You have $(( __free_space / 1024 / 1024 )) GiB free for Docker volumes"
else
echo "You have $(( __free_space / 1024 / 1024 )) GiB free on ${__docker_dir}"
fi
echo
__display_docker_dir
__display_docker_volumes
}
# Warn user if space is low, so they can prune
check_disk_space() {
__get_docker_free_space
var="COMPOSE_FILE"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
var="AUTOPRUNE_NM"
auto_prune=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
var="NETWORK"
NETWORK=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${NETWORK}" = "mainnet" ] || [ "${NETWORK}" = "gnosis" ]; then
__min_free=314572800
__min_gib=300
__safe_prune=250
else
__min_free=31457280
__min_gib=30
__safe_prune=25
fi
# Literal match intended
# shellcheck disable=SC2076
if [[ "${value}" =~ "nethermind.yml" ]] && [[ "${__free_space}" -lt "${__min_free}" ]]; then
echo
echo "You are running Nethermind and have less than ${__min_gib} GiB of free disk space."
if [ "${auto_prune}" = true ]; then
echo "It should currently be auto-pruning, check logs with \"$__me logs -f --tail 500 execution | grep \
Full\". Free space:"
else
echo "If the below reads above ${__safe_prune} GiB free, prune it with \"$__me prune-nethermind\""
fi
echo
__display_docker_dir
__display_docker_volumes
elif [[ "${value}" =~ "geth.yml" ]] && [[ "${__free_space}" -lt 104857600 ]]; then
echo
echo "You are running Geth and have less than 100 GiB of free disk space."
echo "You may resync from scratch to use PBSS and slow on-disk DB growth, with \"$__me resync-execution\"."
echo
__display_docker_dir
__display_docker_volumes
elif [[ "${value}" =~ "besu.yml" ]] && [[ "${__free_space}" -lt 52428800 ]]; then
echo
echo "You are running Besu and have less than 50 GiB of free disk space."
echo
echo "If this is a long-running Besu, you may prune trie-logs with \"$__me prune-besu\"."
__display_docker_volumes
echo
elif [[ "${__free_space}" -lt 52428800 ]]; then
echo
echo "You have less than 50 GiB of free disk space:"
echo
__display_docker_dir
echo
echo "Pruning does not appear an option for your client mix."
echo "If total space is less than 1.8 TiB, consider cloning to a larger drive."
__display_docker_volumes
fi
}
source_build() {
# Check whether there's a source-built client and if so, force it with --no-cache
var="COMPOSE_FILE"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
case "${value}" in
*deposit-cli.yml* )
docompose --profile tools build --pull --no-cache deposit-cli-new
;;
esac
case "${value}" in
*mev-boost.yml* )
var="MEV_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache mev-boost
fi
;;
esac
case "${value}" in
*reth.yml* )
var="RETH_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache execution
fi
;;
*geth.yml* )
var="GETH_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache execution
fi
;;
*besu.yml* )
var="BESU_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache execution
fi
;;
*nethermind.yml* )
var="NM_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache execution
fi
;;
*erigon.yml* )
var="ERIGON_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache execution
fi
;;
*nimbus-el.yml* )
var="NIMEL_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache execution
fi
;;
esac
case "${value}" in
*lighthouse.yml* | *lighthouse-cl-only.yml* )
var="LH_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache consensus
fi
;;
*teku.yml* | *teku-allin1.yml* | *teku-cl-only.yml* )
var="TEKU_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache consensus
fi
;;
*lodestar.yml* | *lodestar-cl-only.yml* )
var="LS_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache consensus
fi
;;
*nimbus.yml* | *nimbus-allin1.yml* | *nimbus-cl-only.yml* )
var="NIM_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache consensus
fi
;;
*prysm.yml* | *prysm-cl-only.yml* )
var="PRYSM_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache consensus
fi
;;
*grandine.yml* | *grandine-allin1.yml* | *grandine-cl-only.yml* )
var="GRANDINE_DOCKERFILE"
build=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
if [ "${build}" = "Dockerfile.source" ]; then
docompose build --pull --no-cache consensus
fi
;;
esac
}
migrate_compose_file() {
# When this gets called $var is COMPOSE_FILE and $value is what is set in .env for it
# Some files have been renamed and others removed altogether
FROM_YML=( )
TO_YML=( )
IFS=":"
set -o noglob
# Globbing is off
# shellcheck disable=SC2206
__ymlarray=($value) # split+glob with glob disabled, and split using : as delimiter
set +o noglob
# Unset restores default
unset IFS
value=""
for n in "${!__ymlarray[@]}"; do
__ymlfile="${__ymlarray[n]}"
for index in "${!FROM_YML[@]}"; do
if [ "${FROM_YML[index]}" = "${__ymlfile}" ]; then
__ymlfile=${TO_YML[index]}
break
fi
done
if [ -n "${__ymlfile}" ]; then
if [ -z "${value}" ]; then
value="${__ymlfile}"
else
value="${value}:${__ymlfile}"
fi
fi
done
}
ssv_switch() {
echo "Detected legacy SSV Node. Migrating config to new testnet."
echo
echo "Stopping SSV Node container"
__node=$(dodocker ps --format '{{.Names}}' | grep 'ssv2-node')
dodocker stop "${__node}" && dodocker rm -f "${__node}"
dodocker volume rm "$(dodocker volume ls -q | grep "$(basename "$(realpath .)")"_ssv2-data)"
echo
echo "SSV Node stopped and database deleted."
echo
cp blox-ssv-config.yaml blox-ssv-config.yaml.bak
cp blox-ssv-config.yaml ssv-config/config.yaml
rm blox-ssv-config.yaml
echo "Backup copy blox-ssv-config.yaml.bak created"
echo "Making changes to ssv-config/config.yaml"
var="NETWORK"
NETWORK=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
sed -i'.original' 's/blox-ssv2.yml/ssv.yml/' "${ENV_FILE}".source
if ! grep -q "LogFilePath:" ssv-config/config.yaml; then
# macOS-isms: Newline for sed add
sed -i'.original' '/global:/a\
LogFilePath: /tmp/ssv/debug.log
' ssv-config/config.yaml
fi
if ! grep -q "MetricsAPIPort:" ssv-config/config.yaml; then
sed -i'.original' '$a\
MetricsAPIPort: 15000
' ssv-config/config.yaml
fi
if ! grep -q "ssv:" ssv-config/config.yaml; then
sed -i'.original' '/^ Network:/d' ssv-config/config.yaml # Remove old eth2 Network line if present
sed -i'.original' '$a\
ssv:
' ssv-config/config.yaml
if [ "${NETWORK}" = "holesky" ]; then
sed -i'.original' '$a\
Network: holesky
' ssv-config/config.yaml
elif [ "${NETWORK}" = "mainnet" ]; then
sed -i'.original' '$a\
Network: mainnet
' ssv-config/config.yaml
else
echo "${NETWORK} is not something that works with SSV."
echo "Please fix this manually before running $__me update again."
echo "Aborting."
exit 1
fi
fi
rm ssv-config/config.yaml.original
}
delete_reth() {
# Check for Reth
var="COMPOSE_FILE"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
# I do mean to match literally
# shellcheck disable=SC2076
if [[ ! "${value}" =~ "reth.yml" ]]; then
return 0
fi
# Check Reth version, only continue if not on alpha
var="RETH_DOCKER_TAG"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
# I do mean to match literally
# shellcheck disable=SC2076
if [[ "${value}" =~ "alpha" ]]; then
return 0
fi
if [ -z "$(dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]reth-el-data")" ]; then # No Reth volume
return 0
fi
# Check Reth db version
__db_version="$(dodocker run --rm -v "$(dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]reth-el-data")":"/var/lib/reth" \
alpine:3 cat /var/lib/reth/db/database.version)"
if [ "${__db_version}" -ne "1" ]; then
return 0
fi
echo "Detected Reth. For Reth beta, it will need to be re-synced from scratch."
echo
if [ "${__non_interactive:-0}" -eq 0 ]; then
while true; do
read -rp "WARNING - About to delete the Reth database. Do you wish to continue? (Y/n) " yn
case $yn in
[Nn]o | [Nn] ) echo "No changes made"; return 0;;
* ) break;;
esac
done
fi
echo "Stopping Reth container"
docompose stop execution && docompose rm -f execution
dodocker volume rm "$(dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]reth-el-data")"
echo
echo "Reth stopped and database deleted."
echo
}
delete_erigon() {
# Enable this when Erigon v3 is out
if true; then
return 0
fi
# Check for Erigon
var="COMPOSE_FILE"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
# I do mean to match literally
# shellcheck disable=SC2076
if [[ ! "${value}" =~ "erigon.yml" ]]; then
return 0
fi
# Check Erigon version, only continue if v3
var="ERIGON_DOCKER_TAG"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
# I do mean to match literally
# shellcheck disable=SC2076
if [[ ! ("${value}" =~ "v3" || "${value}" = "stable") ]]; then
return 0
fi
if [ -z "$(dodocker volume ls -q -f "name=erigon-el-data")" ]; then # No Erigon volume
return 0
fi
# https://discord.com/channels/687972960811745322/886550095749873666/1068994749480054866
# Detect Erigon v3 by files in snapshots/history
if [ -n "$(dodocker run --rm -v "$(dodocker volume ls -q -f "name=erigon-el-data")":"/var/lib/erigon" \
alpine:3 ls /var/lib/erigon/snapshots/history)" ]; then
return 0 # Files in snapshots/history means it's v3
fi
echo "Detected Erigon. For Erigon v3, it will need to be re-synced from scratch."
echo
while true; do
read -rp "WARNING - About to delete the Erigon database. Do you wish to continue? (Y/n) " yn
case $yn in
[Nn]o | [Nn] ) echo "Aborting, no changes made"; exit 130;;
* ) break;;
esac
done
echo "Stopping Erigon container"
docompose stop execution && docompose rm -f execution
dodocker volume rm "$(dodocker volume ls -q -f "name=erigon-el-data")"
echo
echo "Erigon stopped and database deleted."
echo
}
upgrade_postgres() {
# Check for web3signer
var="COMPOSE_FILE"
value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
# I do mean to match literally
# shellcheck disable=SC2076
if [[ ! "${value}" =~ "web3signer.yml" ]]; then
return 0
fi
__source_vol="$(basename "$(pwd)")_web3signer-slashing-data"
if [ -z "$(dodocker volume ls -q -f "name=${__source_vol}")" ]; then
return 0
fi
__target_pg=16
__during_postgres=1
__source_pg="$(dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/data" \
alpine:3 cat /var/lib/postgresql/data/PG_VERSION)"
if [ "${__source_pg}" -lt "${__target_pg}" ]; then
echo "Web3signer is using PostgreSQL ${__source_pg}. The current version is PostgreSQL ${__target_pg}."
echo
if [ "${__non_interactive:-0}" -eq 0 ]; then
while true; do
read -rp "Would you like to migrate to PostgreSQL ${__target_pg}? (Y/n) " yn
case $yn in
[Nn]o | [Nn] ) echo "Keeping PostgreSQL at version ${__source_pg}"; return 0;;
* ) break;;
esac
done
fi
else
return 0
fi
__source_size="$(dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/data" \
alpine:3 du -s /var/lib/postgresql/data/ | awk '{print $1}')"
re='^[0-9]+$'
if ! [[ "${__source_size}" =~ $re ]] ; then
echo "Unable to determine database size. This is likely a bug."
echo "__source_size is ${__source_size}"
return 70
fi
__get_docker_free_space
if [[ "${__free_space}" -lt $(( (__source_size * 2) + 10485760 )) ]]; then
echo
echo "You don't have enough free space to migrate the database."
echo "It is $(( __source_size / 1024 / 1024 )) GiB in size and you need twice as much free again."
echo
__display_docker_dir
echo
return
fi
__migrated_vol="$(basename "$(pwd)")_web3signer-slashing-data-pg${__target_pg}-migrated"
__backup_vol="$(basename "$(pwd)")_web3signer-slashing-data-pg${__source_pg}-backup"
echo "Stopping Web3signer"
docompose stop web3signer && docompose rm -f web3signer
echo "Stopping PostgreSQL"
docompose stop postgres && docompose rm -f postgres
echo
echo "Migrating database from PostgreSQL ${__source_pg} to PostgreSQL ${__target_pg}"
echo "If this step fails, the Web3signer slashing protection database is no longer protecting you."
echo "In failure case, do not start Web3signer again, instead seek help on Ethstaker Discord."
echo
dodocker pull "pats22/postgres-upgrade:${__source_pg}-to-${__target_pg}"
dodocker volume create "${__migrated_vol}"
dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/${__source_pg}/data" \
-v "${__migrated_vol}":"/var/lib/postgresql/${__target_pg}/data" \
"pats22/postgres-upgrade:${__source_pg}-to-${__target_pg}"
# Adjust ownership. We use 70; postgres-upgrade creates it with 999
dodocker run --rm -v "${__migrated_vol}":"/var/lib/postgres" \
alpine:3 chown -R 70:70 /var/lib/postgres
# Conversion can leave us with a pg_hba.conf that does not allow connections
dodocker run --rm -v "${__migrated_vol}":"/var/lib/postgres" \
alpine:3 sh -c 'grep -qxE "host\s+all\s+all\s+all\s+scram-sha-256" /var/lib/postgres/pg_hba.conf \
|| echo "host all all all scram-sha-256" \
>> /var/lib/postgres/pg_hba.conf'
echo
echo "Migration complete, copying data in web3signer-slashing-data volume to backup"
dodocker volume create "${__backup_vol}"
dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/data" \
-v "${__backup_vol}":"/var/lib/postgresql/${__source_pg}/data" \
alpine:3 cp -a /var/lib/postgresql/data/. "/var/lib/postgresql/${__source_pg}/data/"
__during_migrate=1
echo "Moving migrated data to web3signer-slashing-data volume"
dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/data" \
alpine:3 rm -rf /var/lib/postgresql/data/*
dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/data" \
-v "${__migrated_vol}":"/var/lib/postgresql/${__target_pg}/data" \
alpine:3 cp -a "/var/lib/postgresql/${__target_pg}/data/." /var/lib/postgresql/data/
__migrated=1
dodocker volume remove "${__migrated_vol}"
echo
echo "Adjusting PostgreSQL Docker tag"
if [ ! -f "${ENV_FILE}.source" ]; then # update() didn't migrate env, let's make sure .env.source exists
cp "${ENV_FILE}" "${ENV_FILE}.source"
fi
var="PG_DOCKER_TAG"
# This gets used, but shellcheck doesn't recognize that
# shellcheck disable=SC2034
PG_DOCKER_TAG=${__target_pg}-bookworm # To bookworm to avoid collation errors - also a faster PostgreSQL
set_value_in_env
echo "Web3signer has been stopped. You'll need to run \"$__me up\" to start it again."
echo
echo "A copy of your old slashing protection database is in the Docker volume ${__backup_vol}."
echo "Confirm that everything works, and then delete it with \"docker volume rm ${__backup_vol}\"."
__during_postgres=0
}
__lookup_cf_zone() { # Migrates traefik-cf setup to use Zone ID
__compose_ymls=$(sed -n -e "s/^COMPOSE_FILE=\(.*\)/\1/p" "${ENV_FILE}.source" || true)
__dns_token=$(sed -n -e "s/^CF_DNS_API_TOKEN=\(.*\)/\1/p" "${ENV_FILE}.source" || true)
__zone_token=$(sed -n -e "s/^CF_ZONE_API_TOKEN=\(.*\)/\1/p" "${ENV_FILE}.source" || true)
__domain=$(sed -n -e "s/^DOMAIN=\(.*\)/\1/p" "${ENV_FILE}.source" || true)
if [[ ! $__compose_ymls =~ traefik-cf.yml ]]; then
value=""
return
elif [[ -n $__dns_token ]]; then
if [[ -n $__zone_token ]]; then
__token=$__zone_token
else
__token=$__dns_token
fi
set +e
value=$(docompose run --rm curl-jq sh -c \
"curl -s \"https://api.cloudflare.com/client/v4/zones?name=${__domain}\" -H \"Authorization: Bearer ${__token}\" \
-H \"Content-Type: application/json\" | jq -r '.result[0].id'" | tail -n 1)
__code=$?
if [[ "$__code" -ne 0 ]]; then
value=""
return
fi
__success=$(docompose run --rm curl-jq sh -c \
"curl -s \"https://api.cloudflare.com/client/v4/zones?name=${__domain}\" -H \"Authorization: Bearer ${__token}\" \
-H \"Content-Type: application/json\" | jq -r '.success'" | tail -n 1)
set -e
if [ "${__success}" = "true" ]; then
return
else
value=""
return
fi
else
value=""
return
fi
}
envmigrate() {
if [ ! -f "${ENV_FILE}" ]; then
return 0
fi
ALL_VARS=( COMPOSE_FILE FEE_RECIPIENT EL_NODE GRAFFITI DEFAULT_GRAFFITI NETWORK MEV_BOOST MEV_RELAYS MEV_MIN_BID \
MEV_NODE CL_MAX_PEER_COUNT CL_MIN_PEER_COUNT EL_MAX_PEER_COUNT EL_MIN_PEER_COUNT DOMAIN ACME_EMAIL ANCIENT_DIR \
AUTOPRUNE_NM LOGS_LABEL CF_DNS_API_TOKEN CF_ZONE_API_TOKEN CF_ZONE_ID AWS_PROFILE AWS_HOSTED_ZONE_ID \
GRAFANA_HOST SIREN_HOST DISTRIBUTED BESU_HEAP TEKU_HEAP PROM_HOST HOST_IP SHARE_IP PRYSM_HOST EE_HOST \
EL_HOST EL_LB EL_WS_HOST EL_WS_LB CL_HOST CL_LB VC_HOST DDNS_SUBDOMAIN IPV6 DDNS_PROXY RAPID_SYNC_URL \
CL_NODE BEACON_STATS_API BEACON_STATS_MACHINE EL_P2P_PORT CL_P2P_PORT WEB3SIGNER PRYSM_PORT DOPPELGANGER \
PRYSM_UDP_PORT CL_QUIC_PORT GRAFANA_PORT SIREN_PORT PROMETHEUS_PORT KEY_API_PORT TRAEFIK_WEB_PORT \
TRAEFIK_WEB_HTTP_PORT CL_REST_PORT EL_RPC_PORT EL_WS_PORT EE_PORT ERIGON_TORRENT_PORT LOG_LEVEL JWT_SECRET \
EL_EXTRAS CL_EXTRAS VC_EXTRAS ARCHIVE_NODE SSV_P2P_PORT SSV_P2P_PORT_UDP ERIGON_P2P_PORT_2 \
ERIGON_P2P_PORT_3 LODESTAR_HEAP SSV_DKG_PORT )
TARGET_VARS=( ETH_DOCKER_TAG NIM_SRC_BUILD_TARGET NIM_SRC_REPO NIM_DOCKER_TAG NIM_DOCKER_VC_TAG NIM_DOCKER_REPO \
NIM_DOCKER_VC_REPO NIM_DOCKERFILE TEKU_SRC_BUILD_TARGET TEKU_SRC_REPO TEKU_DOCKER_TAG TEKU_DOCKER_REPO \
TEKU_DOCKERFILE LH_SRC_BUILD_TARGET LH_SRC_REPO LH_DOCKER_TAG LH_DOCKER_REPO LH_DOCKERFILE \
PRYSM_SRC_BUILD_TARGET PRYSM_SRC_REPO PRYSM_DOCKER_TAG PRYSM_DOCKER_VC_TAG PRYSM_DOCKER_CTL_TAG \
PRYSM_DOCKER_REPO PRYSM_DOCKER_VC_REPO PRYSM_DOCKER_CTL_REPO PRYSM_DOCKERFILE ERIGON_SRC_BUILD_TARGET \
ERIGON_SRC_REPO ERIGON_DOCKER_TAG ERIGON_DOCKER_REPO ERIGON_DOCKERFILE MEV_SRC_BUILD_TARGET MEV_SRC_REPO \
MEV_DOCKERFILE MEV_DOCKER_TAG MEV_DOCKER_REPO NIMEL_SRC_BUILD_TARGET NIMEL_SRC_REPO NIMEL_DOCKER_TAG \
NIMEL_DOCKER_REPO NIMEL_DOCKERFILE LS_SRC_BUILD_TARGET LS_SRC_REPO LS_DOCKER_TAG LS_DOCKER_REPO LS_DOCKERFILE \
GETH_SRC_BUILD_TARGET GETH_SRC_REPO GETH_DOCKER_TAG GETH_DOCKER_REPO TRAEFIK_TAG DDNS_TAG \
GETH_DOCKERFILE NM_SRC_BUILD_TARGET NM_SRC_REPO NM_DOCKER_TAG NM_DOCKER_REPO NM_DOCKERFILE \
BESU_SRC_BUILD_TARGET BESU_SRC_REPO BESU_DOCKER_TAG BESU_DOCKER_REPO BESU_DOCKERFILE SSV_NODE_TAG \
DEPCLI_SRC_BUILD_TARGET DEPCLI_SRC_REPO DEPCLI_DOCKER_TAG W3S_DOCKER_TAG W3S_DOCKER_REPO \
PG_DOCKER_TAG RETH_SRC_BUILD_TARGET RETH_SRC_REPO RETH_DOCKER_TAG RETH_DOCKER_REPO RETH_DOCKERFILE \
GRANDINE_SRC_BUILD_TARGET GRANDINE_SRC_REPO GRANDINE_DOCKER_TAG GRANDINE_DOCKER_REPO GRANDINE_DOCKERFILE \
SIREN_DOCKER_TAG SIREN_DOCKER_REPO SSV_DKG_TAG NODE_EXPORTER_IGNORE_MOUNT_REGEX )
OLD_VARS=( )
NEW_VARS=( )
var=ENV_VERSION
__target_ver=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "default.env" || true)
__source_ver=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true)
# Aggressive prune to work around Docker grabbing old clients. Here so it doesn't get called during config
if [[ "${__source_ver}" -lt "9" ]]; then
dodocker system prune --force -a
fi
if [[ "${__keep_targets}" -eq 1 && "${__target_ver}" -le "${__source_ver}" ]]; then # No changes in template, do nothing
return 0
fi
if [ "${__keep_targets}" -eq 0 ]; then