Browse Source

Added Vultr DNS Scripts

pull/774/head
ErwinsExpertise 3 years ago
parent
commit
a10e36487d
2 changed files with 56 additions and 0 deletions
  1. +30
    -0
      dns_scripts/dns_add_vultr
  2. +26
    -0
      dns_scripts/dns_del_vultr

+ 30
- 0
dns_scripts/dns_add_vultr View File

@ -0,0 +1,30 @@
#!/bin/bash
# Vultr Add DNS Record
api_url="https://api.vultr.com/v2"
api_key=${VULTR_API_KEY:-''}
domain="$1"
challenge="$2"
root=$(echo "$domain" | awk -F\. '{print $(NF-1) FS $NF}')
subdomain="_acme-challenge.${domain%.$root}"
if [[ -z "$VULTR_API_KEY" ]]; then
echo "VULTR_API_KEY variable not set"
exit 1
fi
function create {
curl "${api_url}/domains/$1/records" -X POST -H "Authorization: Bearer ${VULTR_API_KEY}" -H "Content-Type: application/json" \
--data "{
\"name\" : \"$2\",
\"type\" : \"TXT\",
\"data\" : \"${challenge}\",
\"ttl\" : 300,
\"priority\" : 0
}"
}
create $root $subdomain

+ 26
- 0
dns_scripts/dns_del_vultr View File

@ -0,0 +1,26 @@
#!/bin/bash
# Vultr Delete DNS Record
# This script requires jq to be installed on the machine running it
api_url="https://api.vultr.com/v2"
api_key=${VULTR_API_KEY:-''}
domain="$1"
root=$(echo "$domain" | awk -F\. '{print $(NF-1) FS $NF}')
subdomain="_acme-challenge.${domain%.$root}"
if [[ -z "$VULTR_API_KEY" ]]; then
echo "VULTR_API_KEY variable not set"
exit 1
fi
function delete {
recordID=$(curl "${api_url}/domains/$1/records" -X GET -H "Authorization: Bearer ${VULTR_API_KEY}" | jq -r ".records[] | select(.name==\"$2\").id")
curl "${api_url}/domains/$1/records/$recordID" -X DELETE -H "Authorization: Bearer ${VULTR_API_KEY}"
}
delete $root $subdomain

Loading…
Cancel
Save