Created
July 28, 2024 06:47
-
-
Save QuiltMeow/222c9d9b7872aeea4f177839823bb276 to your computer and use it in GitHub Desktop.
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/bash | |
| # crontab -e | |
| # */5 * * * * /path/to/script.sh | |
| # Domain Zone | |
| zone=example.com | |
| # Domain | |
| dns_record=quilt.example.com | |
| # Cloudflare Authentication Mail | |
| [email protected] | |
| # Cloudflare Authentication API Key | |
| cloudflare_auth_key=abcdef0123456789abcdef0123456789abcde | |
| ip=$(curl -s -X GET https://checkip.amazonaws.com/) | |
| if host $dns_record 1.1.1.1 | grep "has address" | grep "$ip"; then | |
| exit | |
| fi | |
| zone_id=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \ | |
| -H "X-Auth-Email: $cloudflare_auth_mail" \ | |
| -H "X-Auth-Key: $cloudflare_auth_key" \ | |
| -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id') | |
| dns_record_id=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=A&name=$dns_record" \ | |
| -H "X-Auth-Email: $cloudflare_auth_mail" \ | |
| -H "X-Auth-Key: $cloudflare_auth_key" \ | |
| -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id') | |
| curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$dns_record_id" \ | |
| -H "X-Auth-Email: $cloudflare_auth_mail" \ | |
| -H "X-Auth-Key: $cloudflare_auth_key" \ | |
| -H "Content-Type: application/json" \ | |
| --data "{ \"type\": \"A\", \"name\": \"$dns_record\", \"content\": \"$ip\", \"ttl\": 60, \"proxied\": false }" | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment