#!/bin/bash trap "abort" 0 abort() { #kill special conversion imap server echo "Cleaning up.." pkill -f gateway-conv.cfg 2>/dev/null pkill -f cyrus-conv.conf 2>/dev/null sleep 3 pkill -9 -f gateway-conv.cfg 2>/dev/null pkill -9 -f cyrus-conv.conf 2>/dev/null } echo "Disabling cyrus imap.." svcstop /service/cyrus-imapd || exit 1 touch /service/cyrus-imapd/down #start zarafa imap gateway forever: echo "Starting zarafa imap.." rm /service/zarafa-gateway/down &>/dev/null svcstart /service/zarafa-gateway || exit 1 echo "Starting 2nd zarafa imap in conversion mode.." #start zarafa imap gateway in special passwordless conversion mode #on port 10143 zarafa-gateway -c /etc/zarafa/gateway-conv.cfg || exit 1 #change cyrusconfig (that option should be commented out anyway) sed 's/^sasl_mech_list:.*/#&/' /etc/imapd.conf -i #start cyrus in conversion mode #on port 20143 echo "Starting 2nd cyrus imap in conversion mode.." /usr/cyrus/bin/master -M /etc/cyrus-conv.conf -d || exit 1 sleep 5 # wait for the stuff to start up #settings export TZ=GMT #for imapsync SPECIALUSERS=" admin Administrator mailadmin nobody " MAXAGE=$1 CONVDB="/root/syn3-cyrus2zarafa.$MAXAGE""days.done" if [ "$MAXAGE" ]; then PARS="$PARS --maxage $MAXAGE" fi echo "Starting conversion..." migrate() { imapsync \ --host1 localhost \ --port1 20143 \ --authuser1 admin \ --user1 "$user" \ --password1 `cat /etc/webint/LDAP_MASTER_PASSWD` \ --host2 127.0.0.1 \ --port2 10143 \ --user2 "$user" \ --password2 "none" \ --prefix2 "" \ --ssl2 \ --sep2 / \ --folderrec INBOX \ --skipsize \ --nofoldersizes \ --useheader Message-ID \ --idatefromheader \ --nohash \ --regextrans2 "s/Spam/Junk E-mail/" \ --regextrans2 "s/Trash/Deleted Items/" \ --regextrans2 "s/Sent/Sent Items/" \ $PARS ; return $? } #traverse all users ldapsearchpars="ldapsearch -D cn=Manager,dc=syn-3 -w `cat /etc/webint/LDAP_MASTER_PASSWD` -b ou=Users,dc=syn-3 -s one" for user in `$ldapsearchpars | grep ^uid: | grep -v "\\$$" | cut -f2 -d' '`; do if ! echo "$SPECIALUSERS" | grep " $user " >/dev/null; then if ! grep -x "$user" "$CONVDB" &>/dev/null; then echo "Migrating $user pass 1:"; if migrate; then #(second pass is needed to correct mail flags, because of some imapsync/zarafa problem) echo "Migrating $user pass 2:"; if migrate; then sync echo "Migration of $user complete!" echo "$user" >> $CONVDB sync fi fi else echo "$user OK: already migrated"; fi fi done echo "Conversion done, days=$MAXAGE"; echo "Run again to see if all users are OK."