~phroa/awsddns

1e7b4c9fad49a878f420443784d8260ec97b58aa — Jack Stratton 1 year, 3 months ago master
Initial commit
4 files changed, 44 insertions(+), 0 deletions(-)

A .gitignore
A awsddns
A awsddns.timer
A package.sh
A  => .gitignore +3 -0
@@ 1,3 @@
*.tar.xz
*.deb
*.rpm

A  => awsddns +21 -0
@@ 1,21 @@
#!/usr/bin/env bash

set -eux

API="https://du0v02jxu4.execute-api.us-east-1.amazonaws.com/default/my-ip"
DOMAIN="${2-phroa.net}"
SUBDOMAIN="${1-$HOST}"

hosted_zone_id="$(aws --output json route53 list-hosted-zones | jq -r '.HostedZones | map(select(.Name == "'"$DOMAIN"'."))[0].Id')"
tempfile="$(mktemp)"

curl -so "$tempfile" "$API?name=$SUBDOMAIN.$DOMAIN."

response="$(aws --output json route53 change-resource-record-sets --hosted-zone-id "$hosted_zone_id" --change-batch "file://$tempfile")"

jq . <<EOF
{
    "request": $(cat "$tempfile"),
    "response": $response
}
EOF
\ No newline at end of file

A  => awsddns.timer +9 -0
@@ 1,9 @@
[Unit]
Description=AWS DDNS update 15 min after boot and/or daily

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

[Install]
WantedBy=timers.target
\ No newline at end of file

A  => package.sh +11 -0
@@ 1,11 @@
#!/usr/bin/env bash

set -eux

FORMAT="${1-deb}"

fpm -f -a all -s dir -t "$FORMAT" -n awsddns-bin \
  ./awsddns=/usr/local/bin/awsddns \
  ./awsddns.timer=/etc/systemd/system/awsddns.timer

fpm -f -a all -s pleaserun -t "$FORMAT" -n awsddns /usr/local/bin/awsddns
\ No newline at end of file