otcerts/letsencrypt/lets_cleanup.sh
2020-02-23 19:59:56 +01:00

41 lines
1.2 KiB
Bash
Executable file

LOG_FILE='/tmp/lets_clean.log'
DNS_DB_MYCNF="/usr/local/ortiche/otcerts/etc/dns_db.conf"
echo "" >> $LOG_FILE
date >> $LOG_FILE
echo "CERTBOT_AUTH_OUTPUT = $CERTBOT_AUTH_OUTPUT" >> $LOG_FILE
RECORD_NAME='_acme-challenge'
RECORD_FQDN="$RECORD_NAME.$CERTBOT_DOMAIN"
DOMAIN_ID=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
SELECT domains.id FROM domains WHERE domains.name='$CERTBOT_DOMAIN'
END_QUERY`
if [ -z "$DOMAIN_ID" ]; then
echo "ERROR: Nameservers are not managed for domain $CERTBOT_DOMAIN" >> $LOG_FILE
exit 255
fi
RECORD_ID=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
SELECT id FROM records WHERE (type='TXT' and name='$RECORD_FQDN')
END_QUERY`
echo "Cleaning $RECORD_FQDN TXT entry, record id $RECORD_ID" >> $LOG_FILE
# QUERY_RES=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
# UPDATE records SET content='""' WHERE id=$RECORD_ID
# END_QUERY`
# To complete delete
DELETE_RES=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
DELETE FROM records WHERE (domain_id=$DOMAIN_ID AND name='$RECORD_FQDN')
END_QUERY`
echo "Done cleaning, sleeping 5 secs .. " >> $LOG_FILE
sleep 5
echo "Done sleeping." >> $LOG_FILE
exit 0