2014-03-27 17:39:28 +00:00
|
|
|
#!/bin/bash
|
2012-10-15 15:14:43 +00:00
|
|
|
# Upgrading script to AlternC 1.1
|
2012-09-26 09:41:41 +00:00
|
|
|
|
|
|
|
CONFIG_FILE="/etc/alternc/local.sh"
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
|
|
|
|
umask 022
|
|
|
|
|
|
|
|
if [ ! -r "$CONFIG_FILE" ]; then
|
|
|
|
echo "Can't access $CONFIG_FILE."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ `id -u` -ne 0 ]; then
|
2014-03-28 13:53:34 +00:00
|
|
|
echo "3.0.0~2.sh must be launched as root"
|
2012-09-26 09:41:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-09-26 12:22:10 +00:00
|
|
|
. "$CONFIG_FILE"
|
|
|
|
|
2012-10-15 15:14:43 +00:00
|
|
|
MAIL_DIR="$ALTERNC_LOC/mail"
|
|
|
|
|
|
|
|
## This part update mails' file owner and group ##
|
2012-09-26 09:41:41 +00:00
|
|
|
fix_mail() {
|
|
|
|
read LOGIN GID || true
|
|
|
|
while [ "$LOGIN" ]; do
|
|
|
|
INITIALE=`echo $LOGIN |cut -c1`
|
2012-10-15 15:14:43 +00:00
|
|
|
MAIL=$(echo $LOGIN |sed -e 's/\@/_/')
|
2012-09-26 12:22:10 +00:00
|
|
|
REP="$ALTERNC_LOC/mail/$INITIALE/$MAIL/"
|
2012-09-26 09:41:41 +00:00
|
|
|
chown --recursive $GID:vmail "$REP"
|
2012-10-15 15:14:43 +00:00
|
|
|
read LOGIN GID || true
|
2012-09-26 12:22:10 +00:00
|
|
|
done
|
2012-09-26 09:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
query="select user,userdb_gid from dovecot_view"
|
|
|
|
mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |fix_mail
|
2012-10-15 15:14:43 +00:00
|
|
|
## End of mails' files owner and group fixing part ##
|
2012-09-26 09:41:41 +00:00
|
|
|
|
2012-10-15 15:14:43 +00:00
|
|
|
## This part does the migration from Courier IMAP and POP3, preserving IMAP UIDs and POP3 UIDLs. ##
|
|
|
|
## It reads Courier's 'courierimapuiddb' and 'courierpop3dsizelist' files and produces 'dovecot-uidlist' file from it. ##
|
|
|
|
# We warn user it will take some time to migrate all indexes
|
2014-03-28 13:53:34 +00:00
|
|
|
echo -e "\033[31m"
|
2012-10-15 15:14:43 +00:00
|
|
|
echo "################################################"
|
|
|
|
echo "# /!\ CONVERTING COURIER INDEXES TO DOVECOT /!\ "
|
|
|
|
echo "# /!\ THIS MAY TAKE A WHILE ! /!\ "
|
|
|
|
echo "# "
|
|
|
|
echo "# If you want to regenerate specifics indexes, "
|
|
|
|
echo "# remove related 'dovecot-uidlist' files in "
|
|
|
|
echo "# $MAIL_DIR "
|
|
|
|
echo "# then execute this command manually : "
|
|
|
|
echo "# "
|
|
|
|
echo "# perl \"/usr/lib/alternc/courier-dovecot-migrate.pl\" --to-dovecot --convert --recursive \"$MAIL_DIR\""
|
|
|
|
echo "# "
|
|
|
|
echo "# Add \"--overwrite\" option if you want to "
|
|
|
|
echo "# overwrite ALL 'dovecot-uidlist' indexes "
|
|
|
|
echo "################################################"
|
2014-03-28 13:53:34 +00:00
|
|
|
echo -e "\033[0m"
|
|
|
|
|
2012-09-26 09:41:41 +00:00
|
|
|
|
2012-10-15 15:14:43 +00:00
|
|
|
# Stoping dovecot service
|
|
|
|
invoke-rc.d dovecot stop || true
|
2012-09-26 09:41:41 +00:00
|
|
|
|
2012-10-15 15:14:43 +00:00
|
|
|
# We call the migration script (provided by wiki.dovecot.com)
|
|
|
|
perl "/usr/lib/alternc/courier-dovecot-migrate.pl" --to-dovecot --convert --recursive "$MAIL_DIR"
|
2012-09-26 09:41:41 +00:00
|
|
|
|
2013-01-23 13:47:52 +00:00
|
|
|
|
|
|
|
#We have to resync maildirs quotas with dovecot informations.
|
|
|
|
/usr/lib/alternc/update_quota_mail.sh
|
|
|
|
|
2012-10-15 15:14:43 +00:00
|
|
|
# Starting dovecot service
|
|
|
|
invoke-rc.d dovecot start || true
|
|
|
|
## End of migration part
|