-
-
Save rivy/14a033a678105eb33a64 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
EMAIL= | |
API_TOKEN= | |
DOMAIN_ID= | |
RECORD_ID= | |
IP=$( nvram get wan_ipaddr ) | |
OUTPUT='-s -o /dev/null' | |
usage() | |
{ | |
cat << EOF | |
usage: $(basename $0) -e EMAIL -t APITOKEN -d DOMAINID -r RECORDID | |
OPTIONS: | |
-v Be verbose | |
-h Show this message | |
EOF | |
} | |
while getopts "he:t:d:r:v" OPTION | |
do | |
case $OPTION in | |
h) | |
usage | |
exit 1 | |
;; | |
e) | |
EMAIL=$OPTARG | |
;; | |
t) | |
API_TOKEN=$OPTARG | |
;; | |
d) | |
DOMAIN_ID=$OPTARG | |
;; | |
r) | |
RECORD_ID=$OPTARG | |
;; | |
v) | |
OUTPUT='-s -i -v -o /dev/stderr' | |
;; | |
?) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
if [[ -z $EMAIL ]] || [[ -z $API_TOKEN ]] || [[ -z $DOMAIN_ID ]] || [[ -z $RECORD_ID ]] | |
then | |
usage | |
exit 1 | |
fi | |
echo "Updating with IP: $IP" | |
RESULT=$(curl -H "Accept: application/json" \ | |
-H "X-DNSimple-Token: $EMAIL:$API_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-X PUT https://DNSimple.com/domains/$DOMAIN_ID/records/$RECORD_ID.json \ | |
-d "{\"record\":{\"content\":\"$IP\"}}" \ | |
-k \ | |
-w "%{http_code}" \ | |
$OUTPUT) | |
if [ "$RESULT" = "200" ]; then | |
exit 0 | |
else | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment