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

35 lines
958 B
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
# MIT License Copyright (c) 2021 Matthew Saunders Brown
2021-03-19 11:59:41 -07:00
# must be root to enable apache config
if [ "$USER" != "root" ]; then
exec su "$0" -- "$@"
fi
2021-02-10 16:16:23 -08:00
# check for and set virtualhost
if [ -n "$1" ]; then
virtualhost=$1
else
echo "virtualhost not set"
exit 1
fi
2021-03-19 11:59:41 -07:00
# check that letsencrypt cert exists
2021-02-10 16:16:23 -08:00
if [ ! -f /etc/ssl/letsencrypt/mail.$virtualhost.pem ]; then
echo "Let's Encrypt cert for mail.$virtualhost does not exist, create that first:"
exit 1
fi
# enable webmail vhost & restart apache
if [ ! -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then
2021-04-13 14:13:14 -07:00
echo "Use VMailHTTPS mail.$virtualhost" > /etc/apache2/sites-available/mail.$virtualhost.conf
2021-02-10 16:16:23 -08:00
fi
2021-03-19 11:59:41 -07:00
2021-02-10 16:16:23 -08:00
if [ ! -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then
/usr/sbin/a2ensite --quiet mail.$virtualhost
/usr/bin/systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
fi