vmail-stack/bin/vmail-webmail-enable.sh
Matthew Saunders Brown b1ea2ee09e change to try-reload-or-restart
try-reload-or-restart has this logic:
  Reload service if it supports it.
  If not, stop and then start instead.
  Does nothing if the service is not running.
2023-12-20 10:11:36 -08:00

48 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# 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)
# 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 mail.<domain>"
}
vmail:getoptions "$@"
# check for domain
if [[ -z $domain ]]; then
echo "ERROR: domain name is required"
exit 1
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:"
exit 1
fi
# enable webmail vhost & restart apache
if [ ! -f "/etc/apache2/sites-available/mail.$domain.conf" ]; then
echo "Use VMailHTTPS mail.$domain" > /etc/apache2/sites-available/mail.$domain.conf
fi
if [ ! -h "/etc/apache2/sites-enabled/mail.$domain.conf" ]; then
/usr/sbin/a2ensite --quiet mail.$domain
fi