Skip to content

Commit

Permalink
Added Vultr DNS Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
happytreees committed Aug 22, 2022
1 parent ec27405 commit a10e364
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dns_scripts/dns_add_vultr
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions dns_scripts/dns_del_vultr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a10e364

Please sign in to comment.