-
-
Save grahamc/dba13660a088431857d7e5461b0ee2ff to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
set -eux | |
# More advanced options below | |
# The Time-To-Live of this recordset | |
dns() { | |
RECORD=$1 | |
TYPE=$2 | |
IP=$3 | |
TTL=300 | |
# Fill a temp file with valid JSON | |
TMPFILE=$(mktemp /tmp/temporary-file.XXXXXXXX) | |
cat > ${TMPFILE} << EOF | |
{ | |
"Changes":[ | |
{ | |
"Action":"UPSERT", | |
"ResourceRecordSet":{ | |
"ResourceRecords":[ | |
{ | |
"Value":"$IP" | |
} | |
], | |
"Name":"$RECORD", | |
"Type":"$TYPE", | |
"TTL":$TTL | |
} | |
} | |
] | |
} | |
EOF | |
# Update the Hosted Zone record | |
aws route53 change-resource-record-sets \ | |
--hosted-zone-id $ZONEID \ | |
--change-batch file://"$TMPFILE" | |
echo "" | |
# Clean up | |
rm $TMPFILE | |
} | |
dns "$(hostname).wg.gsc.io" "A" "$(ip --json addr show dev wg0 \ | |
| jq -r '.[] | .addr_info[] | select(.family == "inet") | .local')" | |
dns "$(hostname).gsc.io" "A" "$(curl https://ipv4.icanhazip.com)" | |
dns "$(hostname).gsc.io" "AAAA" "$(curl https://ipv6.icanhazip.com)" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment