forked from andresmazzo/linode-ddns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinode-ddns.sh
42 lines (35 loc) · 915 Bytes
/
linode-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
#!/bin/sh
BASE=`basename $0 .sh`
DIR=`dirname $0`
# Read the configuration file
CONF=$DIR/vars.conf
if [ -r "$CONF" ]; then
. $CONF
else
logger -t $BASE "Could not read configuration file: $CONF"
exit 1
fi
CURRIP=`"$DIR/scripts/get-public-ip.sh"`
RC=$?
if [ "$RC" != 0 ];then
logger -t $BASE "Cannot get public IP address: $RC"
exit 2
fi
DNSIP=`"$DIR/scripts/get-dns-ip.sh" $TOKEN $DOMAIN_ID $RECORD_ID`
RC=$?
if [ "$RC" != 0 ];then
logger -t $BASE "Curl get reported error: $RC"
exit 2
fi
if [ "$DNSIP" = "$CURRIP" ]; then
logger -t $BASE "External IP address has not changed. No IP update necessary. IP address: $CURRIP"
exit 0
fi
`"$DIR/scripts/update-dns-ip.sh" $TOKEN $DOMAIN_ID $RECORD_ID $CURRIP`
RC=$?
if [ "$RC" != 0 ];then
logger -t $BASE "Curl update reported error: $RC"
exit 2
fi
# Log the IP address change
logger -t $BASE "Updated IP address from $DNSIP to $CURRIP"