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

@ -12,35 +12,27 @@ help()
echo "" echo ""
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 " -r Revoke cert from Let's Encrypt before deleting files." echo " -d <domain> Domain (hostname) of the certificate to delete."
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
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
case "${opt}" in case "${opt}" in
h ) h )
help help
exit;; 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 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