create new vars, remove placeholder domain

This commit is contained in:
Matthew Saunders Brown 2023-05-18 15:59:54 -07:00
parent c68120d55e
commit 3ac3ee2b75

View File

@ -29,19 +29,24 @@ vmail:getoptions "$@"
if [[ -z $domain ]]; then
echo "ERROR: domain name is required"
exit 1
else
# set vars
maildomain="mail.$domain"
pemfile="$maildomain.pem"
confile="$maildomain.conf"
fi
# check that letsencrypt cert exists
if [ ! -f /etc/ssl/letsencrypt/mail.$domain.pem ]; then
echo "Let's Encrypt cert for mail.$domain does not exist, create that first:"
if [ ! -f /etc/ssl/letsencrypt/$pemfile ]; then
echo "Let's Encrypt cert for $maildomain does not exist, create that first:"
exit 1
fi
# create dovecot config & restart
if [ ! -f "/etc/dovecot/sites.d/mail.$domain.conf" ]; then
echo "local_name mail.pawderosa.com {" > /etc/dovecot/sites.d/mail.$domain.conf
echo " ssl_cert = </etc/ssl/letsencrypt/mail.pawderosa.com.pem" >> /etc/dovecot/sites.d/mail.$domain.conf
echo " ssl_key = </etc/ssl/letsencrypt/mail.pawderosa.com.pem" >> /etc/dovecot/sites.d/mail.$domain.conf
echo "}" >> /etc/dovecot/sites.d/mail.$domain.conf
if [ ! -f "/etc/dovecot/sites.d/$confile" ]; then
echo "local_name $maildomain {" > /etc/dovecot/sites.d/$confile
echo " ssl_cert = </etc/ssl/letsencrypt/$pemfile" >> /etc/dovecot/sites.d/$confile
echo " ssl_key = </etc/ssl/letsencrypt/$pemfile" >> /etc/dovecot/sites.d/$confile
echo "}" >> /etc/dovecot/sites.d/$confile
/usr/bin/systemctl --quiet is-active dovecot && systemctl --quiet reload dovecot
fi