Skip to content

Instantly share code, notes, and snippets.

@ntotten
Created July 29, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntotten/9f8394c02ed6beb259905676a62cb89f to your computer and use it in GitHub Desktop.
Save ntotten/9f8394c02ed6beb259905676a62cb89f to your computer and use it in GitHub Desktop.
Let's Encrypt Certbot Authorization Hook for DNSimple
#!/bin/bash
(
ACCESS_TOKEN="YOUR_ACCESS_TOKEN_HERE" # See https://developer.dnsimple.com/v2/oauth/
ACCOUNT_ID="YOUR_ACCOUNT_ID"
DOMAIN="YOUR_DOMAIN"
RECORD_ID="YOUR_RECORD_ID"
if [[ ! $(type -P curl) ]] ; then
>&2 echo "Please install curl to use certbot with dedyn.io."
exit 4
fi
>&2 echo "Setting challenge to ${CERTBOT_VALIDATION}..."
curl -Ss -X PATCH \
"https://api.dnsimple.com/v2/$ACCOUNT_ID/zones/$DOMAIN/records/$RECORD_ID" \
-H "authorization: Bearer $ACCESS_TOKEN" \
-H "Cache-Control: no-cache" \
-H "Content-Type: application/json" \
-d "{ \"content\": \"$CERTBOT_VALIDATION\" }"
> /dev/null
>&2 echo "Verifying challenge is set correctly. This can take up to 2 Minutes."
>&2 echo "Current Time: `date`"
for i in `seq 1 60`;
do
CURRENT=$(host -t TXT _acme-challenge.$CERTBOT_DOMAIN ns1.dnsimple.com | grep $CERTBOT_VALIDATION)
if [ ! -z "$CURRENT" ]; then
break
fi
sleep 2
done
if [ -z "$CURRENT" ]; then
>&2 echo "Token could not be published. Please check your credentials."
exit 5
fi
>&2 echo "Token published. Returning to certbot."
)
host -t TXT _acme-challenge.vpn.totten.net ns1.dnsimple.com | grep "eDD1kCX0Q_ePdrPXKwK36RdCdE4WEPQaPA4Hh44j4dU"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment