mirror of
https://github.com/tunix/digitalocean-dyndns
synced 2024-12-23 05:19:52 +00:00
Compare commits
No commits in common. "db6c6d4c003a9ba5ef4aa91fcb5ad032e89c0b03" and "a3553daa2f62d8542f631f0bad22139a9a00fec7" have entirely different histories.
db6c6d4c00
...
a3553daa2f
2 changed files with 15 additions and 19 deletions
|
@ -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`). Multiple subdomains must be separated by semicolons `;`
|
* **NAME:** Subdomain to use. (name in A record) (i.e. `home` for `home.foo.com`)
|
||||||
* **SLEEP_INTERVAL:** Polling time in seconds. (default: 300)
|
* **SLEEP_INTERVAL:** Polling time in seconds. (default: 300)
|
||||||
|
|
||||||
### Docker (Recommended)
|
### Docker (Recommended)
|
||||||
|
|
18
dyndns.sh
18
dyndns.sh
|
@ -19,20 +19,17 @@ 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\"}"
|
||||||
if [[ -n $ip ]]; then
|
|
||||||
for sub in ${NAME//;/ }; do
|
|
||||||
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
|
|
||||||
|
|
||||||
if [[ "$ip" != "$record_data" ]]; then
|
|
||||||
data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
|
|
||||||
url="$dns_list/$record_id"
|
url="$dns_list/$record_id"
|
||||||
|
|
||||||
|
if [[ -n $ip ]]; then
|
||||||
|
if [[ "$ip" != "$record_data" ]]; then
|
||||||
echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url"
|
echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url"
|
||||||
|
|
||||||
curl -s -X PUT \
|
curl -s -X PUT \
|
||||||
|
@ -41,7 +38,6 @@ while ( true ); do
|
||||||
-d "$data" \
|
-d "$data" \
|
||||||
"$url" &> /dev/null
|
"$url" &> /dev/null
|
||||||
fi
|
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
|
||||||
|
|
Loading…
Reference in a new issue