-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.sh
45 lines (33 loc) · 1.8 KB
/
run.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
#!/bin/bash
echo "$(date +'%Y-%m-%d %T') Started"
sleep $(($RANDOM % 30))
# Setup
./tipctl.phar setup -n --apiUseWhitelist=false --loginName="$LOGINNAME" --apiPrivateKey="$PRIVATEKEY" -vvv
LastSet="?"
while :
do
# Get IP address
CurrentIP="$(curl -s ipinfo.io/ip)"
# Check IP address
ipv4='^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$'
ipv6='^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$'
if ! [[ $CurrentIP =~ $ipv4 || $CurrentIP =~ $ipv6 ]]; then
echo "$(date +'%Y-%m-%d %T') Error getting IP address, response was: $CurrentIP"
sleep $INTERVAL
continue
fi
# Check if IP has changed
if [ "$CurrentIP" != "$LastSet" ]; then
# Update DNS record
./tipctl.phar domain:dns:updatednsentry $DOMAIN $RECORD $TTL $TYPE $CurrentIP
if [ $? == 0 ]; then
# IP has been set
LastSet=$CurrentIP
echo "$(date +'%Y-%m-%d %T') Set $RECORD.$DOMAIN -> $CurrentIP"
fi
elif [ $ALWAYSLOG = true ]; then
#Log that no changes have been made
echo "$(date +'%Y-%m-%d %T') IP address not changed"
fi
sleep $INTERVAL
done