Quoted double quotes
[clearscm.git] / bin / certbot_cleanup.sh
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         certbot_cleanup.sh
5 # Revision:     1.0
6 # Description:  Perform cleanup after domain validation by removing the TXT
7 #               record on the domain created by certbot_authentication.sh
8 #
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.
12 #
13 # See also:     https://help.dreamhost.com/hc/en-us/articles/217555707-DNS-API-commands
14 #
15 # Crontab:      0 0 1 * * certbot renew --manual-auth-hook /path/to/certbot_authentication.sh --manual-cleanup-hook /path/to/certbot_cleanup.sh
16 #
17 # Author:       Andrew@DeFaria.com
18 # Created:      Fri 04 Jun 2021 11:20:16 PDT
19 # Modified:
20 # Language:     Bash
21 #
22 # (c) Copyright 2021, ClearSCM, Inc., all rights reserved
23 #
24 ################################################################################
25 # The following are environment variables that certbot passes to us
26 #
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
31 #                     CERTBOT_DOMAIN
32 domain=${1:-CERTBOT_DOMAIN}
33
34 # CERTBOT_VALIDATION: The validation string. Pass in $2 or use the default of
35 #                     CERTBOT_VALIDATION
36 value=${2:-CERTBOT_VALIDATION}
37
38 logfile=/tmp/debug.log
39
40 function log {
41   #echo $1
42   echo $1 >> $logfile
43 } # log
44
45 # Dreamhost key - generate at https://panel.dreamhost.com/?tree=home.api 
46 key=KHY6UJQXD9MEJZHR
47
48 # URL where the REST endpoint is
49 url="https://api.dreamhost.com/?key=$key"
50
51 # Remove a TXT record. Oddly you must also specify the value.
52 function removeTXT {
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"
55
56   response=$(wget -O- -q "$cmd")
57
58   log "$response"
59 } # removeTXT
60
61 removeTXT
62
63 # Removal is instanteous but propagation will take some time. No need to wait
64 # around though...