vmail-stack/bin/vmail-webmail-enable.sh

49 lines
1.4 KiB
Bash
Raw Normal View History

2021-02-10 16:16:23 -08:00
#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
2022-08-22 13:34:20 -07:00
# 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)
2021-02-10 16:16:23 -08:00
2023-02-18 16:20:03 -08:00
# load include file
source $(dirname $0)/vmail.sh
help()
{
thisfilename=$(basename -- "$0")
echo "$thisfilename"
echo "Enable webmail for given domain"
echo ""
echo "usage: $thisfilename -d <domain> [-h]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain to enable webmail for."
echo ""
echo " Let's Encrypt certificate must already exist. If need be run this first:"
echo " letsencrypt-certonly.sh -d <domain>"
}
vmail:getoptions "$@"
2021-02-10 16:16:23 -08:00
2023-02-18 16:20:03 -08:00
# check for domain
if [[ -z $domain ]]; then
echo "ERROR: domain name is required"
2021-02-10 16:16:23 -08:00
exit 1
fi
2021-03-19 11:59:41 -07:00
# check that letsencrypt cert exists
2023-02-18 16:20:03 -08:00
if [ ! -f /etc/ssl/letsencrypt/mail.$domain.pem ]; then
echo "Let's Encrypt cert for mail.$domain does not exist, create that first:"
2021-02-10 16:16:23 -08:00
exit 1
fi
# enable webmail vhost & restart apache
2023-02-18 16:20:03 -08:00
if [ ! -f "/etc/apache2/sites-available/mail.$domain.conf" ]; then
echo "Use VMailHTTPS mail.$domain" > /etc/apache2/sites-available/mail.$domain.conf
2021-02-10 16:16:23 -08:00
fi
2021-03-19 11:59:41 -07:00
2023-02-18 16:20:03 -08:00
if [ ! -h "/etc/apache2/sites-enabled/mail.$domain.conf" ]; then
/usr/sbin/a2ensite --quiet mail.$domain
2021-02-10 16:16:23 -08:00
/usr/bin/systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
fi