-
Notifications
You must be signed in to change notification settings - Fork 2
/
dns-o-matic.sh
executable file
·51 lines (42 loc) · 1.35 KB
/
dns-o-matic.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
#!/usr/bin/env sh
CONFIG_DIR=${CONFIG_DIR:-/config}
HOST=${HOST:-all.dnsomatic.com}
WILDCARD=${WILDCARD:-NOCHG}
MX=${MX:-NOCHG}
BACKMX=${BACKMX:-NOCHG}
DELAY=${DELAY:-1h}
IP_ADDR_PROVIDER=${IP_ADDR_PROVIDER:-"http://myip.dnsomatic.com/"}
IP_FILE=${CONFIG_DIR}/dnsomatic.myip
# make sure we have a username and password
if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
echo You must provide a USERNAME and PASSWORD
exit 1
fi
cleanup () {
kill -s SIGTERM $!
exit 0
}
trap cleanup SIGINT SIGTERM
while true; do
# fetch your current ip address
NEW_IP=$(curl -s "${IP_ADDR_PROVIDER}")
OLD_IP=$(test -f "${IP_FILE}" && cat "${IP_FILE}")
echo OLD IP: ${OLD_IP}
echo NEW IP: ${NEW_IP}
if [ "${NEW_IP}" = "${OLD_IP}" ]; then
echo IP is still the same, not updating
else
echo Updating ${HOST} with ${NEW_IP}
LOG=$(curl -s -u "${USERNAME}:${PASSWORD}" "https://updates.dnsomatic.com/nic/update?myip=${NEW_IP}&hostname=${HOST}&wildcard=${WILDCARD}&mx=${MX}&backmx=${BACKMX}")
if echo $LOG | grep -q 'good'; then
echo Successfully updated ${HOST} to ${NEW_IP}
echo ${NEW_IP} > "${IP_FILE}"
else
echo Uh oh. Update failed with response...
echo "${LOG}"
break
fi
fi
echo "Sleeping for ${DELAY}"
sleep ${DELAY} & wait $!
done