diff --git a/ethd b/ethd index f68103f8..94435286 100755 --- a/ethd +++ b/ethd @@ -9,19 +9,19 @@ __compose_exe="docker compose" __compose_upgraded=0 -dodocker() { +__dodocker() { $__docker_sudo $__docker_exe "$@" } -docompose() { +__docompose() { # I want word splitting here # shellcheck disable=SC2086 $__docker_sudo $__compose_exe "$@" } -determine_distro() { +__determine_distro() { # Determine OS platform __uname=$(uname | tr "[:upper:]" "[:lower:]") # If Linux, try to determine specific distribution @@ -70,12 +70,12 @@ determine_distro() { } -handle_docker_sudo() { +__handle_docker_sudo() { set +e if [[ "$__distro" =~ "debian" || "$__distro" = "ubuntu" ]]; then systemctl status docker >/dev/null - result=$? - if [ ! "${result}" -eq 0 ]; then + __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." @@ -104,7 +104,7 @@ handle_docker_sudo() { } -handle_root() { +__handle_root() { __cannot_sudo=0 if [ "${EUID}" -eq 0 ]; then __as_owner="sudo -u ${OWNER}" @@ -121,7 +121,7 @@ handle_root() { } -upgrade_compose() { +__upgrade_compose() { if ! type -P docker-compose >/dev/null 2>&1; then echo "Docker Compose has already been updated to V2" return @@ -177,7 +177,7 @@ upgrade_compose() { } -check_compose_version() { +__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") @@ -199,10 +199,10 @@ check_compose_version() { 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 + 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;; + * ) __upgrade_compose; break;; esac done fi @@ -210,7 +210,7 @@ check_compose_version() { } -prep_conffiles() { +__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" @@ -247,7 +247,7 @@ prep_conffiles() { } -check_for_snap() { +__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." @@ -267,7 +267,7 @@ check_for_snap() { } -install-bash-completions() { +__install_bash_completions() { if [[ "$OSTYPE" == "darwin"* ]]; then echo "Skipping installation of tab completions (not supported on macOS)" else @@ -297,8 +297,8 @@ install() { 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 +continue? (no/yes) " __yn + case $__yn in [Yy]* ) ;; * ) echo "Aborting, no changes made"; return 0;; esac @@ -336,8 +336,8 @@ continue? (no/yes) " yn 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 +continue? (no/yes) " __yn + case $__yn in [Yy]* ) ;; * ) echo "Aborting, no changes made"; return 0;; esac @@ -372,11 +372,11 @@ continue? (no/yes) " yn fi # We only get here on Ubuntu or Debian - install-bash-completions + __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 + read -rp "Do you want to be able to call 'ethd' from anywhere? (yes/no) " __yn + case $__yn in [Nn]* ) return 0;; * ) ;; esac @@ -398,17 +398,17 @@ continue? (no/yes) " yn __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)}') + __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}}') + __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 + __regex='^[0-9]+$' + if ! [[ "${__free_space}" =~ $__regex ]] ; 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}" + 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 @@ -420,7 +420,7 @@ __get_docker_free_space() { # set __free_space to what's available to Docker __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 + __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}" @@ -430,12 +430,12 @@ __display_docker_dir() { __display_docker_volumes() { echo - if [ -z "$(dodocker volume ls -q -f "name=^$(basename "$(realpath .)")_[^_]+")" ]; then + 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]}")")")" + __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\"." @@ -461,15 +461,15 @@ space() { # Warn user if space is low, so they can prune -check_disk_space() { +__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) + __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 @@ -483,10 +483,10 @@ check_disk_space() { # Literal match intended # shellcheck disable=SC2076 - if [[ "${value}" =~ "nethermind.yml" ]] && [[ "${__free_space}" -lt "${__min_free}" ]]; then + 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 + 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 @@ -495,14 +495,14 @@ Full\". Free space:" echo __display_docker_dir __display_docker_volumes - elif [[ "${value}" =~ "geth.yml" ]] && [[ "${__free_space}" -lt 104857600 ]]; then + 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 + 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 @@ -522,158 +522,158 @@ Full\". Free space:" } -source_build() { +__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) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) - case "${value}" in + case "${__value}" in *deposit-cli.yml* ) - docompose --profile tools build --pull --no-cache deposit-cli-new + __docompose --profile tools build --pull --no-cache deposit-cli-new ;; esac - case "${value}" in + 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 + __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 + 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 + __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 + __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 + __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 + __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 + __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 + __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 + 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 + __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 + __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 + __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 + __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 + __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 + __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 +__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=( ) + __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 + __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]} + __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}" + if [ -z "${__value}" ]; then + __value="${__ymlfile}" else - value="${value}:${__ymlfile}" + __value="${__value}:${__ymlfile}" fi fi done } -ssv_switch() { +__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)" + __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 @@ -682,9 +682,9 @@ ssv_switch() { 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 + __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\ @@ -720,31 +720,31 @@ MetricsAPIPort: 15000 } -delete_reth() { +__delete_reth() { # Check for Reth - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __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 + 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) + __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 + if [[ "${__value}" =~ "alpha" ]]; then return 0 fi - if [ -z "$(dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]reth-el-data")" ]; then # No Reth volume + 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" \ + __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 @@ -754,8 +754,8 @@ delete_reth() { 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 + 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 @@ -763,40 +763,40 @@ delete_reth() { 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")" + __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() { +__delete_erigon() { # Check for Erigon - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __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 + 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) + __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}" = "latest" || "${value}" = "stable") ]]; then # No stable yet - if [[ ! ("${value}" =~ "v3" || "${value}" = "latest") ]]; then +# if [[ ! ("${__value}" =~ "v3" || "${__value}" = "latest" || "${__value}" = "stable") ]]; then # No stable yet + if [[ ! ("${__value}" =~ "v3" || "${__value}" = "latest") ]]; then return 0 fi - if [ -z "$(dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]erigon-el-data")" ]; then # No Erigon volume + if [ -z "$(__dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]erigon-el-data")" ]; then # No Erigon volume return 0 fi # Detect Erigon v3 by directory caplin/latest - __erigon_v3=$(dodocker run --rm -v "$(dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]erigon-el-data")":"/var/lib/erigon" \ + __erigon_v3=$(__dodocker run --rm -v "$(__dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]erigon-el-data")":"/var/lib/erigon" \ alpine:3 sh -c 'if [ -d "/var/lib/erigon/caplin/latest" ]; then echo true; else echo false; fi') if [ "$__erigon_v3" = "true" ]; then return 0 @@ -805,41 +805,41 @@ delete_erigon() { 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 + 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=$(basename "$(realpath .)")[_-]erigon-el-data")" + __docompose stop execution && __docompose rm -f execution + __dodocker volume rm "$(__dodocker volume ls -q -f "name=$(basename "$(realpath .)")[_-]erigon-el-data")" echo echo "Erigon stopped and database deleted." echo } -upgrade_postgres() { +__upgrade_postgres() { # Check for web3signer - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __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 + 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 + 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" \ + __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 @@ -847,8 +847,8 @@ upgrade_postgres() { 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 + 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 @@ -858,11 +858,11 @@ upgrade_postgres() { return 0 fi - __source_size="$(dodocker run --rm -v "${__source_vol}":"/var/lib/postgresql/data" \ + __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 + __regex='^[0-9]+$' + if ! [[ "${__source_size}" =~ $__regex ]] ; then echo "Unable to determine database size. This is likely a bug." echo "__source_size is ${__source_size}" return 70 @@ -884,9 +884,9 @@ upgrade_postgres() { __backup_vol="$(basename "$(pwd)")_web3signer-slashing-data-pg${__source_pg}-backup" echo "Stopping Web3signer" - docompose stop web3signer && docompose rm -f web3signer + __docompose stop web3signer && __docompose rm -f web3signer echo "Stopping PostgreSQL" - docompose stop postgres && docompose rm -f postgres + __docompose stop postgres && __docompose rm -f postgres echo echo "Migrating database from PostgreSQL ${__source_pg} to PostgreSQL ${__target_pg}" @@ -894,48 +894,48 @@ upgrade_postgres() { 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" \ + __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" \ + __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" \ + __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" \ + __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" \ + __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" \ + __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}" + __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" + 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" + __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 + __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}." @@ -945,12 +945,12 @@ upgrade_postgres() { __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) + __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="" + __value="" return elif [[ -n $__dns_token ]]; then if [[ -n $__zone_token ]]; then @@ -959,37 +959,37 @@ __lookup_cf_zone() { # Migrates traefik-cf setup to use Zone ID __token=$__dns_token fi set +e - value=$(docompose run --rm curl-jq sh -c \ + __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="" + __value="" return fi - __success=$(docompose run --rm curl-jq sh -c \ + __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="" + __value="" return fi else - value="" + __value="" return fi } -envmigrate() { - if [ ! -f "${ENV_FILE}" ]; then +__env_migrate() { + 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 \ + __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 \ @@ -999,7 +999,7 @@ envmigrate() { 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 SIREN_PASSWORD ) - TARGET_VARS=( ETH_DOCKER_TAG NIM_SRC_BUILD_TARGET NIM_SRC_REPO NIM_DOCKER_TAG NIM_DOCKER_VC_TAG NIM_DOCKER_REPO \ + __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 \ @@ -1015,23 +1015,23 @@ envmigrate() { 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=( ) + __old_vars=( ) + __new_vars=( ) # Always make sure we have a SIREN password - var="SIREN_PASSWORD" - SIREN_PASSWORD=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="SIREN_PASSWORD" + SIREN_PASSWORD=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) if [ -z "${SIREN_PASSWORD}" ]; then SIREN_PASSWORD=$(head -c 8 /dev/urandom | od -A n -t u8 | tr -d '[:space:]' | sha256sum | head -c 32) - set_value_in_env + __set_value_in_env fi - 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) + __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 + __dodocker system prune --force -a fi if [[ "${__keep_targets}" -eq 1 && "${__target_ver}" -le "${__source_ver}" ]]; then # No changes in template, do nothing @@ -1039,111 +1039,111 @@ envmigrate() { fi if [ "${__keep_targets}" -eq 0 ]; then - echo "Refreshing build targets in ${ENV_FILE}" + echo "Refreshing build targets in ${__env_file}" else - echo "Migrating ${ENV_FILE} to version ${__target_ver}" + echo "Migrating ${__env_file} to version ${__target_ver}" fi - ${__as_owner} cp "${ENV_FILE}" "${ENV_FILE}".source + ${__as_owner} cp "${__env_file}" "${__env_file}".source __during_migrate=1 __migrated=1 - ${__as_owner} cp default.env "${ENV_FILE}" + ${__as_owner} cp default.env "${__env_file}" - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}.source" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}.source" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ "${value}" =~ "blox-ssv2.yml" ]]; then - ssv_switch + if [[ "${__value}" =~ "blox-ssv2.yml" ]]; then + __ssv_switch fi # Migrate over user settings - for var in "${ALL_VARS[@]}"; do - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}.source" || true) - if [ -n "${value}" ] || [ "${var}" = "GRAFFITI" ] || [ "${var}" = "MEV_RELAYS" ] \ - || [ "${var}" = "ETH_DOCKER_TAG" ] || [ "${var}" = "RAPID_SYNC_URL" ]; then - if [ "${var}" = "COMPOSE_FILE" ]; then - migrate_compose_file + for __var in "${__all_vars[@]}"; do + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}.source" || true) + if [ -n "${__value}" ] || [ "${__var}" = "GRAFFITI" ] || [ "${__var}" = "MEV_RELAYS" ] \ + || [ "${__var}" = "ETH_DOCKER_TAG" ] || [ "${__var}" = "RAPID_SYNC_URL" ]; then + if [ "${__var}" = "COMPOSE_FILE" ]; then + __migrate_compose_file fi - if [ "${var}" = "CL_QUIC_PORT" ]; then - __cl_port=$(sed -n -e "s/^CL_P2P_PORT=\(.*\)/\1/p" "${ENV_FILE}.source" || true) - if [ -n "${__cl_port}" ] && [ "${__cl_port}" = "${value}" ]; then - value=$((value + 1)) - echo "Adjusted CL_QUIC_PORT to ${value} so it does not conflict with CL_P2P_PORT" + if [ "${__var}" = "CL_QUIC_PORT" ]; then + __cl_port=$(sed -n -e "s/^CL_P2P_PORT=\(.*\)/\1/p" "${__env_file}.source" || true) + if [ -n "${__cl_port}" ] && [ "${__cl_port}" = "${__value}" ]; then + __value=$((__value + 1)) + echo "Adjusted CL_QUIC_PORT to ${__value} so it does not conflict with CL_P2P_PORT" fi - __prysm_port=$(sed -n -e "s/^PRYSM_UDP_PORT=\(.*\)/\1/p" "${ENV_FILE}.source" || true) - if [ -n "${__prysm_port}" ] && [ "${__prysm_port}" = "${value}" ]; then # just in case this is one ahead - value=$((value + 1)) - echo "Adjusted CL_QUIC_PORT to ${value} so it does not conflict with PRYSM_UDP_PORT" + __prysm_port=$(sed -n -e "s/^PRYSM_UDP_PORT=\(.*\)/\1/p" "${__env_file}.source" || true) + if [ -n "${__prysm_port}" ] && [ "${__prysm_port}" = "${__value}" ]; then # just in case this is one ahead + __value=$((__value + 1)) + echo "Adjusted CL_QUIC_PORT to ${__value} so it does not conflict with PRYSM_UDP_PORT" fi fi # Literal match intended # shellcheck disable=SC2076 - if [[ "${var}" = "RAPID_SYNC_URL" && "${value}" =~ "eth2-beacon-mainnet.infura.io" ]]; then - value="https://beaconstate.info" + if [[ "${__var}" = "RAPID_SYNC_URL" && "${__value}" =~ "eth2-beacon-mainnet.infura.io" ]]; then + __value="https://beaconstate.info" fi - if [[ "${var}" = "HOST_IP" && "${value: -1}" = ":" ]]; then - value="${value%:}" # Undo Compose V1 accommodation + if [[ "${__var}" = "HOST_IP" && "${__value: -1}" = ":" ]]; then + __value="${__value%:}" # Undo Compose V1 accommodation fi - if [[ "${var}" = "SHARE_IP" && "${value: -1}" = ":" ]]; then - value="${value%:}" # Undo Compose V1 accommodation + if [[ "${__var}" = "SHARE_IP" && "${__value: -1}" = ":" ]]; then + __value="${__value%:}" # Undo Compose V1 accommodation fi # Handle & in GRAFFITI gracefully - sed -i'.original' -e "s~^\(${var}\s*=\s*\).*\$~\1${value//&/\\&}~" "${ENV_FILE}" - else # empty value - if [ "${var}" = "CF_ZONE_ID" ]; then + sed -i'.original' -e "s~^\(${__var}\s*=\s*\).*\$~\1${__value//&/\\&}~" "${__env_file}" + else # empty __value + if [ "${__var}" = "CF_ZONE_ID" ]; then __lookup_cf_zone - if [ -n "${value}" ]; then - sed -i'.original' -e "s~^\(${var}\s*=\s*\).*\$~\1${value//&/\\&}~" "${ENV_FILE}" + if [ -n "${__value}" ]; then + sed -i'.original' -e "s~^\(${__var}\s*=\s*\).*\$~\1${__value//&/\\&}~" "${__env_file}" fi fi fi done if [ "${__keep_targets}" -eq 1 ]; then # Migrate over build targets - for var in "${TARGET_VARS[@]}"; do - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}.source" || true) - if [ -n "${value}" ]; then - if [[ "${var}" = "DDNS_TAG" && "${__source_ver}" -lt "8" ]]; then # Switch to ddns-updater - value="v2" + for __var in "${__target_vars[@]}"; do + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}.source" || true) + if [ -n "${__value}" ]; then + if [[ "${__var}" = "DDNS_TAG" && "${__source_ver}" -lt "8" ]]; then # Switch to ddns-updater + __value="v2" fi - if [[ "${var}" = "LH_DOCKER_TAG" && "${value}" = "latest-modern" ]]; then # LH 5.2 ditched latest-modern - value="latest" + if [[ "${__var}" = "LH_DOCKER_TAG" && "${__value}" = "latest-modern" ]]; then # LH 5.2 ditched latest-modern + __value="latest" fi - if [[ "${var}" = "ERIGON_DOCKER_TAG" && "${value}" = "stable" ]]; then # Erigon ditched stable - value="v2.60.1" + if [[ "${__var}" = "ERIGON_DOCKER_TAG" && "${__value}" = "stable" ]]; then # Erigon ditched stable + __value="v2.60.6" fi - sed -i'.original' -e "s~^\(${var}\s*=\s*\).*$~\1${value}~" "${ENV_FILE}" + 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=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}.source" || true) - if [ -n "${value}" ]; then - sed -i'.original' -e "s~^\(${NEW_VARS[index]}\s*=\s*\).*$~\1${value}~" "${ENV_FILE}" + for __index in "${!__old_vars[@]}"; do + __var=${__old_vars[__index]} + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}.source" || true) + if [ -n "${__value}" ]; then + sed -i'.original' -e "s~^\(${__new_vars[__index]}\s*=\s*\).*$~\1${__value}~" "${__env_file}" fi done # Check whether we run a CL or VC, if so nag about FEE_RECIPIENT - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # It's CL&VC, CL-only, or VC-only # I do mean to match literally # shellcheck disable=SC2076 - if [[ "${value}" =~ "prysm.yml" || "${value}" =~ "lighthouse.yml" || "${value}" =~ "teku.yml" \ - || "${value}" =~ "nimbus.yml" || "${value}" =~ "lodestar.yml" || "${value}" =~ "-cl-only.yml" \ - || "${value}" =~ "-allin1.yml" || "${value}" =~ "-vc-only.yml" ]]; then + if [[ "${__value}" =~ "prysm.yml" || "${__value}" =~ "lighthouse.yml" || "${__value}" =~ "teku.yml" \ + || "${__value}" =~ "nimbus.yml" || "${__value}" =~ "lodestar.yml" || "${__value}" =~ "-cl-only.yml" \ + || "${__value}" =~ "-allin1.yml" || "${__value}" =~ "-vc-only.yml" ]]; then # Check for rewards - var="FEE_RECIPIENT" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [[ -z "${value}" || ${value} != 0x* || ${#value} -ne 42 ]]; then + __var="FEE_RECIPIENT" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [[ -z "${__value}" || ${__value} != 0x* || ${#__value} -ne 42 ]]; then if [ "${__non_interactive:-0}" -eq 0 ]; then whiptail --msgbox "A fee recipient ETH wallet address is required in order to start the client. This is \ for priority fees and, optionally, MEV. Please enter a valid ETH address in the next screen. Refer to \ Eth Docker docs (https://ethdocker.com/About/Rewards) for more information.\n\nCAUTION: \"$__me up\" will fail if no \ valid address is set" 12 75 - query_coinbase - set_value_in_env + __query_coinbase + __set_value_in_env else echo "A fee recipient ETH wallet address is required in order to start the client. Please set one in \".env\"." echo "CAUTION: \"$__me up\" will fail if no valid address is set." @@ -1152,48 +1152,48 @@ envmigrate() { fi # User signals it's a distributed setup and not to nag - var="DISTRIBUTED" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [[ "${value}" = "true" || "${__non_interactive:-0}" -eq 1 ]]; then - ${__as_owner} rm "${ENV_FILE}".original + __var="DISTRIBUTED" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [[ "${__value}" = "true" || "${__non_interactive:-0}" -eq 1 ]]; then + ${__as_owner} rm "${__env_file}".original __during_migrate=0 return 0 fi # Check for CL and EL, nag if we have only one without the other - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Case 1 ... CL, do we have an EL? # I do mean to match literally # shellcheck disable=SC2076 - if [[ "${value}" =~ "prysm.yml" || "${value}" =~ "lighthouse.yml" || "${value}" =~ "teku.yml" \ - || "${value}" =~ "nimbus.yml" || "${value}" =~ "lodestar.yml" || "${value}" =~ "-cl-only.yml" \ - || "${value}" =~ "-allin1.yml" ]]; then - if [[ ! "${value}" =~ "geth.yml" && ! "${value}" =~ "besu.yml" && ! "${value}" =~ "erigon.yml" \ - && ! "${value}" =~ "nethermind.yml" && ! "${value}" =~ "nimbus-el.yml" \ - && ! "${value}" =~ "reth.yml" ]]; then + if [[ "${__value}" =~ "prysm.yml" || "${__value}" =~ "lighthouse.yml" || "${__value}" =~ "teku.yml" \ + || "${__value}" =~ "nimbus.yml" || "${__value}" =~ "lodestar.yml" || "${__value}" =~ "-cl-only.yml" \ + || "${__value}" =~ "-allin1.yml" ]]; then + if [[ ! "${__value}" =~ "geth.yml" && ! "${__value}" =~ "besu.yml" && ! "${__value}" =~ "erigon.yml" \ + && ! "${__value}" =~ "nethermind.yml" && ! "${__value}" =~ "nimbus-el.yml" \ + && ! "${__value}" =~ "reth.yml" ]]; then whiptail --msgbox "An Execution Layer client is required alongside your Consensus Layer client since \ Ethereum Merge.\n\nIf you run a distributed setup, you can shut off this nag screen by setting DISTRIBUTED=true in \ -${ENV_FILE}" 12 75 +${__env_file}" 12 75 fi # Case 2 ... EL, do we have a CL? - elif [[ "${value}" =~ "geth.yml" || "${value}" =~ "besu.yml" || "${value}" =~ "erigon.yml" \ - || "${value}" =~ "nethermind.yml" || "${value}" =~ "nimbus-el.yml" || "${value}" =~ "reth.yml" ]]; then - if [[ ! "${value}" =~ "prysm.yml" && ! "${value}" =~ "lighthouse.yml" && ! "${value}" =~ "teku.yml" \ - && ! "${value}" =~ "nimbus.yml" && ! "${value}" =~ "lodestar.yml" && ! "${value}" =~ "-cl-only.yml" \ - && ! "${value}" =~ "-allin1.yml" ]]; then + elif [[ "${__value}" =~ "geth.yml" || "${__value}" =~ "besu.yml" || "${__value}" =~ "erigon.yml" \ + || "${__value}" =~ "nethermind.yml" || "${__value}" =~ "nimbus-el.yml" || "${__value}" =~ "reth.yml" ]]; then + if [[ ! "${__value}" =~ "prysm.yml" && ! "${__value}" =~ "lighthouse.yml" && ! "${__value}" =~ "teku.yml" \ + && ! "${__value}" =~ "nimbus.yml" && ! "${__value}" =~ "lodestar.yml" && ! "${__value}" =~ "-cl-only.yml" \ + && ! "${__value}" =~ "-allin1.yml" ]]; then whiptail --msgbox "A Consensus Layer client is required alongside your Execution Layer client since \ Ethereum Merge.\n\nIf you run a distributed setup, you can shut off this nag screen by setting DISTRIBUTED=true in \ -${ENV_FILE}" 12 75 +${__env_file}" 12 75 fi fi - ${__as_owner} rm "${ENV_FILE}".original + ${__as_owner} rm "${__env_file}".original __during_migrate=0 - echo "${ENV_FILE} updated successfully" + echo "${__env_file} updated successfully" } -nag_os_version() { +__nag_os_version() { if [[ "$__distro" = "ubuntu" ]]; then if [ "${__os_major_version}" -lt 22 ]; then echo @@ -1218,11 +1218,11 @@ nag_os_version() { } -pull_and_build() { - dodocker system prune --force - docompose --profile tools pull - source_build - docompose --profile tools build --pull +__pull_and_build() { + __dodocker system prune --force + __docompose --profile tools pull + __source_build + __docompose --profile tools build --pull } @@ -1239,8 +1239,8 @@ update() { __free_space=$(df -P "$(pwd)" | awk '/[0-9]%/{print $(NF-2)}') - re='^[0-9]+$' - if ! [[ "${__free_space}" =~ $re ]] ; then + __regex='^[0-9]+$' + if ! [[ "${__free_space}" =~ $__regex ]] ; then echo "Unable to determine free disk space. This is likely a bug." echo "df reports $(df -P "$(pwd)") and __free_space is ${__free_space}" exit 70 @@ -1260,9 +1260,9 @@ update() { if [ -z "${ETHDSECUNDO-}" ]; then set +e ${__as_owner} git config pull.rebase false - var="ETH_DOCKER_TAG" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [ -z "${value}" ] || [ "${value}" = "latest" ]; then + __var="ETH_DOCKER_TAG" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [ -z "${__value}" ] || [ "${__value}" = "latest" ]; then export ETHDPINNED="" __branch=$(git rev-parse --abbrev-ref HEAD) if [[ "${__branch}" =~ ^tag-v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then @@ -1280,9 +1280,9 @@ update() { ${__as_owner} git update-index --assume-unchanged ext-network.yml fi else - export ETHDPINNED="${value}" + export ETHDPINNED="${__value}" ${__as_owner} git fetch --tags - ${__as_owner} git checkout -B "tag-${value}" "tags/${value}" + ${__as_owner} git checkout -B "tag-${__value}" "tags/${__value}" fi export GITEXITCODE=$? set -e @@ -1332,33 +1332,33 @@ update() { __non_interactive=1 fi -# envmigrate used to be called w/ arguments and checks for that +# __env_migrate used to be called w/ arguments and checks for that # shellcheck disable=SC2119 - envmigrate - pull_and_build + __env_migrate + __pull_and_build - delete_erigon - delete_reth - upgrade_postgres + __delete_erigon + __delete_reth + __upgrade_postgres echo - if [ "${__migrated}" -eq 1 ] && ! cmp -s "${ENV_FILE}" "${ENV_FILE}".source; then - ${__as_owner} cp "${ENV_FILE}".source "${ENV_FILE}".bak - ${__as_owner} rm "${ENV_FILE}".source - echo "Your ${ENV_FILE} configuration settings have been migrated to a fresh copy. You can \ -find the original contents in ${ENV_FILE}.bak." + if [ "${__migrated}" -eq 1 ] && ! cmp -s "${__env_file}" "${__env_file}".source; then + ${__as_owner} cp "${__env_file}".source "${__env_file}".bak + ${__as_owner} rm "${__env_file}".source + echo "Your ${__env_file} configuration settings have been migrated to a fresh copy. You can \ +find the original contents in ${__env_file}.bak." if [ "${__keep_targets}" -eq 0 ]; then echo "NB: If you made changes to the source or binary build targets, these have been \ reset to defaults." fi echo - echo "List of changes made to ${ENV_FILE} during migration - current on left, original on right:" + 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 || true + diff -y --suppress-common-lines "${__env_file}" "${__env_file}".bak || true else - echo "No changes made to ${ENV_FILE} during update" - if [ -f "${ENV_FILE}".source ]; then - ${__as_owner} rm "${ENV_FILE}".source || true + echo "No changes made to ${__env_file} during update" + if [ -f "${__env_file}".source ]; then + ${__as_owner} rm "${__env_file}".source || true fi fi echo @@ -1374,7 +1374,7 @@ reset to defaults." echo "The current partial update risks startup failure." fi - nag_os_version + __nag_os_version unset ETHDSECUNDO unset GITEXITCODE @@ -1398,10 +1398,10 @@ reset to defaults." resync-execution() { # Check for EL client - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) - case "${value}" in + case "${__value}" in *erigon.yml* ) __el_volume='erigon-el-data'; __el_client="erigon";; *geth.yml* ) __el_volume='geth-el-data'; __el_client="geth";; *reth.yml* ) __el_volume='reth-el-data'; __el_client="reth";; @@ -1410,35 +1410,35 @@ resync-execution() { * ) echo "You do not appear to be running an execution layer client. Nothing to do."; return 0;; esac - if ! dodocker volume ls -q | grep -q "$(basename "$(realpath .)")[_-]${__el_volume}"; then + if ! __dodocker volume ls -q | grep -q "$(basename "$(realpath .)")[_-]${__el_volume}"; then echo "Did not find Docker volume for ${__el_client}. Nothing to do." return 0 fi echo "This will stop ${__el_client} and delete its database to force a resync." - read -rp "WARNING - resync may take days. Do you wish to continue? (No/yes) " yn - case $yn in + read -rp "WARNING - resync may take days. Do you wish to continue? (No/yes) " __yn + case $__yn in [Yy][Ee][Ss] ) ;; * ) echo "Aborting."; exit 130;; esac __el_volume="$(basename "$(realpath .)")_${__el_volume}" echo "Stopping ${__el_client} container" - docompose stop execution && docompose rm -f execution - dodocker volume rm "$(dodocker volume ls -q -f "name=${__el_volume}")" + __docompose stop execution && __docompose rm -f execution + __dodocker volume rm "$(__dodocker volume ls -q -f "name=${__el_volume}")" __volume_id="" if [[ "${__el_volume}" =~ geth-el-data ]]; then __legacy_volume="$(basename "$(realpath .)")_geth-eth1-data" - __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + __volume_id="$(__dodocker volume ls -q -f "name=${__legacy_volume}")" elif [[ "${__el_volume}" =~ besu-el-data ]]; then __legacy_volume="$(basename "$(realpath .)")_besu-eth1-data" - __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + __volume_id="$(__dodocker volume ls -q -f "name=${__legacy_volume}")" elif [[ "${__el_volume}" =~ nethermind-el-data ]]; then __legacy_volume="$(basename "$(realpath .)")_nm-eth1-data" - __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + __volume_id="$(__dodocker volume ls -q -f "name=${__legacy_volume}")" fi if [ -n "${__volume_id}" ]; then - dodocker volume rm "${__volume_id}" + __dodocker volume rm "${__volume_id}" fi echo echo "${__el_client} stopped and database deleted." @@ -1450,10 +1450,10 @@ resync-execution() { resync-consensus() { # Check for CL client - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) - case "${value}" in + case "${__value}" in *lighthouse.yml* | *lighthouse-cl-only.yml* ) __cl_volume='lhconsensus-data'; __cl_client="lighthouse";; *teku-allin1.yml* ) __cl_volume='wipe-db'; __cl_client="teku";; *teku.yml* | *teku-cl-only.yml* ) __cl_volume='tekuconsensus-data'; __cl_client="teku";; @@ -1466,43 +1466,43 @@ resync-consensus() { * ) echo "You do not appear to be running a consensus layer client. Nothing to do."; return;; esac - if [ ! "${__cl_volume}" = "wipe-db" ] && ! dodocker volume ls -q \ + if [ ! "${__cl_volume}" = "wipe-db" ] && ! __dodocker volume ls -q \ | grep -q "$(basename "$(realpath .)")[_-]${__cl_volume}"; then echo "Did not find Docker volume for ${__cl_client}. Nothing to do." return 0 fi # Can we checkpoint sync? - var="RAPID_SYNC_URL" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="RAPID_SYNC_URL" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) echo "This will stop ${__cl_client} and delete its database to force a resync." - if [ -z "${value}" ]; then - read -rp "WARNING - RAPID_SYNC_URL not set, resync may take days. Do you wish to continue? (No/yes) " yn + if [ -z "${__value}" ]; then + read -rp "WARNING - RAPID_SYNC_URL not set, resync may take days. Do you wish to continue? (No/yes) " __yn else - read -rp "RAPID_SYNC_URL set, resync should finish in minutes. Do you wish to continue? (No/yes) " yn + read -rp "RAPID_SYNC_URL set, resync should finish in minutes. Do you wish to continue? (No/yes) " __yn fi - case $yn in + case $__yn in [Yy][Ee][Ss] ) ;; * ) echo "Aborting."; exit 130;; esac echo "Stopping ${__cl_client} container" - docompose stop consensus && docompose rm -f consensus + __docompose stop consensus && __docompose rm -f consensus if [ "${__cl_volume}" = "wipe-db" ]; then - docompose run --rm wipe-db + __docompose run --rm wipe-db else __cl_volume="$(basename "$(realpath .)")_${__cl_volume}" - dodocker volume rm "$(dodocker volume ls -q -f "name=${__cl_volume}")" + __dodocker volume rm "$(__dodocker volume ls -q -f "name=${__cl_volume}")" __volume_id="" if [[ "${__cl_volume}" =~ lhconsensus-data ]]; then __legacy_volume="$(basename "$(realpath .)")_lhbeacon-data" - __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + __volume_id="$(__dodocker volume ls -q -f "name=${__legacy_volume}")" elif [[ "${__cl_volume}" =~ prysmconsensus-data ]]; then __legacy_volume="$(basename "$(realpath .)")_prysmbeacon-data" - __volume_id="$(dodocker volume ls -q -f "name=${__legacy_volume}")" + __volume_id="$(__dodocker volume ls -q -f "name=${__legacy_volume}")" fi if [ -n "${__volume_id}" ]; then - dodocker volume rm "${__volume_id}" + __dodocker volume rm "${__volume_id}" fi fi echo @@ -1514,23 +1514,23 @@ resync-consensus() { attach-geth() { - if [ ! -f "${ENV_FILE}" ]; then - echo "${ENV_FILE} configuration file not found, aborting." + 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 + 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 - __legacy_datadir=$(dodocker run --rm -v "$(dodocker volume ls -q -f \ + __legacy_datadir=$(__dodocker run --rm -v "$(__dodocker volume ls -q -f \ "name=$(basename "$(realpath .)")[_-]geth-eth1-data")":"/var/lib/goethereum" \ alpine:3 sh -c 'if [ -d "/var/lib/goethereum/geth/chaindata" ]; then echo true; else echo false; fi') if [ "${__legacy_datadir}" = "true" ]; then - docompose exec -it execution bash -c "geth attach /var/lib/goethereum/geth.ipc" + __docompose exec -it execution bash -c "geth attach /var/lib/goethereum/geth.ipc" else - docompose exec -it execution bash -c "geth attach /var/lib/geth/geth.ipc" + __docompose exec -it execution bash -c "geth attach /var/lib/geth/geth.ipc" fi } @@ -1557,48 +1557,48 @@ prune-besu() { __non_interactive=1 fi - if [ ! -f "${ENV_FILE}" ]; then - echo "${ENV_FILE} configuration file not found, aborting." + if [ ! -f "${__env_file}" ]; then + echo "${__env_file} configuration file not found, aborting." exit 1 fi - if ! grep -q '^COMPOSE_FILE=.*besu\.yml' "${ENV_FILE}" 2>/dev/null ; then + if ! grep -q '^COMPOSE_FILE=.*besu\.yml' "${__env_file}" 2>/dev/null ; then echo "You do not appear to be using Besu, aborting." exit 1 fi # Check for archive node - var="ARCHIVE_NODE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [[ "${value}" = "true" ]]; then + __var="ARCHIVE_NODE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [[ "${__value}" = "true" ]]; then echo "Besu is an archive node: Aborting." exit 1 fi - rpc_line=$(grep '^EL_RPC_PORT=' "${ENV_FILE}") - regex='^EL_RPC_PORT=([0-9]+)' - if [[ ! "${rpc_line}" =~ ${regex} ]]; then + __rpc_line=$(grep '^EL_RPC_PORT=' "${__env_file}") + __regex='^EL_RPC_PORT=([0-9]+)' + if [[ ! "${__rpc_line}" =~ ${__regex} ]]; then echo "Unable to determine EL_RPC_PORT, aborting." exit 1 else - rpc_port="${BASH_REMATCH[1]}" + __rpc_port="${BASH_REMATCH[1]}" fi set +e - sync_status=$(docompose exec -T execution wget -qO- "http://localhost:$rpc_port" \ + __sync_status=$(__docompose 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=$? + __exitstatus=$? set -e - if [ $exitstatus -ne 0 ]; then + if [ $__exitstatus -ne 0 ]; then echo "Unable to connect to Besu: Is it running?" - echo "Output: ${sync_status}" + echo "Output: ${__sync_status}" echo "Aborting." exit 1 fi - if [[ ! "${sync_status}" =~ "false" ]]; then + if [[ ! "${__sync_status}" =~ "false" ]]; then echo "Besu is not done syncing yet. Sync status:" - echo "${sync_status}" + echo "${__sync_status}" echo echo "Aborting." exit 1 @@ -1606,8 +1606,8 @@ prune-besu() { if [ $__non_interactive = 0 ]; then while true; do - read -rp "WARNING - this will stop Besu and prune its trie-logs. Do you wish to continue? (No/Yes) " yn - case $yn in + read -rp "WARNING - this will stop Besu and prune its trie-logs. Do you wish to continue? (No/Yes) " __yn + case $__yn in [Yy][Ee][Ss] ) break;; * ) echo "Aborting, no changes made"; exit 130;; esac @@ -1617,8 +1617,8 @@ prune-besu() { echo echo "Starting Besu prune" echo - docompose run --rm set-prune-marker "touch /var/lib/besu/prune-marker" - docompose stop execution && docompose rm -f execution + __docompose run --rm set-prune-marker "touch /var/lib/besu/prune-marker" + __docompose stop execution && __docompose rm -f execution start echo echo "Prune is running, you can observe it with '$__me logs -f execution'" @@ -1650,48 +1650,48 @@ prune-reth() { __non_interactive=1 fi - if [ ! -f "${ENV_FILE}" ]; then - echo "${ENV_FILE} configuration file not found, aborting." + if [ ! -f "${__env_file}" ]; then + echo "${__env_file} configuration file not found, aborting." exit 1 fi - if ! grep -q '^COMPOSE_FILE=.*reth\.yml' "${ENV_FILE}" 2>/dev/null ; then + if ! grep -q '^COMPOSE_FILE=.*reth\.yml' "${__env_file}" 2>/dev/null ; then echo "You do not appear to be using Reth, aborting." exit 1 fi # Check for archive node - var="ARCHIVE_NODE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [[ "${value}" = "true" ]]; then + __var="ARCHIVE_NODE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [[ "${__value}" = "true" ]]; then echo "Reth is an archive node: Aborting." exit 1 fi - rpc_line=$(grep '^EL_RPC_PORT=' "${ENV_FILE}") - regex='^EL_RPC_PORT=([0-9]+)' - if [[ ! "${rpc_line}" =~ ${regex} ]]; then + __rpc_line=$(grep '^EL_RPC_PORT=' "${__env_file}") + __regex='^EL_RPC_PORT=([0-9]+)' + if [[ ! "${__rpc_line}" =~ ${__regex} ]]; then echo "Unable to determine EL_RPC_PORT, aborting." exit 1 else - rpc_port="${BASH_REMATCH[1]}" + __rpc_port="${BASH_REMATCH[1]}" fi set +e - sync_status=$(docompose exec -T execution wget -qO- "http://localhost:$rpc_port" \ + __sync_status=$(__docompose 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=$? + __exitstatus=$? set -e - if [ $exitstatus -ne 0 ]; then + if [ $__exitstatus -ne 0 ]; then echo "Unable to connect to Reth: Is it running?" - echo "Output: ${sync_status}" + echo "Output: ${__sync_status}" echo "Aborting." exit 1 fi - if [[ ! "${sync_status}" =~ "false" ]]; then + if [[ ! "${__sync_status}" =~ "false" ]]; then echo "Reth is not done syncing yet. Sync status:" - echo "${sync_status}" + echo "${__sync_status}" echo echo "Aborting." exit 1 @@ -1699,8 +1699,8 @@ prune-reth() { if [ $__non_interactive = 0 ]; then while true; do - read -rp "WARNING - this will stop Reth and prune its database. Do you wish to continue? (No/Yes) " yn - case $yn in + read -rp "WARNING - this will stop Reth and prune its database. Do you wish to continue? (No/Yes) " __yn + case $__yn in [Yy][Ee][Ss] ) break;; * ) echo "Aborting, no changes made"; exit 130;; esac @@ -1710,8 +1710,8 @@ prune-reth() { echo echo "Starting Reth prune" echo - docompose run --rm set-prune-marker "touch /var/lib/reth/prune-marker" - docompose stop execution && docompose rm -f execution + __docompose run --rm set-prune-marker "touch /var/lib/reth/prune-marker" + __docompose stop execution && __docompose rm -f execution start echo echo "Prune is running, you can observe it with '$__me logs -f execution'" @@ -1743,28 +1743,28 @@ prune-nethermind() { __non_interactive=1 fi - if [ ! -f "${ENV_FILE}" ]; then - echo "${ENV_FILE} configuration file not found, aborting." + if [ ! -f "${__env_file}" ]; then + echo "${__env_file} configuration file not found, aborting." exit 1 fi - if ! grep -q '^COMPOSE_FILE=.*nethermind\.yml' "${ENV_FILE}" 2>/dev/null ; then + if ! grep -q '^COMPOSE_FILE=.*nethermind\.yml' "${__env_file}" 2>/dev/null ; then echo "You do not appear to be using Nethermind, aborting." exit 1 fi # Check for archive node - var="ARCHIVE_NODE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [[ "${value}" = "true" ]]; then + __var="ARCHIVE_NODE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [[ "${__value}" = "true" ]]; then echo "Nethermind is an archive node: Aborting." exit 1 fi __get_docker_free_space - var="NETWORK" - NETWORK=$(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=262144000 @@ -1783,51 +1783,51 @@ prune-nethermind() { exit 1 fi - rpc_line=$(grep '^EL_RPC_PORT=' "${ENV_FILE}") - regex='^EL_RPC_PORT=([0-9]+)' - if [[ ! "${rpc_line}" =~ ${regex} ]]; then + __rpc_line=$(grep '^EL_RPC_PORT=' "${__env_file}") + __regex='^EL_RPC_PORT=([0-9]+)' + if [[ ! "${__rpc_line}" =~ ${__regex} ]]; then echo "Unable to determine EL_RPC_PORT, aborting." exit 1 else - rpc_port="${BASH_REMATCH[1]}" + __rpc_port="${BASH_REMATCH[1]}" fi set +e - sync_status=$(docompose exec -T execution wget -qO- "http://localhost:$rpc_port" --header \ + __sync_status=$(__docompose 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=$? + __exitstatus=$? set -e - if [ $exitstatus -ne 0 ]; then + if [ $__exitstatus -ne 0 ]; then echo "Unable to connect to Nethermind: Is it running?" - echo "Output: ${sync_status}" + echo "Output: ${__sync_status}" echo "Aborting." exit 1 fi - if [[ ! "${sync_status}" =~ "false" ]]; then + if [[ ! "${__sync_status}" =~ "false" ]]; then echo "Nethermind is not done syncing yet. Sync status:" - echo "${sync_status}" + echo "${__sync_status}" echo echo "Aborting." exit 1 fi - var="AUTOPRUNE_NM" - auto_prune=$(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) if [ $__non_interactive = 0 ]; then while true; do - if [ "${auto_prune}" = true ]; then + if [ "${__auto_prune}" = true ]; then if [ "${NETWORK}" = "mainnet" ] || [ "${NETWORK}" = "gnosis" ]; then - threshold="350" + __threshold="350" else - threshold="50" + __threshold="50" fi - echo "Nethermind should auto-prune below ${threshold} GiB free. Check logs with \"$__me logs -f --tail 500 \ + echo "Nethermind should auto-prune below ${__threshold} GiB free. Check logs with \"$__me logs -f --tail 500 \ execution | grep Full\" to see whether it is." fi - read -rp "WARNING - this will prune Nethermind's database in the background. Do you wish to continue? (No/Yes) " yn - case $yn in + read -rp "WARNING - this will prune Nethermind's database in the background. Do you wish to continue? (No/Yes) " __yn + case $__yn in [Yy][Ee][Ss] ) break;; * ) echo "Aborting, no changes made"; exit 130;; esac @@ -1839,21 +1839,21 @@ execution | grep Full\" to see whether it is." echo set +e - prune_result=$(docompose exec -T execution wget -qO- "http://localhost:1337" --header \ + __prune_result=$(__docompose exec -T execution wget -qO- "http://localhost:1337" --header \ 'Content-Type: application/json' --post-data '{"jsonrpc":"2.0","method":"admin_prune","params":[],"id":1}') - exitstatus=$? + __exitstatus=$? set -e - if [ $exitstatus -ne 0 ]; then - echo "Unable to start prune, error code ${exitstatus}. This is likely a bug." - echo "An attempt to run it returned this: ${prune_result}" + if [ $__exitstatus -ne 0 ]; then + echo "Unable to start prune, error code ${__exitstatus}. This is likely a bug." + echo "An attempt to run it returned this: ${__prune_result}" # shellcheck disable=SC2028 echo 'The command attempted was: docker compose run --rm set-prune-marker "curl -s \ --data {\\\"method\\\":\\\"admin_prune\\\",\\\"params\\\":[],\\\"id\\\":1,\\\"jsonrpc\\\":\\\"2.0\\\"} \ -H Content-Type:\ application/json http://execution:8545"' - exit ${exitstatus} + exit ${__exitstatus} fi - echo "Nethermind returns ${prune_result}" - if [[ ! "${prune_result}" =~ [Ss]tarting ]]; then + echo "Nethermind returns ${__prune_result}" + if [[ ! "${__prune_result}" =~ [Ss]tarting ]]; then echo "Unable to start prune. This is likely a bug." exit 70 fi @@ -1889,51 +1889,51 @@ prune-lighthouse() { __non_interactive=1 fi - if [ ! -f "${ENV_FILE}" ]; then - echo "${ENV_FILE} configuration file not found, aborting." + if [ ! -f "${__env_file}" ]; then + echo "${__env_file} configuration file not found, aborting." exit 1 fi - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ ! "${value}" =~ "lighthouse.yml" && ! "${value}" =~ "lighthouse-cl-only.yml" ]]; then + if [[ ! "${__value}" =~ "lighthouse.yml" && ! "${__value}" =~ "lighthouse-cl-only.yml" ]]; then echo "You do not appear to be using Lighthouse, aborting." exit 1 fi # Check for archive node - var="ARCHIVE_NODE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - if [[ "${value}" = "true" ]]; then + __var="ARCHIVE_NODE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + if [[ "${__value}" = "true" ]]; then echo "Lighthouse is an archive node: Aborting." exit 1 fi - rpc_line=$(grep '^CL_REST_PORT=' "${ENV_FILE}") - regex='^CL_REST_PORT=([0-9]+)' - if [[ ! "${rpc_line}" =~ ${regex} ]]; then + __rpc_line=$(grep '^CL_REST_PORT=' "${__env_file}") + __regex='^CL_REST_PORT=([0-9]+)' + if [[ ! "${__rpc_line}" =~ ${__regex} ]]; then echo "Unable to determine CL_REST_PORT, aborting." exit 1 else - rpc_port="${BASH_REMATCH[1]}" + __rpc_port="${BASH_REMATCH[1]}" fi set +e - sync_status=$(docompose exec -T consensus wget -qO- "http://localhost:$rpc_port/eth/v1/node/syncing") - exitstatus=$? + __sync_status=$(__docompose exec -T consensus wget -qO- "http://localhost:$__rpc_port/eth/v1/node/syncing") + __exitstatus=$? set -e - if [ $exitstatus -ne 0 ]; then + if [ $__exitstatus -ne 0 ]; then echo "Unable to connect to Lighthouse: Is it running?" - echo "Output: ${sync_status}" + echo "Output: ${__sync_status}" echo "Aborting." exit 1 fi - if [[ "${sync_status}" =~ "true" ]]; then # Avoid jq - if el_offline or is_optimistic or is_syncing, don't proceed + if [[ "${__sync_status}" =~ "true" ]]; then # Avoid jq - if el_offline or is_optimistic or is_syncing, don't proceed echo "Lighthouse is not done syncing yet. Sync status:" - echo "${sync_status}" + echo "${__sync_status}" echo echo "Aborting." exit 1 @@ -1941,8 +1941,8 @@ prune-lighthouse() { if [ $__non_interactive = 0 ]; then while true; do - read -rp "WARNING - this will stop Lighthouse and prune its state. Do you wish to continue? (No/Yes) " yn - case $yn in + read -rp "WARNING - this will stop Lighthouse and prune its state. Do you wish to continue? (No/Yes) " __yn + case $__yn in [Yy][Ee][Ss] ) break;; * ) echo "Aborting, no changes made"; exit 130;; esac @@ -1952,8 +1952,8 @@ prune-lighthouse() { echo echo "Starting Lighthouse prune" echo - docompose run --rm set-cl-prune-marker "touch /var/lib/lighthouse/beacon/prune-marker" - docompose stop consensus && docompose rm -f consensus + __docompose run --rm set-cl-prune-marker "touch /var/lib/lighthouse/beacon/prune-marker" + __docompose stop consensus && __docompose rm -f consensus start echo echo "Prune is running, you can observe it with '$__me logs -f consensus'" @@ -1963,19 +1963,19 @@ prune-lighthouse() { } -prep-keyimport() { - if [ ! -f "${ENV_FILE}" ]; then - echo "${ENV_FILE} configuration file not found, aborting." +__prep-keyimport() { + if [ ! -f "${__env_file}" ]; then + echo "${__env_file} configuration file not found, aborting." exit 1 fi - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ ! "${value}" =~ "prysm.yml" ]] && [[ ! "${value}" =~ "lighthouse.yml" ]] && [[ ! "${value}" =~ "teku.yml" ]] \ - && [[ ! "${value}" =~ "nimbus.yml" ]] && [[ ! "${value}" =~ "lodestar.yml" ]] && \ - [[ ! "${value}" =~ "-allin1.yml" ]] && [[ ! "${value}" =~ "vc-only.yml" ]]; then + if [[ ! "${__value}" =~ "prysm.yml" ]] && [[ ! "${__value}" =~ "lighthouse.yml" ]] && [[ ! "${__value}" =~ "teku.yml" ]] \ + && [[ ! "${__value}" =~ "nimbus.yml" ]] && [[ ! "${__value}" =~ "lodestar.yml" ]] && \ + [[ ! "${__value}" =~ "-allin1.yml" ]] && [[ ! "${__value}" =~ "vc-only.yml" ]]; then echo "You do not appear to be running a validator client. Aborting." exit 1 fi @@ -2003,18 +2003,18 @@ prep-keyimport() { continue fi IFS=$'\n' - files=$(find "$2" -maxdepth 1 -name '*.json') + __files=$(find "$2" -maxdepth 1 -name '*.json') # Unset restores default unset IFS - if [ -z "$files" ]; then + if [ -z "$__files" ]; then echo "No .json files found in $2, aborting" exit 1 fi IFS=$'\n' - files=$(find ./.eth/validator_keys -maxdepth 1 -name '*.json') + __files=$(find ./.eth/validator_keys -maxdepth 1 -name '*.json') # Unset restores default unset IFS - if [ -n "$files" ]; then + if [ -n "$__files" ]; then ${__as_owner} mkdir -p ./.eth/validator_keys/keybackup ${__as_owner} mv -uf ./.eth/validator_keys/*.json ./.eth/validator_keys/keybackup ${__as_owner} rm -f ./.eth/validator_keys/*.json @@ -2048,70 +2048,70 @@ prep-keyimport() { __i_haz_ethdo() { - if [ ! -f "${ENV_FILE}" ]; then + if [ ! -f "${__env_file}" ]; then echo "${__project_name} has not been configured. Please run $__me config first." exit 0 fi - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ ! "${value}" =~ "ethdo.yml" ]]; then - echo "Please edit the ${ENV_FILE} file and make sure \":ethdo.yml\" is added to the \"COMPOSE_FILE\" line" - echo "For example, \"nano ${ENV_FILE}\" will open the nano text editor with the \"${ENV_FILE}\" file loaded." + if [[ ! "${__value}" =~ "ethdo.yml" ]]; then + echo "Please edit the ${__env_file} file and make sure \":ethdo.yml\" is added to the \"COMPOSE_FILE\" line" + echo "For example, \"nano ${__env_file}\" will open the nano text editor with the \"${__env_file}\" file loaded." echo "Without it, this step cannot be run" echo - read -rp "Do you want me to make this change for you? (n/y)" yn - case $yn in + read -rp "Do you want me to make this change for you? (n/y)" __yn + case $__yn in [Yy] );; * ) exit 130;; esac - if [ -n "${value}" ]; then - COMPOSE_FILE="${value}:ethdo.yml" + if [ -n "${__value}" ]; then + COMPOSE_FILE="${__value}:ethdo.yml" else COMPOSE_FILE="ethdo.yml" - echo "You do not have a CL in ${__project_name}. Please make sure CL_NODE in ${ENV_FILE} points at an available one" + echo "You do not have a CL in ${__project_name}. Please make sure CL_NODE in ${__env_file} points at an available one" fi - set_value_in_env + __set_value_in_env echo "Your COMPOSE_FILE now reads ${COMPOSE_FILE}" fi } __i_haz_web3signer() { - if [ ! -f "${ENV_FILE}" ]; then + if [ ! -f "${__env_file}" ]; then echo "${__project_name} has not been configured. Please run $__me config first." exit 0 fi - var="WEB3SIGNER" - __w3s=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="WEB3SIGNER" + __w3s=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) if [ ! "${__w3s}" = "true" ]; then return 0 fi - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ ! "${value}" =~ "web3signer.yml" ]]; then - echo "WEB3SIGNER=true in ${ENV_FILE}, but web3signer.yml is not in use" - echo "Please edit the ${ENV_FILE} file and make sure \":web3signer.yml\" is added to the \"COMPOSE_FILE\" line" - echo "For example, \"nano ${ENV_FILE}\" will open the nano text editor with the \"${ENV_FILE}\" file loaded." + if [[ ! "${__value}" =~ "web3signer.yml" ]]; then + echo "WEB3SIGNER=true in ${__env_file}, but web3signer.yml is not in use" + echo "Please edit the ${__env_file} file and make sure \":web3signer.yml\" is added to the \"COMPOSE_FILE\" line" + echo "For example, \"nano ${__env_file}\" will open the nano text editor with the \"${__env_file}\" file loaded." echo "Without it, $__me keys cannot be run" echo - read -rp "Do you want me to make this change for you? (n/y)" yn - case $yn in + read -rp "Do you want me to make this change for you? (n/y)" __yn + case $__yn in [Yy] );; * ) exit 130;; esac - if [ -n "${value}" ]; then - COMPOSE_FILE="${value}:web3signer.yml" + if [ -n "${__value}" ]; then + COMPOSE_FILE="${__value}:web3signer.yml" else echo "You do not have a validator client in ${__project_name}. web3signer cannot be used without one." exit 1 fi - set_value_in_env + __set_value_in_env echo "Your COMPOSE_FILE now reads ${COMPOSE_FILE}" fi } @@ -2119,7 +2119,7 @@ __i_haz_web3signer() { __i_haz_keys_service() { # This caused issues and is currently not being called - if ! docompose --profile tools config --services | grep -q validator-keys; then + if ! __docompose --profile tools config --services | grep -q validator-keys; then if [[ "${1:-}" = "silent" ]]; then return 1 fi @@ -2151,7 +2151,7 @@ __keys_usage() { echo echo " get-recipient 0xPUBKEY" echo " List fee recipient set for the validator with public key 0xPUBKEY" - echo " Validators will use FEE_RECIPIENT in ${ENV_FILE} by default, if not set individually" + echo " Validators will use FEE_RECIPIENT in ${__env_file} by default, if not set individually" echo " set-recipient 0xPUBKEY 0xADDRESS" echo " Set individual fee recipient for the validator with public key 0xPUBKEY" echo " delete-recipient 0xPUBKEY" @@ -2214,52 +2214,52 @@ keys() { if [ "${1:-}" = "import" ]; then #__i_haz_keys_service shift - prep-keyimport "$@" - docompose run --rm -e OWNER_UID="${__owner_uid}" validator-keys import "${__args}" + __prep-keyimport "$@" + __docompose run --rm -e OWNER_UID="${__owner_uid}" validator-keys import "${__args}" elif [ "${1:-}" = "create-prysm-wallet" ]; then - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ ! "${value}" =~ "prysm.yml" ]] && [[ ! "${value}" =~ "prysm-vc-only.yml" ]]; then + if [[ ! "${__value}" =~ "prysm.yml" ]] && [[ ! "${__value}" =~ "prysm-vc-only.yml" ]]; then echo "You do not appear to be using a Prysm validator. Aborting." exit 1 fi - if docompose run --rm create-wallet; then - docompose stop validator - docompose rm --force validator + if __docompose run --rm create-wallet; then + __docompose stop validator + __docompose rm --force validator up fi elif [ "${1:-}" = "prepare-address-change" ]; then __i_haz_ethdo echo "Generating offline prep file" set +e - docompose run --rm ethdo validator credentials set --prepare-offline - exitstatus=$? + __docompose run --rm ethdo validator credentials set --prepare-offline + __exitstatus=$? set -e - if [ "${exitstatus}" -ne 0 ]; then + if [ "${__exitstatus}" -ne 0 ]; then echo "Running ethdo failed, unfortunately. Is the CL running and synced?" echo "Please try again after fixing root cause. Aborting." exit 1 fi echo echo "Downloading ethdo" - REPO="wealdtech/ethdo"; \ - wget -q -O- https://api.github.com/repos/${REPO}/releases/latest | grep "browser_download_url.*linux-amd64.tar.gz" \ + __repo="wealdtech/ethdo"; \ + wget -q -O- https://api.github.com/repos/${__repo}/releases/latest | grep "browser_download_url.*linux-amd64.tar.gz" \ | head -1 \ | cut -d : -f 2,3 \ | tr -d \" \ | wget -qi- -O- \ | ${__as_owner} tar zxf - -C ./.eth/ethdo/ \ - || echo "-> Could not download the latest version of '${REPO}' for amd64." + || echo "-> Could not download the latest version of '${__repo}' for amd64." ${__as_owner} mkdir -p ./.eth/ethdo/arm64 - wget -q -O- https://api.github.com/repos/${REPO}/releases/latest | grep "browser_download_url.*linux-arm64.tar.gz" \ + wget -q -O- https://api.github.com/repos/${__repo}/releases/latest | grep "browser_download_url.*linux-arm64.tar.gz" \ | head -1 \ | cut -d : -f 2,3 \ | tr -d \" \ | wget -qi- -O- \ | ${__as_owner} tar zxf - -C ./.eth/ethdo/arm64 \ - || echo "-> Could not download the latest version of '${REPO}' for arm64." + || echo "-> Could not download the latest version of '${__repo}' for arm64." ${__as_owner} mv ./.eth/ethdo/arm64/ethdo ./.eth/ethdo/ethdo-arm64 ${__as_owner} rm -rf ./.eth/ethdo/arm64 echo @@ -2267,7 +2267,7 @@ keys() { echo "Please see https://ethdocker.com/Support/ChangingWithdrawalCredentials for details" elif [ "${1:-}" = "send-address-change" ]; then __i_haz_ethdo - docompose run --rm ethdo validator credentials set + __docompose run --rm ethdo validator credentials set elif [ "${1:-}" = "sign-exit" ] && [ "${2:-}" = "from-keystore" ]; then __i_haz_ethdo @@ -2298,8 +2298,8 @@ keys() { if [ "$__num_files" -gt 1 ]; then while true; do - read -rp "Do all validator keys have the same password? (y/n) " yn - case $yn in + read -rp "Do all validator keys have the same password? (y/n) " __yn + case $__yn in [Yy]* ) __justone=1; break;; [Nn]* ) __justone=0; break;; * ) echo "Please answer yes or no.";; @@ -2325,8 +2325,8 @@ keys() { fi fi - created=0 - failed=0 + __created=0 + __failed=0 for __keyfile in .eth/validator_keys/keystore-*.json; do [ -f "${__keyfile}" ] || continue # Should always evaluate true - just in case if [ "${__justone}" -eq 0 ]; then @@ -2355,40 +2355,40 @@ keys() { set +e # __offline may be empty, don't quote it # shellcheck disable=SC2086 - __json=$(docompose run --rm ethdo validator exit --validator "${__keyfile}" --json --timeout 2m \ + __json=$(__docompose run --rm ethdo validator exit --validator "${__keyfile}" --json --timeout 2m \ --passphrase "${__password}" ${__offline}) - exitstatus=$? - if [ "${exitstatus}" -eq 0 ]; then + __exitstatus=$? + if [ "${__exitstatus}" -eq 0 ]; then echo "${__json}" >".eth/exit_messages/${__pubkey::10}--${__pubkey:90}-exit.json" # shellcheck disable=SC2320 - exitstatus=$? - if [ "${exitstatus}" -eq 0 ]; then + __exitstatus=$? + if [ "${__exitstatus}" -eq 0 ]; then echo "Creating an exit message for validator ${__pubkey} into file \ ./.eth/exit_messages/${__pubkey::10}--${__pubkey:90}-exit.json succeeded" - (( created++ )) + (( __created++ )) else echo "Error writing exit json to file ./.eth/exit_messages/${__pubkey::10}--${__pubkey:90}-exit.json" - (( failed++ )) + (( __failed++ )) fi else echo "Creating an exit message for validator ${__pubkey} from file ${__keyfile} failed" - (( failed++ )) + (( __failed++ )) fi set -e done echo - echo "Created pre-signed exit messages for ${created} validators" - if [ "${created}" -gt 0 ]; then + echo "Created pre-signed exit messages for ${__created} validators" + if [ "${__created}" -gt 0 ]; then echo "You can find them in ./.eth/exit_messages" fi - if [ "${failed}" -gt 0 ]; then - echo "Failed for ${failed} validators" + if [ "${__failed}" -gt 0 ]; then + echo "Failed for ${__failed} validators" fi #elif [ "${1:-}" = "send-exit" ] && ! __i_haz_keys_service silent; then elif [ "${1:-}" = "send-exit" ]; then - var="CL_NODE" - CL_NODE=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - network_name="$(docompose config | awk ' + __var="CL_NODE" + CL_NODE=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + __network_name="$(__docompose config | awk ' BEGIN { found_networks=0; found_default=0; @@ -2406,19 +2406,19 @@ keys() { exit; } ')" - if ! dodocker image ls --format "{{.Repository}}:{{.Tag}}" | grep -q "vc-utils:local"; then + if ! __dodocker image ls --format "{{.Repository}}:{{.Tag}}" | grep -q "vc-utils:local"; then if ! dpkg-query -W -f='${Status}' docker-ce 2>/dev/null | grep -q "ok installed"; then - dodocker build -t vc-utils:local ./vc-utils + __dodocker build -t vc-utils:local ./vc-utils else if ! dpkg-query -W -f='${Status}' docker-buildx-plugin 2>/dev/null | grep -q "ok installed"; then ${__auto_sudo} apt-get update && ${__auto_sudo} apt-get install -y docker-buildx-plugin fi - dodocker buildx build -t vc-utils:local ./vc-utils + __dodocker buildx build -t vc-utils:local ./vc-utils fi fi - dodocker run --rm \ + __dodocker run --rm \ -u 1000:1000 \ - --network "${network_name}" \ + --network "${__network_name}" \ --name send-exit \ -v "$(pwd)/.eth/exit_messages:/exit_messages" \ -v "/etc/localtime:/etc/localtime:ro" \ @@ -2427,10 +2427,10 @@ keys() { vc-utils:local /var/lib/lighthouse/nonesuch.txt eth2 send-exit else #__i_haz_keys_service - docompose run --rm -e OWNER_UID="${__owner_uid}" validator-keys "$@" + __docompose run --rm -e OWNER_UID="${__owner_uid}" validator-keys "$@" fi - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) } @@ -2440,7 +2440,7 @@ upgrade() { start() { - docompose up -d --remove-orphans "$@" + __docompose up -d --remove-orphans "$@" } # Passed by user @@ -2456,7 +2456,7 @@ run() { stop() { - docompose down --remove-orphans "$@" + __docompose down --remove-orphans "$@" } @@ -2472,17 +2472,17 @@ restart() { logs() { - docompose logs "$@" + __docompose logs "$@" } cmd() { - docompose "$@" + __docompose "$@" } terminate() { - if [ -z "$(dodocker volume ls -q -f "name=^$(basename "$(realpath .)")_[^_]+")" ]; then + if [ -z "$(__dodocker volume ls -q -f "name=^$(basename "$(realpath .)")_[^_]+")" ]; then echo "There are no data stores - Docker volumes - left to remove for this Ethereum node." stop return 0 @@ -2490,8 +2490,8 @@ 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 +(No/Yes) " __yn + case $__yn in [Yy][Ee][Ss] ) break;; * ) echo "Aborting, no changes made"; exit 130;; esac @@ -2500,16 +2500,16 @@ terminate() { stop # In this case I want the word splitting, so rm can remove all volumes # shellcheck disable=SC2046 - dodocker volume rm $(dodocker volume ls -q -f "name=^$(basename "$(realpath .)")_[^_]+") + __dodocker volume rm $(__dodocker volume ls -q -f "name=^$(basename "$(realpath .)")_[^_]+") echo echo "All containers stopped and all volumes deleted" echo } -query_network() { - var="NETWORK" - __prev_network=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) +__query_network() { + __var="NETWORK" + __prev_network=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) NETWORK=$(whiptail --notags --title "Select Network" --menu \ "Which network do you want to run on?" 13 65 6 \ "holesky" "Holešovice Testnet" \ @@ -2550,7 +2550,7 @@ screen.\n\nCustom testnets only work with a URL to fetch their configuration fro } -query_deployment() { +__query_deployment() { if [ "${NETWORK}" = "gnosis" ]; then if uname -m | grep -q riscv64; then echo "Gnosis network has no available client combos on RISC-V. Aborting." @@ -2590,7 +2590,7 @@ query_deployment() { } -query_validator_client() { +__query_validator_client() { if [ "${NETWORK}" = "gnosis" ]; then CONSENSUS_CLIENT=$(whiptail --notags --title "Select validator client" --menu \ "Which validator client do you want to run?" 11 65 4 \ @@ -2635,7 +2635,7 @@ query_validator_client() { } -query_consensus_client() { +__query_consensus_client() { if [ "${NETWORK}" = "gnosis" ]; then CONSENSUS_CLIENT=$(whiptail --notags --title "Select consensus client" --menu \ "Which consensus client do you want to run?" 11 65 4 \ @@ -2672,7 +2672,7 @@ query_consensus_client() { } -query_consensus_only_client() { +__query_consensus_only_client() { if [ "${NETWORK}" = "gnosis" ]; then CONSENSUS_CLIENT=$(whiptail --notags --title "Select consensus client" --menu \ "Which consensus client do you want to run?" 11 65 4 \ @@ -2707,15 +2707,15 @@ query_consensus_only_client() { } -query_custom_execution_client() { +__query_custom_execution_client() { if [ "${__minty_fresh}" -eq 1 ]; then EL_CUSTOM_NODE="" JWT_SECRET="" else - var="EL_NODE" - EL_CUSTOM_NODE=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) - var="JWT_SECRET" - JWT_SECRET=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="EL_NODE" + EL_CUSTOM_NODE=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) + __var="JWT_SECRET" + JWT_SECRET=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) fi EL_CUSTOM_NODE=$(whiptail --title "Configure custom execution client" --inputbox "What is the URL for your custom \ execution client? (right-click to paste)" 10 65 "${EL_CUSTOM_NODE}" 3>&1 1>&2 2>&3) @@ -2737,7 +2737,7 @@ again or Cancel on the next screen." 10 65 } -query_execution_client() { +__query_execution_client() { if [ "${NETWORK}" = "gnosis" ]; then if uname -m | grep -q aarch64 || uname -m | grep -q arm64; then EXECUTION_CLIENT=$(whiptail --notags --title "Select execution client" --menu \ @@ -2776,7 +2776,7 @@ query_execution_client() { if [ "${EXECUTION_CLIENT}" == "NONE" ]; then unset EXECUTION_CLIENT - query_custom_execution_client + __query_custom_execution_client EL_NODE="${EL_CUSTOM_NODE}" else echo "Your execution client file is:" "${EXECUTION_CLIENT}" @@ -2790,7 +2790,7 @@ query_execution_client() { } -query_grafana() { +__query_grafana() { if (whiptail --title "Grafana" --yesno "Do you want to use Grafana dashboards?" 10 65) then if [[ "$OSTYPE" == "darwin"* ]]; then # macOS doesn't do well with / bind mount - leave node-exporter, cadvisor and loki/promtail off by default @@ -2804,7 +2804,7 @@ query_grafana() { } -query_remote_beacon() { +__query_remote_beacon() { if [ "${__minty_fresh}" -eq 1 ]; then if [ "${__deployment}" = "rocket" ]; then REMOTE_BEACON="http://eth2:5052" @@ -2812,8 +2812,8 @@ query_remote_beacon() { REMOTE_BEACON="" fi else - var="CL_NODE" - REMOTE_BEACON=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="CL_NODE" + REMOTE_BEACON=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) fi REMOTE_BEACON=$(whiptail --title "Configure remote consensus client" --inputbox "What is the URL for your remote \ consensus client? (right-click to paste)" 10 60 "${REMOTE_BEACON}" 3>&1 1>&2 2>&3) @@ -2822,12 +2822,12 @@ consensus client? (right-click to paste)" 10 60 "${REMOTE_BEACON}" 3>&1 1>&2 2>& } -query_checkpoint_beacon() { +__query_checkpoint_beacon() { if [ "${__minty_fresh}" -eq 1 ] || [ "${__network_change}" -eq 1 ]; then RAPID_SYNC_URL="" else - var="RAPID_SYNC_URL" - RAPID_SYNC_URL=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="RAPID_SYNC_URL" + RAPID_SYNC_URL=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) fi if [ -z "${RAPID_SYNC_URL}" ]; then case "${NETWORK}" in @@ -2856,9 +2856,9 @@ checkpoint sync provider? (right-click to paste)" 10 65 "${RAPID_SYNC_URL}" 3>&1 } -query_graffiti() { - var="GRAFFITI" - GRAFFITI=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) +__query_graffiti() { + __var="GRAFFITI" + GRAFFITI=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) while true; do GRAFFITI=$(whiptail --title "Configure Graffiti" --inputbox "What Graffiti do you want to send with your blocks? \ @@ -2875,18 +2875,18 @@ query_graffiti() { } -query_rapid_sync() { +__query_rapid_sync() { if [[ "${NETWORK}" =~ ^https?:// ]]; then RAPID_SYNC_URL="" return fi - query_checkpoint_beacon + __query_checkpoint_beacon } -query_coinbase() { - var="FEE_RECIPIENT" - FEE_RECIPIENT=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) +__query_coinbase() { + __var="FEE_RECIPIENT" + FEE_RECIPIENT=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) while true; do set +e # Can't rely on the error handler here because of the special-casing below for update() @@ -2900,9 +2900,9 @@ address? Yes even on an RPC node. Can be any address at all. (right-click to pas "${FEE_RECIPIENT}" 3>&1 1>&2 2>&3) fi - exitstatus=$? + __exitstatus=$? set -e - if [ $exitstatus -eq 0 ]; then + if [ $__exitstatus -eq 0 ]; then if [[ ${FEE_RECIPIENT} == 0x* && ${#FEE_RECIPIENT} -eq 42 ]]; then echo "Your rewards address is: ${FEE_RECIPIENT}" break @@ -2916,7 +2916,7 @@ screen.\n\nThe client will not start successfully until a valid ETH rewards addr echo "Please make requested changes manually or run \"$__me update\" again" echo "before running \"$__me up\"." echo - echo "Without a FEE_RECIPIENT set in \"${ENV_FILE}\", containers will not" + echo "Without a FEE_RECIPIENT set in \"${__env_file}\", containers will not" echo "start successfully. Already running containers will keep running with the" echo "old configuration until you are ready to restart them." else @@ -2929,7 +2929,7 @@ screen.\n\nThe client will not start successfully until a valid ETH rewards addr } -query_mev() { +__query_mev() { if [ "${NETWORK}" = "gnosis" ]; then return 0 fi @@ -2954,8 +2954,8 @@ https://0x98650451ba02064f7b000f5768cf0cf4d4e492317d82871bdc87ef841a0743f69f0f1e esac return 0 fi - var="MEV_BOOST" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="MEV_BOOST" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # I do mean to match literally # shellcheck disable=SC2076 if [[ "${CONSENSUS_CLIENT}" =~ "-vc-only.yml" ]]; then @@ -2968,9 +2968,9 @@ want to use MEV Boost?" 10 65); then fi if (whiptail --title "MEV Boost" --yesno "Do you want to use MEV Boost?" 10 65) then MEV_BOOST="true" - if [ "${value}" = "true" ]; then - var="MEV_RELAYS" - MEV_RELAYS=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + if [ "${__value}" = "true" ]; then + __var="MEV_RELAYS" + MEV_RELAYS=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) else case "${NETWORK}" in "sepolia") @@ -3008,11 +3008,11 @@ https://0x8c7d33605ecef85403f8b7289c8058f440cbb6bf72b055dfe2f3e2c6695b6a1ea5a9cd fi } -query_dkg() { +__query_dkg() { __ssv_operator_id=-1 if (whiptail --title "DKG ceremony" --yesno "Do you want to participate in DKG ceremonies as an operator?" 10 60); then __key_file_content=$(${__auto_sudo} cat ./ssv-config/encrypted_private_key.json) - __public_key=$(docompose -f ./ssv-dkg.yml run --rm curl-jq sh -c \ + __public_key=$(__docompose -f ./ssv-dkg.yml run --rm curl-jq sh -c \ "echo '${__key_file_content}' | jq -r '.pubKey'" | tail -n 1) echo "Your SSV node public key is: ${__public_key}" __ssv_operator_id=$(whiptail --title "Register SSV operator" --inputbox "\n1. Your SSV node public key:\n\n${__public_key}\n\n2. Register your operator in the SSV network with the public key\n\n3. Input your Operator ID \ @@ -3028,43 +3028,43 @@ query_dkg() { rm -f ssv-config/dkg-config.yaml.original } -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}" +__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 # Handle & in GRAFFITI gracefully - sed -i'.original' -e "s~^\(${var}\s*=\s*\).*\$~\1${!var//&/\\&}~" "${ENV_FILE}" + sed -i'.original' -e "s~^\(${__var}\s*=\s*\).*\$~\1${!__var//&/\\&}~" "${__env_file}" fi fi } -handle_error() { +__handle_error() { if [[ ! $- =~ e ]]; then # set +e, do nothing return 0 fi - local exit_code=$1 + local __exit_code=$1 echo - if [ "$exit_code" -eq 130 ]; then + if [ "$__exit_code" -eq 130 ]; then echo "$__me terminated by user" - elif [ "$__during_config" -eq 1 ] && [ "$exit_code" -eq 1 ]; then + elif [ "$__during_config" -eq 1 ] && [ "$__exit_code" -eq 1 ]; then echo "Canceled config wizard." else - echo "$__me terminated with exit code $exit_code on line $2" + echo "$__me terminated with exit code $__exit_code on line $2" if [ -n "${__command}" ]; then echo "This happened during $__me ${__command} ${__params}" fi fi if [ "$__during_update" -eq 1 ] && [ "$__during_migrate" -eq 1 ]; then - cp "${ENV_FILE}" "${ENV_FILE}".partial - cp "${ENV_FILE}".source "${ENV_FILE}" + cp "${__env_file}" "${__env_file}".partial + cp "${__env_file}".source "${__env_file}" echo - echo "Restored your ${ENV_FILE} file, to undo partial migration. Please verify it looks correct." - echo "The partially migrated file is in ${ENV_FILE}.partial for troubleshooting." + echo "Restored your ${__env_file} file, to undo partial migration. Please verify it looks correct." + echo "The partially migrated file is in ${__env_file}.partial for troubleshooting." fi if [ "$__during_postgres" -eq 1 ]; then echo @@ -3075,7 +3075,7 @@ handle_error() { echo "Starting the node again could get you slashed." echo echo "Marking Web3signer as unsafe to start." - dodocker run --rm -v "$(dodocker volume ls -q -f "name=web3signer-keys")":/var/lib/web3signer \ + __dodocker run --rm -v "$(__dodocker volume ls -q -f "name=web3signer-keys")":/var/lib/web3signer \ alpine:3 touch /var/lib/web3signer/.migration_fatal_error elif [ "$__migrated" -eq 1 ]; then echo "Web3signer slashing protection database migration failed, after switching to the migrated data." @@ -3092,18 +3092,18 @@ handle_error() { } -check_legacy() { - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) +__check_legacy() { + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Literal match intended # shellcheck disable=SC2076 - if [[ "${value}" =~ "-allin1.yml" && ! "${value}" =~ "grandine-allin1.yml" ]]; then # Warn re Grandine once VC - if [[ "${value}" =~ "teku-allin1.yml" ]]; then + if [[ "${__value}" =~ "-allin1.yml" && ! "${__value}" =~ "grandine-allin1.yml" ]]; then # Warn re Grandine once VC + if [[ "${__value}" =~ "teku-allin1.yml" ]]; then __client="Teku" - elif [[ "${value}" =~ "nimbus-allin1.yml" ]]; then + elif [[ "${__value}" =~ "nimbus-allin1.yml" ]]; then __client="Nimbus" - elif [[ "${value}" =~ "grandine-allin1.yml" ]]; then + elif [[ "${__value}" =~ "grandine-allin1.yml" ]]; then __client="Grandine" else __client="Mystery" @@ -3119,8 +3119,8 @@ config() { # Do not track changes to ext-network.yml ${__as_owner} git update-index --assume-unchanged ext-network.yml # Create ENV file if needed - if ! [[ -f "${ENV_FILE}" ]]; then - ${__as_owner} cp default.env "${ENV_FILE}" + if ! [[ -f "${__env_file}" ]]; then + ${__as_owner} cp default.env "${__env_file}" __minty_fresh=1 else __minty_fresh=0 @@ -3128,15 +3128,15 @@ config() { __during_config=1 - check_legacy - query_network - query_deployment + __check_legacy + __query_network + __query_deployment case "${__deployment}" in "node") - query_consensus_client + __query_consensus_client ;; "validator" | "rocket") - query_validator_client + __query_validator_client ;; "ssv") if [ "${NETWORK}" = "holesky" ]; then @@ -3158,17 +3158,17 @@ config() { fi if [ ! -f "./ssv-config/encrypted_private_key.json" ]; then echo "Creating encrypted operator private key" - dodocker run --name ssv-node-key-generation -v "$(pwd)/ssv-config/password.pass":/password.pass \ + __dodocker run --name ssv-node-key-generation -v "$(pwd)/ssv-config/password.pass":/password.pass \ -it bloxstaking/ssv-node:latest /go/bin/ssvnode generate-operator-keys \ - --password-file=/password.pass && dodocker cp ssv-node-key-generation:/encrypted_private_key.json \ - ./ssv-config/encrypted_private_key.json && dodocker rm ssv-node-key-generation + --password-file=/password.pass && __dodocker cp ssv-node-key-generation:/encrypted_private_key.json \ + ./ssv-config/encrypted_private_key.json && __dodocker rm ssv-node-key-generation ${__auto_sudo} chown 12000:12000 ./ssv-config/encrypted_private_key.json fi - query_dkg - query_consensus_only_client + __query_dkg + __query_consensus_only_client ;; "rpc") - query_consensus_only_client + __query_consensus_only_client ;; *) echo "Unknown deployment ${__deployment}, this is a bug." @@ -3182,25 +3182,25 @@ config() { if [[ ! "${CONSENSUS_CLIENT}" =~ "-vc-only.yml" ]]; then CL_NODE="http://consensus:5052" - query_execution_client - query_rapid_sync - query_mev - query_grafana - query_coinbase + __query_execution_client + __query_rapid_sync + __query_mev + __query_grafana + __query_coinbase if [ "${__deployment}" = "node" ]; then - query_graffiti + __query_graffiti fi else unset EXECUTION_CLIENT unset GRAFANA_CLIENT - query_remote_beacon + __query_remote_beacon # This gets used, but shellcheck doesn't recognize that # shellcheck disable=SC2034 CL_NODE="${REMOTE_BEACON}" - query_mev - query_coinbase - query_graffiti + __query_mev + __query_coinbase + __query_graffiti fi __during_config=0 @@ -3234,59 +3234,59 @@ config() { echo "Your COMPOSE_FILE is:" "${COMPOSE_FILE}" - var=FEE_RECIPIENT - set_value_in_env - var=GRAFFITI - set_value_in_env - var=CL_NODE - set_value_in_env - var=RAPID_SYNC_URL - set_value_in_env - var=COMPOSE_FILE - set_value_in_env - var=EL_NODE - set_value_in_env - var=JWT_SECRET - set_value_in_env - var=NETWORK - set_value_in_env - var=MEV_BOOST - set_value_in_env - var=MEV_RELAYS - set_value_in_env + __var=FEE_RECIPIENT + __set_value_in_env + __var=GRAFFITI + __set_value_in_env + __var=CL_NODE + __set_value_in_env + __var=RAPID_SYNC_URL + __set_value_in_env + __var=COMPOSE_FILE + __set_value_in_env + __var=EL_NODE + __set_value_in_env + __var=JWT_SECRET + __set_value_in_env + __var=NETWORK + __set_value_in_env + __var=MEV_BOOST + __set_value_in_env + __var=MEV_RELAYS + __set_value_in_env if [[ "${NETWORK}" = "gnosis" ]] && [[ "${CONSENSUS_CLIENT}" =~ "nimbus" ]] ; then # We are using the variable # shellcheck disable=SC2034 NIM_DOCKERFILE=Dockerfile.sourcegnosis - var=NIM_DOCKERFILE - set_value_in_env + __var=NIM_DOCKERFILE + __set_value_in_env fi if uname -m | grep -q riscv64; then # We are using the variable # shellcheck disable=SC2034 NIM_DOCKERFILE=Dockerfile.source - var=NIM_DOCKERFILE - set_value_in_env + __var=NIM_DOCKERFILE + __set_value_in_env # We are using the variable # shellcheck disable=SC2034 GETH_DOCKERFILE=Dockerfile.source - var=GETH_DOCKERFILE - set_value_in_env + __var=GETH_DOCKERFILE + __set_value_in_env fi - var="SIREN_PASSWORD" - SIREN_PASSWORD=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="SIREN_PASSWORD" + SIREN_PASSWORD=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) if [ -z "${SIREN_PASSWORD}" ]; then SIREN_PASSWORD=$(head -c 8 /dev/urandom | od -A n -t u8 | tr -d '[:space:]' | sha256sum | head -c 32) - set_value_in_env + __set_value_in_env fi ${__as_owner} rm .env.original - pull_and_build - nag_os_version + __pull_and_build + __nag_os_version echo - echo "Your configuration file is: $(dirname "$(realpath "${BASH_SOURCE[0]}")")/${ENV_FILE}" + echo "Your configuration file is: $(dirname "$(realpath "${BASH_SOURCE[0]}")")/${__env_file}" echo "You can change advanced config items with \"nano .env\" when in the $(dirname "$(realpath "${BASH_SOURCE[0]}")") directory." echo } @@ -3295,108 +3295,108 @@ config() { version() { grep "^This is" README.md echo - var="COMPOSE_FILE" - value=$(sed -n -e "s/^${var}=\(.*\)/\1/p" "${ENV_FILE}" || true) + __var="COMPOSE_FILE" + __value=$(sed -n -e "s/^${__var}=\(.*\)/\1/p" "${__env_file}" || true) # Client versions - case "${value}" in + case "${__value}" in *ssv.yml* ) - docompose exec ssv-node /go/bin/ssvnode --version + __docompose exec ssv-node /go/bin/ssvnode --version echo ;;& *lighthouse.yml* | *lighthouse-cl-only* ) - docompose exec consensus lighthouse --version + __docompose exec consensus lighthouse --version echo ;;& *lighthouse-vc-only* ) - docompose exec validator lighthouse --version + __docompose exec validator lighthouse --version echo ;;& *lodestar.yml* | *lodestar-cl-only* ) - docompose exec consensus node /usr/app/node_modules/.bin/lodestar --version + __docompose exec consensus node /usr/app/node_modules/.bin/lodestar --version echo ;;& *lodestar-vc-only* ) - docompose exec validator node /usr/app/node_modules/.bin/lodestar --version + __docompose exec validator node /usr/app/node_modules/.bin/lodestar --version echo ;;& *prysm.yml* ) - docompose exec consensus beacon-chain --version + __docompose exec consensus beacon-chain --version echo - docompose exec validator validator --version + __docompose exec validator validator --version echo ;;& *prysm-cl-only* ) - docompose exec consensus beacon-chain --version + __docompose exec consensus beacon-chain --version echo ;;& *prysm-vc-only* ) - docompose exec validator validator --version + __docompose exec validator validator --version echo ;;& *nimbus.yml* | *nimbus-allin1.yml* | *nimbus-cl-only* ) - docompose exec consensus nimbus_beacon_node --version + __docompose exec consensus nimbus_beacon_node --version echo ;;& *nimbus-vc-only* ) - docompose exec validator nimbus_validator_client --version + __docompose exec validator nimbus_validator_client --version echo ;;& *teku.yml* | *teku-allin1.yml* | *teku-cl-only* ) - docompose exec consensus /opt/teku/bin/teku --version + __docompose exec consensus /opt/teku/bin/teku --version echo ;;& *teku-vc-only* ) - docompose exec validator /opt/teku/bin/teku --version + __docompose exec validator /opt/teku/bin/teku --version echo ;;& *grandine.yml* | *grandine-allin1.yml* | *grandine-cl-only* ) - docompose exec consensus grandine --version + __docompose exec consensus grandine --version echo ;;& *grandine-vc-only* ) - docompose exec validator grandine --version + __docompose exec validator grandine --version echo ;;& *geth.yml* ) - docompose exec execution geth version + __docompose exec execution geth version echo ;;& *reth.yml* ) - docompose exec execution reth --version + __docompose exec execution reth --version echo ;;& *besu.yml* ) - docompose exec execution /opt/besu/bin/besu --version + __docompose exec execution /opt/besu/bin/besu --version echo ;;& *nethermind.yml* ) - docompose exec execution /nethermind/nethermind --version + __docompose exec execution /nethermind/nethermind --version echo ;;& *erigon.yml* ) - docompose exec execution erigon --version + __docompose exec execution erigon --version echo ;;& *web3signer.yml* ) - docompose exec web3signer /opt/web3signer/bin/web3signer --version + __docompose exec web3signer /opt/web3signer/bin/web3signer --version echo - docompose exec postgres pg_config --version + __docompose exec postgres pg_config --version echo ;;& *mev-boost.yml* ) - docompose exec mev-boost /app/mev-boost -version + __docompose exec mev-boost /app/mev-boost -version echo ;;& *grafana.yml* ) - docompose exec prometheus /bin/prometheus --version + __docompose exec prometheus /bin/prometheus --version echo echo -n "Grafana " - docompose exec grafana /run.sh -v + __docompose exec grafana /run.sh -v echo ;;& *traefik-*.yml* ) echo "Traefik" - docompose exec traefik traefik version + __docompose exec traefik traefik version echo ;;& esac @@ -3432,7 +3432,7 @@ __full_help() { echo " Run without ACTION to get help text" echo " update [--refresh-targets] [--non-interactive]" echo " updates all client versions and ${__project_name} itself" - echo " --refresh-targets will reset your custom build targets in ${ENV_FILE} to defaults" + echo " --refresh-targets will reset your custom build targets in ${__env_file} to defaults" echo " up|start [service-name]" echo " starts the Ethereum node, or restarts containers that had their image or" echo " configuration changed. Can also start a specific service by name" @@ -3489,7 +3489,7 @@ help() { } # Main body from here -ENV_FILE=.env +__env_file=.env __during_config=0 __during_update=0 __during_postgres=0 @@ -3501,7 +3501,7 @@ if [ ! -f ~/.profile ] || ! grep -q "alias ethd" ~/.profile; then __me="./$__me" fi -trap 'handle_error $? $LINENO' ERR +trap '__handle_error $? $LINENO' ERR if [[ "$#" -eq 0 || "$*" =~ "-h" ]]; then # Lazy match for -h and --help but also --histogram, so careful here help "$@" @@ -3523,11 +3523,11 @@ __command="$1" shift __params=$* -handle_root -determine_distro -prep_conffiles +__handle_root +__determine_distro +__prep_conffiles -check_for_snap +__check_for_snap # Don't check for Docker before it's installed if [ "$__command" = "install" ]; then @@ -3535,8 +3535,8 @@ if [ "$__command" = "install" ]; then exit "$?" fi -handle_docker_sudo -check_compose_version +__handle_docker_sudo +__check_compose_version if [ "${__old_compose}" -eq 1 ]; then echo @@ -3564,12 +3564,12 @@ if ! type -P whiptail >/dev/null 2>&1; then exit 0 fi -if ! dodocker images >/dev/null 2>&1; then +if ! __dodocker images >/dev/null 2>&1; then echo "Please ensure you can call $__docker_exe before running ${__project_name}." exit 0 fi -if ! docompose --help >/dev/null 2>&1; then +if ! __docompose --help >/dev/null 2>&1; then echo "Please ensure you can call $__compose_exe before running ${__project_name}." exit 0 fi @@ -3584,7 +3584,7 @@ case "$__command" in ;; esac -check_disk_space +__check_disk_space if [ "${__compose_upgraded}" -eq 1 ]; then echo