-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-ddns.sh
executable file
·38 lines (33 loc) · 934 Bytes
/
update-ddns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
set -euo pipefail
if [ -z "${DDNS_HOST:-}" ]; then
echo "DDNS_HOST envvar must be set"
exit 1
fi
if [ -z "${DDNS_DOMAIN:-}" ]; then
echo "DDNS_DOMAIN envvar must be set"
exit 1
fi
if [ -z "${DDNS_PASSWORD:-}" ]; then
echo "DDNS_PASSWORD envvar must be set"
exit 1
fi
echo "Checking for IP address changes"
last_ip=$(dig +short "$DDNS_HOST.$DDNS_DOMAIN")
if [ -z "${last_ip:-}" ]; then
echo "Unable to get last IP address"
exit 1
fi
public_ip=$(curl -s -S https://api.ipify.org)
if [ -z "${public_ip:-}" ]; then
echo "Unable to get current IP address"
exit 1
fi
echo "Last IP address: $last_ip"
echo "New IP address: $public_ip"
if [ "$last_ip" != "$public_ip" ]; then
echo "Setting IP for $DDNS_HOST.$DDNS_DOMAIN to $public_ip"
curl -s -S "https://dynamicdns.park-your-domain.com/update?host=$DDNS_HOST&domain=$DDNS_DOMAIN&password=$DDNS_PASSWORD&ip=$public_ip"
else
echo "Skipping update"
fi