2019-09-16 09:38:33 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
RPC_ADDR="${RPC_ADDR:-localhost}"
|
|
|
|
RPC_PORT="${RPC_PORT:-8545}"
|
|
|
|
# might be provided by parent
|
|
|
|
if [[ -z "${PUBLIC_IP}" ]]; then
|
|
|
|
PUBLIC_IP=$(curl -s https://ipecho.net/plain)
|
|
|
|
fi
|
2020-01-23 09:20:17 +00:00
|
|
|
# Necessary for enode address for Status app
|
|
|
|
MAIL_PASSWORD="${MAIL_PASSWORD:-status-offline-inbox}"
|
2019-09-16 09:38:33 +00:00
|
|
|
|
|
|
|
# query local
|
|
|
|
RESP_JSON=$(
|
|
|
|
curl -s -XPOST http://${RPC_ADDR}:${RPC_PORT}/ \
|
|
|
|
-H 'Content-type: application/json' \
|
|
|
|
-d '{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}'
|
|
|
|
)
|
|
|
|
if [[ "$?" -ne 0 ]]; then
|
|
|
|
echo "RPC port not up, unable to query enode address!" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# extract enode from JSON response
|
|
|
|
ENODE_RAW=$(echo "${RESP_JSON}" | jq -r '.result.enode')
|
|
|
|
# drop arguments at the end of enode address
|
|
|
|
ENODE_CLEAN=$(echo "${ENODE_RAW}" | grep -oP '\Kenode://[^?]+')
|
|
|
|
|
2020-01-23 09:20:17 +00:00
|
|
|
# replace localhost with public IP and add mail password
|
|
|
|
echo "${ENODE_CLEAN}" | sed \
|
|
|
|
-e "s/127.0.0.1/${PUBLIC_IP}/" \
|
|
|
|
-e "s/@/:${MAIL_PASSWORD}@/"
|