require -d opt for domain

This commit is contained in:
Matthew Saunders Brown 2022-06-15 12:32:45 -07:00
parent c2fe329b5e
commit 0933ae043f

View File

@ -13,34 +13,26 @@ help()
echo "Usage: $thisfilename cert-name(domain) [OPTIONS]" echo "Usage: $thisfilename cert-name(domain) [OPTIONS]"
echo "" echo ""
echo " -h Print this help." echo " -h Print this help."
echo " -d <domain> Domain (hostname) of the certificate to delete."
echo " -r Revoke cert from Let's Encrypt before deleting files." echo " -r Revoke cert from Let's Encrypt before deleting files."
exit exit
} }
# check for and set domain # set options
if [ -n "$1" ]; then while getopts "hd:r" opt; do
if [ $1 == "-h" ]; then case "${opt}" in
h )
help help
else exit;;
domain=$1 d ) # domain name (hostname) to create cert for
shift domain=${OPTARG,,}
# basic but good enough domain name regex validation # basic but good enough domain name regex validation
if [[ ! $domain =~ ^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)+[a-zA-Z]{2,}$ ]] ; then if [[ ! $domain =~ ^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)+[a-zA-Z]{2,}$ ]] ; then
echo "ERROR: Invalid domain name: $1" echo "ERROR: Invalid domain name: $1"
exit 1 exit 1
fi fi
fi ;;
else r ) # revoke
help
fi
# set any options that were passed
while getopts "hr" opt; do
case "${opt}" in
h )
help
exit;;
r )
revoke=true revoke=true
;; ;;
\? ) \? )
@ -52,6 +44,11 @@ while getopts "hr" opt; do
esac esac
done done
# check for domain (hostname)
if [[ -z $domain ]]; then
echo "domain (hostname) is required"
exit
fi
# start by checking if the renewal config exits # start by checking if the renewal config exits
if test -f "/etc/letsencrypt/renewal/$domain.conf"; then if test -f "/etc/letsencrypt/renewal/$domain.conf"; then