github.com/status-im/status-go@v1.1.0/_assets/scripts/get_enode.sh (about) 1 #!/usr/bin/env bash 2 3 RPC_ADDR="${RPC_ADDR:-localhost}" 4 RPC_PORT="${RPC_PORT:-8545}" 5 # might be provided by parent 6 if [[ -z "${PUBLIC_IP}" ]]; then 7 PUBLIC_IP=$(curl -s https://ipecho.net/plain) 8 fi 9 # Necessary for enode address for Status app 10 MAIL_PASSWORD="${MAIL_PASSWORD:-status-offline-inbox}" 11 12 # query local 13 RESP_JSON=$( 14 curl -sS --retry 3 --retry-connrefused \ 15 -X POST http://${RPC_ADDR}:${RPC_PORT}/ \ 16 -H 'Content-type: application/json' \ 17 -d '{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}' 18 ) 19 if [[ "$?" -ne 0 ]]; then 20 echo "RPC port not up, unable to query enode address!" 1>&2 21 exit 1 22 fi 23 24 # extract enode from JSON response 25 ENODE_RAW=$(echo "${RESP_JSON}" | jq -r '.result.enode') 26 # drop arguments at the end of enode address 27 ENODE_CLEAN=$(echo "${ENODE_RAW}" | grep -oP '\Kenode://[^?]+') 28 29 # replace localhost with public IP and add mail password 30 ENODE=$(echo "${ENODE_CLEAN}" | sed \ 31 -e "s/127.0.0.1/${PUBLIC_IP}/" \ 32 -e "s/@/:${MAIL_PASSWORD}@/") 33 34 if [[ "$1" == "--qr" ]]; then 35 if ! [ -x "$(command -v qrencode)" ]; then 36 echo 'Install 'qrencode' for enode QR code.' >&2 37 exit 0 38 fi 39 qrencode -t UTF8 "${ENODE}" 40 else 41 echo "${ENODE}" 42 fi