b1ea2ee09e
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.
102 lines
2.6 KiB
Bash
Executable File
102 lines
2.6 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 "Add domain to vmail system"
|
|
echo ""
|
|
echo "usage: $thisfilename -d <domain>"
|
|
echo ""
|
|
echo " -h Print this help."
|
|
echo " -d Domain to export from the vmail database."
|
|
exit
|
|
}
|
|
|
|
vmail:getoptions "$@"
|
|
|
|
# check for domain
|
|
if [[ -z $domain ]]; then
|
|
echo "ERROR: domain name is required"
|
|
exit 1
|
|
fi
|
|
|
|
# build query
|
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
|
dbcmdopts="-s -r -N -e"
|
|
|
|
# check if domain exists in vmail database
|
|
dbquery="SELECT id FROM vm_domains WHERE domain='$domain';"
|
|
domains_id=`$dbcmd $dbcmdopts "$dbquery"`
|
|
|
|
if [[ "$domains_id" -gt '0' ]] ; then
|
|
|
|
echo "ERROR: $domain already exists in vmail database."
|
|
exit 1
|
|
|
|
elif [[ -z $domains_id ]] ; then
|
|
|
|
if [[ -d /var/vmail/$domain ]]; then
|
|
|
|
if [[ -d /var/vmail/$domain/.exp ]]; then
|
|
|
|
# check for vmail sql file
|
|
if [[ -f /var/vmail/$domain/.exp/vm_dmp.sql ]]; then
|
|
|
|
# import vmail sql data
|
|
eval mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE vmail < /var/vmail/$domain/.exp/vm_dmp.sql
|
|
|
|
# roundcube settings
|
|
if [[ -f /var/vmail/$domain/.exp/roundcubemail.json ]]; then
|
|
/usr/local/bin/vmail-roundcubemail-settings-import.php $domain
|
|
fi
|
|
|
|
# /etc/ configs
|
|
if [[ -d /var/vmail/$domain/.exp/etc ]]; then
|
|
cp -a /var/vmail/$domain/.exp/etc/* /etc/
|
|
# reload dovecot
|
|
if [[ -f /etc/dovecot/sites.d/mail.$domain.conf ]]; then
|
|
systemctl --quiet try-reload-or-restart dovecot.service
|
|
fi
|
|
# apache reload (webmail) handled by vhost-reload-apache.path
|
|
fi
|
|
|
|
echo
|
|
echo "Vmail import complete. If it's no longer need you can remove the data dir:"
|
|
echo "rm -r /var/vmail/$domain/.exp/"
|
|
|
|
else
|
|
|
|
echo "ERROR: Vmail SQL file does not exist."
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "ERROR: Vmail dir for $domain exists, but there is no .exp data dir."
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "ERROR: $domain exists in vmail db, but /var/vmail/$domain dir does not exist."
|
|
echo "This script excepts a sync of the /var/vmail/$domain dir and no records in the db."
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
echo "ERROR: System error querying vmail database"
|
|
exit 1
|
|
fi
|