2 ################################################################################
4 # File: certbot_cleanup.sh
6 # Description: Perform cleanup after domain validation by removing the TXT
7 # record on the domain created by certbot_authentication.sh
9 # Domain validation is the process of validating you have control
10 # over a domain. Services like Let's Encrypt can then issue you
11 # domain validated TLS certificates for use to secure websites.
13 # See also: https://help.dreamhost.com/hc/en-us/articles/217555707-DNS-API-commands
15 # Crontab: 0 0 1 * * certbot renew --manual-auth-hook /path/to/certbot_authentication.sh --manual-cleanup-hook /path/to/certbot_cleanup.sh
17 # Author: Andrew@DeFaria.com
18 # Created: Fri 04 Jun 2021 11:20:16 PDT
22 # (c) Copyright 2021, ClearSCM, Inc., all rights reserved
24 ################################################################################
25 # The following are environment variables that certbot passes to us
27 # CERTBOT_DOMAIN: Domain being authenticated. For example,
28 # _acme-challenge.example.com for a wildcart cert or
29 # _acme-challenge.subdomain.example.com for a subdomain
30 # Note: Pass in $1 for testing or use the default of
32 domain=${1:-CERTBOT_DOMAIN}
34 # CERTBOT_VALIDATION: The validation string. Pass in $2 or use the default of
36 value=${2:-CERTBOT_VALIDATION}
38 logfile=/tmp/debug.log
45 # Dreamhost key - generate at https://panel.dreamhost.com/?tree=home.api
48 # URL where the REST endpoint is
49 url="https://api.dreamhost.com/?key=$key"
51 # Remove a TXT record. Oddly you must also specify the value.
53 log "Removing TXT record $CERTBOT_DOMAIN = $CERTBOT_VALIDATION"
54 cmd="$url&unique_id=$(uuidgen)&cmd=dns-remove_record&record=$CERTBOT_DOMAIN&type=TXT&value=$CERTBOT_VALIDATION"
56 response=$(wget -O- -q "$cmd")
63 # Removal is instanteous but propagation will take some time. No need to wait