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 --- README.txt | 8 ++++++-- update.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100755 update.sh diff --git a/README.txt b/README.txt index 802ccc5..d0fef94 100644 --- a/README.txt +++ b/README.txt @@ -15,8 +15,12 @@ Edit "config" file (this is a bash sourcable file) Set: -AWS_SECRET_KEY -AWS_ +export AWS_SECRET_KEY= +export AWS_SECRET_ACCESS_KEY= + +HOSTED_ZONE_ID= +DOMAIN= +# Note ^ make sure domain is in the form "senders.io." <- note the trailing . == USAGE 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