From e5d5d0c62195b5995c0f723bce34b5ea62279313 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Thu, 28 Dec 2023 07:20:57 -0500 Subject: Preliminary implementation of update script This version leverages most of the wrapper logic flow from utils/porkbun-ip-update. Currently lacks guarding and better logging --- update.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 update.sh (limited to 'update.sh') diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..ab023a7 --- /dev/null +++ b/update.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh +set -e + +# Not needed but useful to know +function aws_ip_check { + + aws route53 list-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID \ + --query "ResourceRecordSets[?(Name == 'senders.io.' && Type == 'A')].ResourceRecords[0].Value | [0]" --output text +} + +if [ $# -ne 2 ]; then + echo "Usage: ./update.sh HOSTED_ZONE_ID DOMAIN" +fi +HOSTED_ZONE_ID=$1 +DOMAIN=$2 +source API_CONFIG +RECORD_CHANGE_JSON=/tmp/aws-ip-update.json + +# Fetch IPs + +config_ip=$(dig +short $DOMAIN) +actual_ip=$(curl -s https://ipinfo.io/ip) + +if [ "$config_ip" != "$actual_ip" ]; then + echo "Updating IP from $config_id to $actual_ip for $DOMAIN" + cat < $RECORD_CHANGE_JSON +{ + "Changes": [ + "Action": "UPSERT", + "ResourceRecordSet": { + "Name": "$DOMAIN", + "Type": "A", + "TTL": 300, + "ResourceRecords": [ + "Value": "$actual_ip" + ] + } + ] +} +EOF + aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID \ + --change-batch $RECORD_CHANGE_JSON + +else + echo "$DOMAIN is currently registered properly: $config_ip $actual_ip" +fi + +exit 0 -- cgit v1.2.3-54-g00ecf