89 lines
2.1 KiB
Bash
89 lines
2.1 KiB
Bash
|
#!/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
|
||
|
|
||
|
# remove existing dump, if it exists
|
||
|
if [[ -f /var/vmail/$domain/vm_dmp.sql ]]; then
|
||
|
|
||
|
eval mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE vmail < /var/vmail/$domain/vm_dmp.sql
|
||
|
|
||
|
echo
|
||
|
echo "Import complete. If it's no longer need you can remove the dump file:"
|
||
|
echo "/var/vmail/$domain/vm_dmp.sql"
|
||
|
echo
|
||
|
|
||
|
if [[ -f /var/vmail/$virtualhost/roundcubemail ]]; then
|
||
|
|
||
|
echo "Found roundcubemail import file. You probably want to run this next:"
|
||
|
echo "vmail-roundcubemail-settings-import.php $domain"
|
||
|
|
||
|
else
|
||
|
|
||
|
echo "No roundcubemail file found. Did you remember to export & sync that too?"
|
||
|
|
||
|
fi
|
||
|
|
||
|
else
|
||
|
|
||
|
echo "ERROR: Dump file /var/vmail/$domain/vm_dmp.sql does not exist."
|
||
|
exit 1
|
||
|
|
||
|
fi
|
||
|
|
||
|
else
|
||
|
|
||
|
echo "$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
|