source: npl/mailserver/zarafa_conf7/root/usr/bin/syn3-cyrus2zarafa @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 2.5 KB
Line 
1#!/bin/bash
2
3trap "abort" 0
4abort()
5{
6        #kill special conversion imap server
7        echo "Cleaning up.."
8        pkill -f gateway-conv.cfg 2>/dev/null
9        pkill -f cyrus-conv.conf 2>/dev/null
10        sleep 3
11        pkill -9 -f gateway-conv.cfg 2>/dev/null
12        pkill -9 -f cyrus-conv.conf 2>/dev/null
13}
14
15echo "Disabling cyrus imap.."
16svcstop /service/cyrus-imapd || exit 1
17touch /service/cyrus-imapd/down
18
19#start zarafa imap gateway forever:
20echo "Starting zarafa imap.."
21rm /service/zarafa-gateway/down &>/dev/null
22svcstart /service/zarafa-gateway || exit 1
23
24
25echo "Starting 2nd zarafa imap in conversion mode.."
26#start zarafa imap gateway in special passwordless conversion mode
27#on port 10143
28zarafa-gateway -c /etc/zarafa/gateway-conv.cfg || exit 1
29
30#change cyrusconfig (that option should be commented out anyway)
31sed 's/^sasl_mech_list:.*/#&/' /etc/imapd.conf -i 
32
33#start cyrus in conversion mode
34#on port 20143
35echo "Starting 2nd cyrus imap in conversion mode.."
36/usr/cyrus/bin/master -M /etc/cyrus-conv.conf -d || exit 1
37
38sleep 5 # wait for the stuff to start up
39
40#settings
41export TZ=GMT #for imapsync
42SPECIALUSERS=" admin Administrator mailadmin nobody "
43MAXAGE=$1
44CONVDB="/root/syn3-cyrus2zarafa.$MAXAGE""days.done"
45if [ "$MAXAGE" ]; then
46        PARS="$PARS --maxage $MAXAGE"
47fi
48
49
50echo "Starting conversion..."
51migrate()
52{
53    imapsync \
54        --host1 localhost \
55        --port1 20143 \
56        --authuser1 admin \
57        --user1 "$user" \
58        --password1 `cat /etc/webint/LDAP_MASTER_PASSWD` \
59        --host2 127.0.0.1 \
60        --port2 10143 \
61        --user2 "$user" \
62        --password2 "none" \
63        --prefix2 "" \
64        --ssl2 \
65        --sep2 / \
66        --folderrec INBOX \
67        --skipsize \
68        --nofoldersizes  \
69        --useheader Message-ID \
70        --idatefromheader \
71        --nohash \
72        --regextrans2 "s/Spam/Junk E-mail/" \
73        --regextrans2 "s/Trash/Deleted Items/" \
74        --regextrans2 "s/Sent/Sent Items/" \
75        $PARS ;
76
77    return $?
78}
79
80#traverse all users
81ldapsearchpars="ldapsearch -D cn=Manager,dc=syn-3 -w `cat /etc/webint/LDAP_MASTER_PASSWD` -b ou=Users,dc=syn-3 -s one"
82for user in `$ldapsearchpars | grep ^uid: | grep -v "\\$$" | cut -f2 -d' '`; do
83        if ! echo "$SPECIALUSERS" | grep " $user " >/dev/null; then
84                if ! grep -x "$user" "$CONVDB" &>/dev/null; then
85                        echo "Migrating $user pass 1:";
86                        if migrate; then
87                                #(second pass is needed to correct mail flags, because of some imapsync/zarafa problem)
88                                echo "Migrating $user pass 2:";
89                                if migrate; then
90                                        sync
91                                        echo "Migration of $user complete!"
92                                        echo "$user" >> $CONVDB
93                                        sync
94                                fi
95                        fi
96                else
97                        echo "$user OK: already migrated";
98                fi
99        fi     
100done
101
102echo "Conversion done, days=$MAXAGE";
103echo "Run again to see if all users are OK."
Note: See TracBrowser for help on using the repository browser.