Created
March 12, 2025 22:23
-
-
Save DasSkelett/1c5a321649504568c4e1f501cd8d9473 to your computer and use it in GitHub Desktop.
Dynamic DNS records for Freifunk nodes from meshviewer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
# prefix of node hostnames to filter for | |
PREFIX="" | |
# TSIG key name | |
KEYNAME="" | |
# base64 encoded TSIG key | |
KEY="" | |
# base domain / zone where records should be added | |
BASEDOMAIN="" | |
# address of authoritative DNS server for the above specified zone | |
DNSSERVER="" | |
NODES=$(curl -sSL https://map.ffmuc.net/data/meshviewer.json | jq '[.nodes[] | select(.hostname | startswith("$PREFIX")) | pick(.hostname, .node_id, .addresses)]') | |
cmd=" | |
server $DNSSERVER 53 | |
zone $BASEDOMAIN | |
" | |
#echo "$NODES" | jq -c '.[]' | while read -r node | |
while read -r node | |
do | |
hostname=$(echo "$node" | jq -r '.hostname') | |
id=$(echo "$node" | jq -r '.node_id') | |
ip0=$(echo "$node" | jq -r '.addresses[0]') | |
ip1=$(echo "$node" | jq -r '.addresses[1]') | |
cmd+="update delete $hostname.$BASEDOMAIN. AAAA"$'\n' | |
cmd+="update delete $id.$BASEDOMAIN. AAAA"$'\n' | |
cmd+="update add $hostname.$BASEDOMAIN. 300 AAAA $ip0"$'\n' | |
cmd+="update add $hostname.$BASEDOMAIN. 300 AAAA $ip1"$'\n' | |
cmd+="update add $id.$BASEDOMAIN. 300 AAAA $ip0"$'\n' | |
cmd+="update add $id.$BASEDOMAIN. 300 AAAA $ip1"$'\n' | |
done < <(echo "$NODES" | jq -c '.[]') | |
cmd+="key hmac-sha512:$KEYNAME $KEY"$'\nsend\n' | |
echo "$cmd" | nsupdate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment