Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #7949

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions DigitalOcean-Updater.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#https://github.com/SemiZhang/DigitalOcean-DDNS-Bash
#v1.1

#################### VARIABLES ####################
TOKEN="aaaaabbbbbccccc000001111122222"
DOMAIN="example.com"
RECORD_V4=("300000001" "300000002")
RECORD_V6=("300000003" "300000004")
###################################################

CURRENT_IPV4="$(curl -s v4.ident.me)"
CURRENT_IPV6="$(curl -s v6.ident.me)"

for RECORD_ID in ${RECORD_V4[*]}
do
LAST_IPV4="$(curl -s -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" | grep -Po '"data":(\d*?,|.*?[^\\]",)' | awk -F '"' '{print $4}')"
HOST="$(curl -s -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" | grep -Po '"name":(\d*?,|.*?[^\\]",)' | awk -F '"' '{print $4}')"
if [ $CURRENT_IPV4 == $LAST_IPV4 ]; then
echo "IPv4 has not changed for [$HOST] ($CURRENT_IPV4)"
else
echo "IPv4 for [$HOST] has changed to $CURRENT_IPV4 from $LAST_IPV4"
curl -s -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"data":"'"$CURRENT_IPV4"'"}' "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID"
echo ""
fi
done

for RECORD_ID in ${RECORD_V6[*]}
do
LAST_IPV6="$(curl -s -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" | grep -Po '"data":(\d*?,|.*?[^\\]",)' | awk -F '"' '{print $4}')"
HOST="$(curl -s -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" | grep -Po '"name":(\d*?,|.*?[^\\]",)' | awk -F '"' '{print $4}')"
if [ $CURRENT_IPV6 == $LAST_IPV6 ]; then
echo "IPv6 has not changed for [$HOST] ($CURRENT_IPV6)"
else
echo "IPv6 for [$HOST] has changed to $CURRENT_IPV6 from $LAST_IPV6"
curl -s -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"data":"'"$CURRENT_IPV6"'"}' "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID"
echo ""
fi
done