This repository has been archived by the owner on Jan 15, 2023. It is now read-only.
forked from dragoncube/docker-google-domains-ddns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoogle-domains-ddns.sh
executable file
·65 lines (52 loc) · 1.81 KB
/
google-domains-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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
if [ -z "$HOSTNAME" ]; then
echo "HOSTNAME must be defined"
exit 1
fi
if [ -z "$USERNAME" ]; then
echo "USERNAME must be defined"
exit 1
fi
if [ -z "$PASSWORD" ]; then
echo "PASSWORD must be defined"
exit 1
fi
if [ -z "$INTERVAL" ]; then
INTERVAL='30m'
fi
if [[ ! "$INTERVAL" =~ ^[0-9]+[mhd]$ ]]; then
echo "INTERVAL must be a number followed by m, h, or d. Example: 5m"
exit 1
fi
if [[ "${INTERVAL: -1}" == 'm' && "${INTERVAL:0:-1}" -lt 5 ]]; then
echo "The shortest allowed INTERVAL is 5 minutes"
exit 1
fi
USER_AGENT="cwmr/docker-google-domains-ddns"
#-----------------------------------------------------------------------------------------------------------------------
function ts {
echo [`date '+%b %d %X'`]
}
#-----------------------------------------------------------------------------------------------------------------------
while true
do
RESPONSE=$(curl -S -s -k --user-agent "$USER_AGENT" -u "$USERNAME:$PASSWORD" "https://domains.google.com/nic/update?hostname=$HOSTNAME" 2>&1)
# Sometimes the API returns "nochg" without a space and ip address. It does this even if the password is incorrect.
if [[ $RESPONSE =~ ^(good|nochg) ]]
then
echo "$(ts) Google Domains successfully called. Result was \"$RESPONSE\"."
elif [[ $RESPONSE =~ ^(nohost|badauth|badagent|abuse|notfqdn) ]]
then
echo "$(ts) Something went wrong. Check your settings. Result was \"$RESPONSE\"."
echo "$(ts) For an explanation of error codes, see https://support.google.com/domains/answer/6147083"
exit 2
elif [[ $RESPONSE =~ ^911 ]]
then
echo "$(ts) Server returned "911". Waiting for 30 minutes before trying again."
sleep 1800
continue
else
echo "$(ts) Couldn't update. Trying again in 5 minutes. Output from curl command was \"$RESPONSE\"."
fi
sleep $INTERVAL
done