From 0933ae043f1eacf1b073cd533984bb50fae68380 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Wed, 15 Jun 2022 12:32:45 -0700 Subject: [PATCH] require -d opt for domain --- bin/letsencrypt-del.sh | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/bin/letsencrypt-del.sh b/bin/letsencrypt-del.sh index 5215319..913c740 100644 --- a/bin/letsencrypt-del.sh +++ b/bin/letsencrypt-del.sh @@ -12,35 +12,27 @@ help() echo "" echo "Usage: $thisfilename cert-name(domain) [OPTIONS]" echo "" - echo " -h Print this help." - echo " -r Revoke cert from Let's Encrypt before deleting files." + echo " -h Print this help." + echo " -d Domain (hostname) of the certificate to delete." + echo " -r Revoke cert from Let's Encrypt before deleting files." exit } -# check for and set domain -if [ -n "$1" ]; then - if [ $1 == "-h" ]; then - help - else - domain=$1 - shift - # basic but good enough domain name regex validation - if [[ ! $domain =~ ^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)+[a-zA-Z]{2,}$ ]] ; then - echo "ERROR: Invalid domain name: $1" - exit 1 - fi - fi -else - help -fi - -# set any options that were passed -while getopts "hr" opt; do +# set options +while getopts "hd:r" opt; do case "${opt}" in h ) help exit;; - r ) + d ) # domain name (hostname) to create cert for + domain=${OPTARG,,} + # basic but good enough domain name regex validation + if [[ ! $domain =~ ^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)+[a-zA-Z]{2,}$ ]] ; then + echo "ERROR: Invalid domain name: $1" + exit 1 + fi + ;; + r ) # revoke revoke=true ;; \? ) @@ -52,6 +44,11 @@ while getopts "hr" opt; do esac done +# check for domain (hostname) +if [[ -z $domain ]]; then + echo "domain (hostname) is required" + exit +fi # start by checking if the renewal config exits if test -f "/etc/letsencrypt/renewal/$domain.conf"; then