|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Create the DNS TXT record from the list of nodes |
| 4 | + |
| 5 | +unset BOOTNODES |
| 6 | +unset NETWORK |
| 7 | +unset DOMAIN |
| 8 | +unset IP_LIST |
| 9 | +PROGNAME=$(basename "$0") |
| 10 | + |
| 11 | +USAGE="$PROGNAME -b bootnodes -n network -d domain [-i ip_list] |
| 12 | +
|
| 13 | +where: |
| 14 | + bootnodes: list of bootnodes to crawl from (comma separated) |
| 15 | + network: ronin-mainnet | ronin-testnet to choose the network |
| 16 | + domain: the DNS domain name |
| 17 | + ip_list: the list of IPs to include in ENR tree (comma separated) |
| 18 | +" |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +while getopts :hb:n:d:i: option; do |
| 23 | + case $option in |
| 24 | + h) |
| 25 | + echo "$USAGE" |
| 26 | + exit 0 |
| 27 | + ;; |
| 28 | + b) BOOTNODES=$OPTARG ;; |
| 29 | + n) NETWORK=$OPTARG ;; |
| 30 | + d) DOMAIN=$OPTARG ;; |
| 31 | + i) IP_LIST=$OPTARG ;; |
| 32 | + :) |
| 33 | + echo "$PROGNAME: option requires an argument -- '$OPTARG'" >&2 |
| 34 | + exit 1 |
| 35 | + ;; |
| 36 | + *) |
| 37 | + echo "$PROGNAME: bad option -$OPTARG" >&2 |
| 38 | + echo "Try '$PROGNAME -h' for more information" >&2 |
| 39 | + exit 1 |
| 40 | + ;; |
| 41 | + esac |
| 42 | +done |
| 43 | +shift $((OPTIND - 1)) |
| 44 | + |
| 45 | +if [[ -z $BOOTNODES || -z $NETWORK || -z $DOMAIN ]]; then |
| 46 | + echo "$PROGNAME: missing mandatory option" >&2 |
| 47 | + echo "Try '$(basename "$0") -h' for more information" >&2 |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | + |
| 51 | +DNS_DIR=dns_record |
| 52 | + |
| 53 | +if [[ -z $PRIVATE_KEY ]]; then |
| 54 | + echo "The PRIVATE_KEY environment for signing DNS record must be provided" |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +if [[ -z $PASSWORD ]]; then |
| 59 | + echo "The PASSWORD environment for decrypting the private key must be provided" |
| 60 | + exit 1 |
| 61 | +fi |
| 62 | + |
| 63 | +echo "$PASSWORD" > password |
| 64 | +echo "$PRIVATE_KEY" > private_key |
| 65 | +unset PASSWORD |
| 66 | +unset PRIVATE_KEY |
| 67 | + |
| 68 | +set -x |
| 69 | +# Create an encrypted keyfile.json |
| 70 | +ethkey generate --passwordfile password --privatekey private_key |
| 71 | + |
| 72 | +devp2p discv4 crawl --timeout 1m --bootnodes $BOOTNODES all_nodes.json |
| 73 | + |
| 74 | +mkdir -p $DNS_DIR |
| 75 | + |
| 76 | +set +x |
| 77 | +IP_LIST_PARAMS="" |
| 78 | +if [[ ! -z $IP_LIST ]]; then |
| 79 | + IP_LIST_PARAMS="-ip-list $IP_LIST" |
| 80 | +fi |
| 81 | +set -x |
| 82 | + |
| 83 | +devp2p nodeset filter all_nodes.json -eth-network $NETWORK $IP_LIST_PARAMS > $DNS_DIR/nodes.json |
| 84 | +devp2p dns sign $DNS_DIR keyfile.json password --domain $DOMAIN |
| 85 | +devp2p dns to-txt $DNS_DIR $DNS_DIR/txt_record.json |
| 86 | + |
| 87 | +echo "Cleanup files" |
| 88 | +rm private_key |
| 89 | +rm password |
| 90 | +rm keyfile.json |
0 commit comments