File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /bin/bash
22set -eu
33
4+ get_public_ip () {
5+ # Define a list of HTTP-based providers
6+ local PROVIDERS=(
7+ " http://ifconfig.me"
8+ " http://api.ipify.org"
9+ " http://ipecho.net/plain"
10+ " http://v4.ident.me"
11+ )
12+ # Iterate through the providers until an IP is found or the list is exhausted
13+ for provider in " ${PROVIDERS[@]} " ; do
14+ local IP
15+ IP=$( curl -s " $provider " )
16+ # Check if IP contains a valid format (simple regex for an IPv4 address)
17+ if [[ $IP =~ ^[0-9]+\. [0-9]+\. [0-9]+\. [0-9]+$ ]]; then
18+ echo " $IP "
19+ return 0
20+ fi
21+ done
22+ return 1
23+ }
24+
425if [[ -z " $OP_NODE_NETWORK " ]]; then
5- echo " expected OP_NODE_NETWORK to be set" 1>&2
6- exit 1
26+ echo " expected OP_NODE_NETWORK to be set" 1>&2
27+ exit 1
728fi
829
930# wait until local geth comes up (authed so will return 401 without token)
@@ -13,7 +34,12 @@ until [ "$(curl -s -w '%{http_code}' -o /dev/null "${OP_NODE_L2_ENGINE_RPC/ws/ht
1334done
1435
1536# public-facing P2P node, advertise public IP address
16- PUBLIC_IP=$( curl -s v4.ident.me)
37+ if PUBLIC_IP=$( get_public_ip) ; then
38+ echo " fetched public IP is: $PUBLIC_IP "
39+ else
40+ echo " Could not retrieve public IP."
41+ exit 8
42+ fi
1743export OP_NODE_P2P_ADVERTISE_IP=$PUBLIC_IP
1844
1945echo " $OP_NODE_L2_ENGINE_AUTH_RAW " > " $OP_NODE_L2_ENGINE_AUTH "
You can’t perform that action at this time.
0 commit comments