summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.txt8
-rwxr-xr-xupdate.sh48
2 files changed, 54 insertions, 2 deletions
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 <<EOF > $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