Last active
October 13, 2016 16:05
-
-
Save yannlugrin/b553a6daaba053745b46ce1c8d4ee9ed to your computer and use it in GitHub Desktop.
Update DNSimple record with current ip (dynamic DNS).
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>io.yalty.update-dnsimple</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>sh</string> | |
<string>/.../update-dnsimple.sh</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>60</integer> | |
</dict> | |
</plist> |
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
#!/usr/bin/env sh | |
set -e | |
TOKEN="" | |
ACCOUNT="" | |
ZONE="" | |
RECORD="" | |
IP=$(curl -s http://icanhazip.com/) | |
CACHE_FILE=/tmp/${0##*/}.cache | |
if [[ -f $CACHE_FILE && "$IP" = "$(cat $CACHE_FILE)" ]]; then | |
echo "IP ($IP) already set on dnsimple" | |
exit 0 | |
fi | |
curl -H "Authorization: Bearer $TOKEN" \ | |
-H "Accept: application/json" \ | |
-H "Content-Type: application/json" \ | |
-X "PATCH" \ | |
-d "{\"content\":\"$IP\"}" \ | |
--fail -sS \ | |
"https://api.dnsimple.com/v2/$ACCOUNT/zones/$ZONE/records/$RECORD" \ | |
>/dev/null | |
echo $IP > $CACHE_FILE | |
echo "IP ($IP) updated on dnsimple" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment