#!/bin/sh
# DNS challenge cleanup script for dnsexit.com
# lego exec provider calls: cleanup [--] <fqdn> <value>

API_KEY="${DNSEXIT_API_KEY}"
DOMAIN="${DNSEXIT_DOMAIN}"

[ "${1}" = "cleanup" ] && shift
[ "${1}" = "--" ] && shift
FQDN="${1%.}"

echo "dns-cleanup: name=${FQDN}" >&2

wget -q -O - \
  --header='Content-type:application/json' \
  --post-data="{
    \"apikey\": \"${API_KEY}\",
    \"domain\": \"${DOMAIN}\",
    \"delete\": [
      {
        \"type\": \"TXT\",
        \"name\": \"${FQDN}\"
      }
    ]
  }" \
  https://api.dnsexit.com/dns/
