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 20 Jan,Apr,Jul,Oct * certbot renew
17 # Author: Andrew@DeFaria.com
18 # Created: Fri 04 Jun 2021 11:20:16 PDT
19 # Modified: Mon Oct 24 11:53:38 AM PDT 2022
22 # (c) Copyright 2021, ClearSCM, Inc., all rights reserved
24 ################################################################################
25 certdir="/System/Certificates"
29 logfile="$certdir/$(basename $0).log"
39 # The following are environment variables that certbot passes to us
41 # CERTBOT_DOMAIN: Domain being authenticated.
42 # CERTBOT_VALIDATION: Validation string for domain
44 # Check that CERTBOT_DOMAIN and CERTBOT_VALIDATION have been passed in properly
45 if [ -z "$CERTBOT_DOMAIN"]; then
46 log "CERTBOT_DOMAIN not passed in!"
49 log "CERTBOT_DOMAIN = $CERTBOT_DOMAIN"
52 if [ -z "$CERTBOT_VALIDATION"]; then
53 log "CERTBOT_VALIDATION not passed in!"
56 log "CERTBOT_VALIDATION = $CERTBOT_VALIDATION"
59 # My DNS registar is Dreamhost. These variables are specific to their DNS API.
60 # Yours will probably be different.
62 # Dreamhost key - generate at https://panel.dreamhost.com/?tree=home.api
65 # URL where the REST endpoint is
66 url="https://api.dreamhost.com/?key=$key"
68 # Remove a TXT record. Oddly you must also specify the value.
70 log "Removing TXT record $CERTBOT_DOMAIN = $CERTBOT_VALIDATION"
71 cmd="$url&unique_id=$(uuidgen)&cmd=dns-remove_record&record=_acme-challenge.$CERTBOT_DOMAIN&type=TXT&value=$CERTBOT_VALIDATION"
74 response=$(wget -O- -q "$cmd")
76 log "Response = $response"
81 # Removal is instanteous but propagation will take some time. No need to wait
84 # Now deploy new certs
85 /opt/clearscm/bin/certbot_deploy.sh