vmail-stack/bin/webmail-enable.sh
Matthew Saunders Brown 9b5c51bcc9 user permissions checks
2021-03-19 11:58:35 -07:00

31 lines
967 B
Bash
Executable File

#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# load config
source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit
# check for and set virtualhost
if [ -n "$1" ]; then
virtualhost=$1
else
echo "virtualhost not set"
exit 1
fi
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
echo "Use VHostMAIL $virtualhost" > /etc/apache2/sites-available/mail.$virtualhost.conf
fi
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