Last active
August 29, 2015 14:14
-
-
Save isao/c28497d0ab8aeaff9046 to your computer and use it in GitHub Desktop.
update subdomain IP address on cloudflare
This file contains hidden or 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 -eu | |
# config | |
# | |
email=REDACTED | |
token=$(security find-generic-password -ws 'Cloudflare API key' -a $email) | |
domain=REDACTED | |
subdomain=REDACTED | |
# funcs | |
# | |
get_interface() | |
{ | |
route get 0.0.0.0 2>/dev/null | awk '/interface: /{print $2}' | |
} | |
get_ip() | |
{ | |
ifconfig -r $1 | awk '/inet /{print $2}' | |
} | |
# main | |
# | |
ip=$(get_ip $(get_interface)) | |
## To get $record_id -- rec_load_all to get DNS Record ID | |
## https://www.cloudflare.com/docs/client-api.html#s3.3 | |
record_id=REDACTED | |
# curl https://www.cloudflare.com/api_json.html \ | |
# -d a=rec_load_all \ | |
# -d tkn=$token \ | |
# -d email=$email \ | |
# -d z=$domain | |
# Set the ip for A record dev for target domain $domain | |
# https://www.cloudflare.com/docs/client-api.html#s5.2 | |
echo "* Setting DNS A record for $subdomain.$domain to $ip" | |
curl -v https://www.cloudflare.com/api_json.html \ | |
-d a=rec_edit \ | |
-d tkn=$token \ | |
-d email=$email \ | |
-d id=$record_id \ | |
-d z=$domain \ | |
-d name=$subdomain \ | |
-d type=A \ | |
-d content=$ip \ | |
-d service_mode=1 \ | |
-d ttl=120 | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment