letsencrypt-tools/bin/letsencrypt-bulk-certonly.sh

48 lines
1.2 KiB
Bash
Raw Normal View History

2022-06-15 12:34:38 -07:00
#!/bin/bash
2022-08-22 13:43:03 -07:00
#
# letsencrypt-tools
# https://git.stack-source.com/msb/letsencrypt-tools
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
2022-06-15 12:34:38 -07:00
# must be root
if [ "$USER" != "root" ]; then
exec sudo -u root $0 $@
fi
help()
{
thisfilename=$(basename -- "$0")
echo "Bulk installs Let's Encrypt certificates."
echo ""
echo "Usage: $thisfilename [OPTIONS]"
echo ""
echo " -h Print this help."
echo
echo " Checks /srv/www/ for all virtualhosts and"
echo " runs letsencrypt-certonly.sh for any site"
echo " that doesn't already have a cert installed."
exit
}
# check for help
if [ -n "$1" ]; then
help
fi
readarray -t virtualhosts < <(ls -1 /srv/www/|grep -v ^html$)
for virtualhost in "${virtualhosts[@]}"; do
# basic but good enough domain name regex validation
if [[ $virtualhost =~ ^(([a-zA-Z0-9](-?[a-zA-Z0-9])*)\.)+[a-zA-Z]{2,}$ ]] ; then
if [ ! -f /etc/letsencrypt/renewal/$virtualhost.conf ]; then
echo "/usr/local/bin/letsencrypt-certonly.sh -d $virtualhost"
fi
fi
# add code here to enable apache config
done