-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6739222
commit f453c91
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |