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