-
Notifications
You must be signed in to change notification settings - Fork 4
/
duckdns
executable file
·43 lines (38 loc) · 1.28 KB
/
duckdns
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
39
40
41
42
43
#!/bin/bash
LANG=en_US.UTF-8
LAST_IP="$HOME/.duckdns/last-ip"
CONFIG="$HOME/.duckdns/config"
if [ -f "$CONFIG" ]; then
source "$CONFIG"
else
logger -t duckdns "Configuration not found"
exit 1
fi
if [ ! -f "$LAST_IP" ]; then
if NEW_IP="$(dig +short myip.opendns.com @208.67.222.222)"; then
echo "$NEW_IP" > "$LAST_IP"
logger -t duckdns "Initialization succeeded, domain: $DOMAIN.duckdns.org, IP: $NEW_IP"
else
logger -t duckdns "Unable to detect the public IP address"
exit 1
fi
fi
while true; do
if CURRENT_IP="$(dig +short myip.opendns.com @208.67.222.222)"; then
if [ "$CURRENT_IP" != "$(< $LAST_IP)" ]; then
if RESULT="$(curl -s "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ip=$CURRENT_IP")"; then
if [ "$RESULT" = "OK" ]; then
echo "$CURRENT_IP" > "$LAST_IP"
logger -t duckdns "Update succeeded, new IP: $CURRENT_IP"
else
logger -t duckdns "Update failed, HTTP API error"
fi
else
logger -t duckdns "Update failed, unable to connect"
fi
fi
else
logger -t duckdns "Unable to detect the public IP address"
fi
sleep $INTERVAL
done