1
0
Fork 0
mirror of https://github.com/tunix/digitalocean-dyndns synced 2024-11-01 00:25:24 +00:00

Compare commits

..

2 commits

Author SHA1 Message Date
Alper Kanat
db6c6d4c00
Merge pull request #8 from zzeneg/master
Add support for multiple subdomains
2020-02-06 11:42:52 +02:00
Evgenii Vilkov
6cba88c6d0 add support for multiple subdomains 2020-01-30 13:38:37 +00:00
2 changed files with 19 additions and 15 deletions

View file

@ -14,7 +14,7 @@ Pick one of the options below using the following settings:
* **DIGITALOCEAN_TOKEN:** The token you generate in DigitalOcean's API settings. * **DIGITALOCEAN_TOKEN:** The token you generate in DigitalOcean's API settings.
* **DOMAIN:** The domain your subdomain is registered at. (i.e. `foo.com` for `home.foo.com`) * **DOMAIN:** The domain your subdomain is registered at. (i.e. `foo.com` for `home.foo.com`)
* **NAME:** Subdomain to use. (name in A record) (i.e. `home` for `home.foo.com`) * **NAME:** Subdomain to use. (name in A record) (i.e. `home` for `home.foo.com`). Multiple subdomains must be separated by semicolons `;`
* **SLEEP_INTERVAL:** Polling time in seconds. (default: 300) * **SLEEP_INTERVAL:** Polling time in seconds. (default: 300)
### Docker (Recommended) ### Docker (Recommended)

View file

@ -19,25 +19,29 @@ while ( true ); do
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
$dns_list) $dns_list)
record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$NAME\") | .id")
record_data=$(echo $domain_records| jq -r ".domain_records[] | select(.type == \"A\" and .name == \"$NAME\") | .data")
test -z $record_id && die "No record found with given domain name!"
ip="$(curl -s ipinfo.io/ip)" ip="$(curl -s ipinfo.io/ip)"
data="{\"type\": \"A\", \"name\": \"$NAME\", \"data\": \"$ip\"}"
url="$dns_list/$record_id"
if [[ -n $ip ]]; then if [[ -n $ip ]]; then
if [[ "$ip" != "$record_data" ]]; then for sub in ${NAME//;/ }; do
echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url" record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$sub\") | .id")
record_data=$(echo $domain_records| jq -r ".domain_records[] | select(.type == \"A\" and .name == \"$sub\") | .data")
test -z $record_id && echo "No record found with '$sub' domain name!" && continue
curl -s -X PUT \ if [[ "$ip" != "$record_data" ]]; then
-H "Content-Type: application/json" \ data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ url="$dns_list/$record_id"
-d "$data" \
"$url" &> /dev/null echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url"
fi
curl -s -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d "$data" \
"$url" &> /dev/null
fi
done
else else
echo "IP wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." echo "IP wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.."
fi fi