Skip to content

Commit

Permalink
add macos version
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyinstarlight committed Aug 26, 2018
1 parent 6739222 commit f453c91
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ddns.macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
token='0123456789abcdefghijklmnopqrstuv'
account=1010
zone='example.com'
arecord=5
aaaarecord=6

ifip=true

code=0

if [ "$arecord" ]; then
if $ifip; then
ipv4=$(route -v get 8.8.8.8 2>/dev/null | grep '^ default' | cut -d' ' -f6)
if echo "$ipv4" | grep -E '[a-z]' &>/dev/null; then
ipv4=$(host $ipv4 | cut -d' ' -f4)
fi
else
ipv4=$(curl -s4 icanhazip.com)
fi
fi

if [ -n "$ipv4" ]; then
response=$(curl -sSf -H "Authorization: Bearer $token" -H "Accept: application/json" -H "Content-Type: application/json" -X PATCH -d "{\"content\":\"$ipv4\"}" "https://api.dnsimple.com/v2/$account/zones/$zone/records/$arecord" 2>&1)
if [ $? != 0 ]; then
code=$((code+1))
echo 'IPv4 Update ('"${zone}"' ('"$arecord"') -> '"$ipv4"'): '"$response" >&2
fi
fi

if [ "$aaaarecord" ]; then
if $ifip; then
ipv6=$(route -v get 2001:4860:4860::8888 2>/dev/null | grep '^ default' | cut -d' ' -f6)
if echo "$ipv6" | grep -E '[a-z]' &>/dev/null; then
ipv6=$(host $ipv6 | cut -d' ' -f4)
fi
else
ipv6=$(curl -s6 icanhazip.com)
fi
fi

if [ -n "$ipv6" ]; then
response=$(curl -sSf -H "Authorization: Bearer $token" -H "Accept: application/json" -H "Content-Type: application/json" -X PATCH -d "{\"content\":\"$ipv6\"}" "https://api.dnsimple.com/v2/$account/zones/$zone/records/$aaaarecord" 2>&1)
if [ $? != 0 ]; then
code=$((code+1))
echo 'IPv6 Update ('"${zone}"' ('"$aaaarecord"') -> '"$ipv6"'): '"$response" >&2
fi
fi

exit $code
19 changes: 19 additions & 0 deletions ddns.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.ddns</string>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<false/>
<key>Program</key>
<string>/usr/local/bin/ddns</string>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>00</integer>
</dict>
</dict>
</plist>

0 comments on commit f453c91

Please sign in to comment.