Many-Domain script: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Migrate|Back]] | |||
#!/bin/sh | #!/bin/sh | ||
# This script converts the vpopmail db traditionally used by QMT with domain | # This script converts the vpopmail db traditionally used by QMT with domain | ||
Line 49: | Line 50: | ||
fi | fi | ||
done | done | ||
[http://wiki.qmailtoaster.org/index.php?title=Alias_Domains Alias Domains] |
Latest revision as of 20:29, 7 April 2024
#!/bin/sh # This script converts the vpopmail db traditionally used by QMT with domain # tables (domain_tld) to the vpopmail table containing many domains (md). # In addition to this vpopmail db conversion appropriate replacement packages # must be installed to interact with the converted vpopmail db, specifically, # CentOS 7/8 pkgs designated with 'md'. The conversion was necessary not only # for Dovecot's dsync utility to utilize commands like `doveadm user '*'` which # fails with Dovecot's vpopmail driver but because Dovecot is dropping support # for the vpopmail driver.
passwd= read -s -p "Enter your MySQL DB management password: " passwd echo "" if [ "$passwd" == "" ]; then echo "You must enter the MySQL DB management password" exit 0 fi
MYSQLPW=$passwd credfile=~/sql.cnf echo -e "[client]\nuser=root\npassword='$MYSQLPW'\nhost=localhost" > $credfile
mysql --defaults-extra-file=$credfile -e "use vpopmail" [ "$?" != "0" ] && echo "Password error, exiting..." && exit 1
DB=vpopmail
mysql --defaults-extra-file=$credfile -D $DB -e "CREATE TABLE vpopmail \ (pw_name char(32) NOT NULL, \ pw_domain char(96) NOT NULL, \ pw_passwd char(40) DEFAULT NULL, \ pw_uid int(11) DEFAULT NULL, \ pw_gid int(11) DEFAULT NULL, \ pw_gecos char(48) DEFAULT NULL, \ pw_dir char(160) DEFAULT NULL, \ pw_shell char(20) DEFAULT NULL,\ pw_clear_passwd char(16) DEFAULT NULL, \ PRIMARY KEY (pw_name,pw_domain)) ENGINE=InnoDB DEFAULT CHARSET=latin1" [ "$?" != "0" ] && echo "Error creating vpopmail table" && exit 1 for i in `echo "show tables" | mysql --defaults-extra-file=$credfile -D $DB|grep -v Tables_in_`; do if ! [ $i = dir_control ] && ! [ $i = lastauth ] && ! [ $i = vlog ] && ! [ $i = valias ] && ! [ $i = vpopmail ]; then # MySQL does not allow table names with a dot (.) so vpopmail replaces the dot (.) with an underscore (_) for # domain table names, example: table whitehorsetc.com becomes whitehorsetc_com. Vpopmail utilities will not allow # one to create a domain name with an underscore even though RFC allows it. So, we can safely replace all domain # table name underscores (_) with periods or dots (.) (below, 'domain_name') in our conversion for entry into the # new vpopmail many domains table. domain_name=`echo $i | sed -e 's/\(.*\)_/\1./' -e 's/_/-/g'` echo $domain_name; mysql --defaults-extra-file=$credfile -D $DB -B --skip-column-names -e \ "INSERT INTO vpopmail SELECT pw_name, '$domain_name', pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell, pw_clear_passwd \ FROM $i" fi done