File tree 1 file changed +29
-3
lines changed
1 file changed +29
-3
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
set -eu
3
3
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
+
4
25
if [[ -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
7
28
fi
8
29
9
30
# 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
13
34
done
14
35
15
36
# 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
17
43
export OP_NODE_P2P_ADVERTISE_IP=$PUBLIC_IP
18
44
19
45
echo " $OP_NODE_L2_ENGINE_AUTH_RAW " > " $OP_NODE_L2_ENGINE_AUTH "
You can’t perform that action at this time.
0 commit comments