diff --git a/distros/raspberry_pi/config-consensus.txt b/distros/raspberry_pi/config-consensus.txt index cf5c4d5..8b32d77 100644 --- a/distros/raspberry_pi/config-consensus.txt +++ b/distros/raspberry_pi/config-consensus.txt @@ -18,12 +18,12 @@ geth_port=30303 [nimbus] nimbus_port=9000 -# Ethereum network: mainnet/holesky/sepolia/goerli +# Ethereum network: mainnet/holesky/sepolia nimbus_network=mainnet [lighthouse] lighthouse_port=9000 -# Ethereum network: mainnet/holesky/sepolia/goerli +# Ethereum network: mainnet/holesky/sepolia lighthouse_network=mainnet # End of Web3 Pi config diff --git a/distros/raspberry_pi/config-exec.txt b/distros/raspberry_pi/config-exec.txt index 5b7f23d..aa22848 100644 --- a/distros/raspberry_pi/config-exec.txt +++ b/distros/raspberry_pi/config-exec.txt @@ -18,12 +18,12 @@ geth_port=30303 [nimbus] nimbus_port=9000 -# Ethereum network: mainnet/holesky/sepolia/goerli +# Ethereum network: mainnet/holesky/sepolia nimbus_network=mainnet [lighthouse] lighthouse_port=9000 -# Ethereum network: mainnet/holesky/sepolia/goerli +# Ethereum network: mainnet/holesky/sepolia lighthouse_network=mainnet # End of Web3 Pi config diff --git a/distros/raspberry_pi/config.txt b/distros/raspberry_pi/config.txt index 7d18505..e6ff757 100644 --- a/distros/raspberry_pi/config.txt +++ b/distros/raspberry_pi/config.txt @@ -20,12 +20,12 @@ geth_port=30303 [nimbus] nimbus_port=9000 -# Ethereum network: mainnet/holesky/sepolia/goerli +# Ethereum network: mainnet/holesky/sepolia nimbus_network=mainnet [lighthouse] lighthouse_port=9000 -# Ethereum network: mainnet/holesky/sepolia/goerli +# Ethereum network: mainnet/holesky/sepolia lighthouse_network=mainnet # End of Web3 Pi config diff --git a/distros/raspberry_pi/install.sh b/distros/raspberry_pi/install.sh index d04d87e..0eb599f 100644 --- a/distros/raspberry_pi/install.sh +++ b/distros/raspberry_pi/install.sh @@ -557,11 +557,18 @@ if [ "$(get_install_stage)" -eq 2 ]; then echolog "Adding client directories required to run the node" sudo -u ethereum mkdir -p /home/ethereum/clients/secrets/ - set_status "[install.sh] - Generating the jwt.hex file" - #sudo -u ethereum openssl rand -hex 32 | tr -d "\n" | tee /home/ethereum/clients/secrets/jwt.hex - sudo -u ethereum openssl rand -hex 32 | sudo -u ethereum tr -d "\n" | sudo -u ethereum tee /home/ethereum/clients/secrets/jwt.hex - echolog " " - + set_status "[install.sh] - Prepare the jwt.hex file" + # Check if the file exists + if [ -f "/boot/firmware/jwt.hex" ]; then + # Move the file to the destination directory + mv "/boot/firmware/jwt.hex" "/home/ethereum/clients/secrets/" + echolog "The /boot/firmware/jwt.hex file has been moved to /home/ethereum/clients/secrets/" + else + echolog "The /boot/firmware/jwt.hex file does not exist. Generating new jwt.hex file" + sudo -u ethereum openssl rand -hex 32 | sudo -u ethereum tr -d "\n" | sudo -u ethereum tee /home/ethereum/clients/secrets/jwt.hex + echolog " " + fi + set_status "[install.sh] - Copying scripts to /home/ethereum/scripts" ln -s /opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/ /home/ethereum/ chmod +x /opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/*.sh diff --git a/distros/raspberry_pi/lighthouse/lighthouse.sh b/distros/raspberry_pi/lighthouse/lighthouse.sh index 00382e6..e4db761 100644 --- a/distros/raspberry_pi/lighthouse/lighthouse.sh +++ b/distros/raspberry_pi/lighthouse/lighthouse.sh @@ -72,7 +72,7 @@ while [ $? -ne 0 ]; do done # Script for finding the best server -source /opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/pingServers.sh +source /opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/ping_servers.sh echolog "$(date): Connected - ${pingServerAdr}" echolog "exec_url = ${exec_url}" diff --git a/distros/raspberry_pi/nimbus/nimbus.sh b/distros/raspberry_pi/nimbus/nimbus.sh index 9e4684c..fd5d654 100644 --- a/distros/raspberry_pi/nimbus/nimbus.sh +++ b/distros/raspberry_pi/nimbus/nimbus.sh @@ -87,10 +87,19 @@ echolog "nimbus_port = ${nimbus_port}" echolog "nimbus_network = ${nimbus_network}" echolog "nimbus_dir = ${nimbus_dir}" -bash /opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/sort_servers.sh - # File with the list of servers -SERVERS_FILE="/opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/serversList.txt" +SERVERS_FILE="/opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/servers_list_${nimbus_network}.txt" + +if [ -f "${SERVERS_FILE}" ]; then + echolog "SERVERS_FILE = ${SERVERS_FILE}" +else + echolog "File ${SERVERS_FILE} does not exist." + return 1 +fi + +bash /opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/servers_sort.sh $SERVERS_FILE + +sleep 1 # Iterate through each server from the list success=false diff --git a/distros/raspberry_pi/scripts/pingServers.sh b/distros/raspberry_pi/scripts/ping_servers.sh similarity index 79% rename from distros/raspberry_pi/scripts/pingServers.sh rename to distros/raspberry_pi/scripts/ping_servers.sh index a62bce3..7e7cc03 100644 --- a/distros/raspberry_pi/scripts/pingServers.sh +++ b/distros/raspberry_pi/scripts/ping_servers.sh @@ -1,6 +1,16 @@ #!/bin/bash -servers_file="/opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/serversList.txt" +# Read custom config flags from /boot/firmware/config.txt +config_read_file() { + (grep -E "^${2}=" -m 1 "${1}" 2>/dev/null || echo "VAR=UNDEFINED") | head -n 1 | cut -d '=' -f 2-; +} + +config_get() { + val="$(config_read_file /boot/firmware/config.txt "${1}")"; + printf -- "%s" "${val}"; +} + +servers_file="/opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/servers_list_${lighthouse_network}.txt" best_server="" best_ping=1000000 # set a very high initial value diff --git a/distros/raspberry_pi/scripts/servers_list_holesky.txt b/distros/raspberry_pi/scripts/servers_list_holesky.txt new file mode 100644 index 0000000..0a84a0c --- /dev/null +++ b/distros/raspberry_pi/scripts/servers_list_holesky.txt @@ -0,0 +1,5 @@ +https://holesky.beaconstate.info +https://holesky-checkpoint-sync.stakely.io +https://beaconstate-holesky.chainsafe.io +https://holesky.beaconstate.ethstaker.cc +https://checkpoint-sync.holesky.ethpandaops.io \ No newline at end of file diff --git a/distros/raspberry_pi/scripts/serversList.txt b/distros/raspberry_pi/scripts/servers_list_mainnet.txt similarity index 100% rename from distros/raspberry_pi/scripts/serversList.txt rename to distros/raspberry_pi/scripts/servers_list_mainnet.txt diff --git a/distros/raspberry_pi/scripts/servers_list_sepolia.txt b/distros/raspberry_pi/scripts/servers_list_sepolia.txt new file mode 100644 index 0000000..591947d --- /dev/null +++ b/distros/raspberry_pi/scripts/servers_list_sepolia.txt @@ -0,0 +1,3 @@ +https://checkpoint-sync.sepolia.ethpandaops.io +https://beaconstate-sepolia.chainsafe.io +https://sepolia.beaconstate.info \ No newline at end of file diff --git a/distros/raspberry_pi/scripts/sort_servers.sh b/distros/raspberry_pi/scripts/servers_sort.sh similarity index 61% rename from distros/raspberry_pi/scripts/sort_servers.sh rename to distros/raspberry_pi/scripts/servers_sort.sh index 52b1764..861bf62 100644 --- a/distros/raspberry_pi/scripts/sort_servers.sh +++ b/distros/raspberry_pi/scripts/servers_sort.sh @@ -1,9 +1,27 @@ #!/bin/bash -echo "Start sorting server list..." +# Function: echolog +# Description: Logs messages with a timestamp prefix. If no arguments are provided, +# reads from stdin and logs each line. Outputs to console and appends to $LOGI file. +LOGI="/var/log/web3pi.log" +echolog(){ + if [ $# -eq 0 ] + then cat - | while read -r message + do + echo "$(date +"[%F %T %Z] -") $message" | tee -a $LOGI + done + else + echo -n "$(date +'[%F %T %Z]') - " | tee -a $LOGI + echo "$*" | tee -a $LOGI + fi +} + +echolog "Start sorting server list..." # File with the list of servers -SERVERS_FILE="/opt/web3pi/Ethereum-On-Raspberry-Pi/distros/raspberry_pi/scripts/serversList.txt" +SERVERS_FILE=$1 + +echolog "SERVERS_FILE = ${SERVERS_FILE}" # Check if the file exists if [ ! -f "$SERVERS_FILE" ]; then @@ -45,4 +63,4 @@ awk '{print $2}' "$TEMP_FILE" > "$SERVERS_FILE" # Remove the temporary file rm "$TEMP_FILE" -echo "The server list has been sorted based on average ping times." +echolog "The server list has been sorted based on average ping times."