enable getopts
This commit is contained in:
parent
f7fab10594
commit
3774665792
|
@ -5,25 +5,35 @@
|
||||||
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
# 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)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# must be root to disable apache config
|
# load include file
|
||||||
if [ "$USER" != "root" ]; then
|
source $(dirname $0)/vmail.sh
|
||||||
exec su "$0" -- "$@"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check for and set virtualhost
|
help()
|
||||||
if [ -n "$1" ]; then
|
{
|
||||||
virtualhost=$1
|
thisfilename=$(basename -- "$0")
|
||||||
else
|
echo "$thisfilename"
|
||||||
echo "virtualhost not set"
|
echo "Disable webmail for given domain"
|
||||||
|
echo ""
|
||||||
|
echo "usage: $thisfilename -d <domain> [-h]"
|
||||||
|
echo ""
|
||||||
|
echo " -h Print this help."
|
||||||
|
echo " -d <domain> Domain to disable webmail for."
|
||||||
|
}
|
||||||
|
|
||||||
|
vmail:getoptions "$@"
|
||||||
|
|
||||||
|
# check for domain
|
||||||
|
if [[ -z $domain ]]; then
|
||||||
|
echo "ERROR: domain name is required"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# disable webmail vhost & restart apache
|
# disable webmail vhost & restart apache
|
||||||
if [ -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then
|
if [ -h "/etc/apache2/sites-enabled/mail.$domain.conf" ]; then
|
||||||
/usr/sbin/a2dissite --quiet mail.$virtualhost
|
/usr/sbin/a2dissite --quiet mail.$domain
|
||||||
/usr/bin/systemctl --quiet reload apache2
|
/usr/bin/systemctl --quiet reload apache2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then
|
if [ -f "/etc/apache2/sites-available/mail.$domain.conf" ]; then
|
||||||
rm /etc/apache2/sites-available/mail.$virtualhost.conf
|
rm /etc/apache2/sites-available/mail.$domain.conf
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -5,31 +5,44 @@
|
||||||
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
# 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)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# must be root to enable apache config
|
# load include file
|
||||||
if [ "$USER" != "root" ]; then
|
source $(dirname $0)/vmail.sh
|
||||||
exec su "$0" -- "$@"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check for and set virtualhost
|
help()
|
||||||
if [ -n "$1" ]; then
|
{
|
||||||
virtualhost=$1
|
thisfilename=$(basename -- "$0")
|
||||||
else
|
echo "$thisfilename"
|
||||||
echo "virtualhost not set"
|
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 "$@"
|
||||||
|
|
||||||
|
# check for domain
|
||||||
|
if [[ -z $domain ]]; then
|
||||||
|
echo "ERROR: domain name is required"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check that letsencrypt cert exists
|
# check that letsencrypt cert exists
|
||||||
if [ ! -f /etc/ssl/letsencrypt/mail.$virtualhost.pem ]; then
|
if [ ! -f /etc/ssl/letsencrypt/mail.$domain.pem ]; then
|
||||||
echo "Let's Encrypt cert for mail.$virtualhost does not exist, create that first:"
|
echo "Let's Encrypt cert for mail.$domain does not exist, create that first:"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# enable webmail vhost & restart apache
|
# enable webmail vhost & restart apache
|
||||||
if [ ! -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then
|
if [ ! -f "/etc/apache2/sites-available/mail.$domain.conf" ]; then
|
||||||
echo "Use VMailHTTPS mail.$virtualhost" > /etc/apache2/sites-available/mail.$virtualhost.conf
|
echo "Use VMailHTTPS mail.$domain" > /etc/apache2/sites-available/mail.$domain.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then
|
if [ ! -h "/etc/apache2/sites-enabled/mail.$domain.conf" ]; then
|
||||||
/usr/sbin/a2ensite --quiet mail.$virtualhost
|
/usr/sbin/a2ensite --quiet mail.$domain
|
||||||
/usr/bin/systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
|
/usr/bin/systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user