Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to use with CertBot's --manual-auth-hook switch
#!/bin/sh
KEY="GoDaddyAuthKey"
SECRET="GoDaddySecret"
APISITE="api.godaddy.com"
BASEDOMAIN=`echo ${CERTBOT_DOMAIN} | awk -F. '{OFS="."; print $(NF-1),$(NF)}'`
SUBDOMAIN=`echo ${CERTBOT_DOMAIN} | sed -e 's/'${BASEDOMAIN}'//' -e 's/\.$//'`
if [ -z ${SUBDOMAIN} ] ; then
DNSRECORD="_acme-challenge"
else
DNSRECORD="_acme-challenge.${SUBDOMAIN}"
fi
NAMESERVER=`nslookup -type=NS ${BASEDOMAIN} | grep "^${BASEDOMAIN}" | awk '{print $4}' | head -1`
curl -X PUT "https://${APISITE}/v1/domains/${BASEDOMAIN}/records/TXT/${DNSRECORD}" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: sso-key ${KEY}:${SECRET}" -d "[ { \"data\": \"${CERTBOT_VALIDATION}\", \"port\": 53, \"priority\": 0, \"protocol\": \"string\", \"service\": \"string\", \"ttl\": 600, \"weight\": 1 }]"
echo "Testing Validation Record"
TRY=0
while [ $TRY -ne 12 ] ; do
CURRENT_DATA=`dig @${NAMESERVER} -t txt +noall +answer ${DNSRECORD}.${BASEDOMAIN} | awk '{gsub("\"",""); print $5}'`
if [ ! -z ${CURRENT_DATA} ] ; then
if [ ${CURRENT_DATA} == ${CERTBOT_VALIDATION} ] ; then
echo Succeeded: ${CERTBOT_DOMAIN}
exit 0
fi
fi
let TRY=$TRY+1
sleep 5
done
echo Domain: ${CERTBOT_DOMAIN}
echo "Timed Out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment