/[smeserver]/rpms/dovecot/sme7/migrate-folders
ViewVC logotype

Annotation of /rpms/dovecot/sme7/migrate-folders

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Tue Jun 12 15:07:20 2007 UTC (17 years ago) by slords
Branch: MAIN
CVS Tags: dovecot-1_0-1_2_rc15_el4_sme, dovecot-1_0_7-2_el4_sme, HEAD
Import on branch sme7 of package dovecot-1.0-1.2.rc15.el4.sme.src.rpm

1 slords 1.1 #!/bin/bash
2    
3     # author: G.R.Keech <rkeech@redhat.com>
4     # name: migrate-folders
5     # date: 2004-10-20
6    
7     # This script assists in the conversion of mail boxes
8     # in mbox format to maildir format.
9     # See also migrate-users.
10    
11     # Applicability.
12     #
13     # This script is intended for the common case on Red Hat systems
14     # where mail users have mail folders in their home directories
15     # under /home, and have inboxes in /var/spool/mail/
16     #==================================================================
17     # Change the value of the elements in this section as required.
18    
19     #This is a list of folders, one per line. This does not
20     #include the inboxes. This might be prepared starting with
21     #the output of "find /home -type d".
22     FOLDERLIST=/root/migrate/folderlist
23     # folder is the existing mbox folder being migrated.
24     # It is a path under /home.
25     # eg if oldfolder is fred/personal, then folder is personal,
26     # user is fred.
27    
28     #Specify the location of the new location for mail folders.
29     #This cannot be the same as the old location because it will
30     #create directory names that contend with existing file names.
31     NEWBASE=/var/spool/mail2
32    
33     #The script to convert invidual mail folders to maildir format.
34     #http://perfectmaildir.home-dn.net/
35     FOLDERCONVERT=/usr/local/bin/perfect_maildir.pl
36    
37     #This is a list of users to have their mail folders created.
38     #One user per line.
39     #Suggest create with cut -d: -f1 /etc/passwd > ~/migrate/u1
40     #then remove inappropriate entries by hand.
41     USERLIST=/root/migrate/userlist
42    
43     # Detailed migration information is sent to this file
44     MIGRATELOG=/tmp/foldermigrationlog-$(date -I)
45     #=================================================================
46     echo
47     echo "Have you created the users' mail directories yet? (y/n)"
48     echo
49     read ans
50     if [ "$ans" != "y" ]
51     then
52     echo Good Bye.
53     echo use the migrate-users script first.
54     exit 0
55     fi
56     echo
57     echo This will copy existing mbox-style mail folders listed
58     echo in the file $FOLDERLIST. Maildir-style folders will
59     echo be created under $NEWBASE
60     echo
61     echo "Do you want to continue? (y/n)"
62     read ans
63     if [ "$ans" != "y" ]
64     then
65     echo Good Bye.
66     exit 0
67     fi
68     echo
69     echo Note: Detailed folder migration information will be sent to $MIGRATELOG
70     echo
71     echo Press enter to start
72     read ans
73    
74     if [ ! -x ${FOLDERCONVERT} ]
75     then
76     echo Error: file ${FOLDERCONVERT} is not available to execute.
77     exit 1
78     fi
79    
80     if [ ! -d ${NEWBASE} ]
81     then
82     echo Error: directory $NEWBASE does not exist
83     exit 1
84     fi
85    
86     if [ ! -f "${USERLIST}" ]
87     then
88     echo Error: user list file \"$USERLIST\" does not exist.
89     exit 1
90     fi
91    
92    
93     #-----------------------------------------------------------------
94     echo
95     echo Testing that the base of the folderlist entries corresponds to usernames
96     while read oldfolder
97     do
98     user="$(dirname "$oldfolder")"
99     if grep ^${user}: /etc/passwd &> /dev/null
100     then
101     echo -n .
102     else
103     echo User \"$user\": is bogus.
104     echo The string \"$user\" from the file \"$FOLDERLIST\" needs to
105     echo correspond exactly to a username. Edit the file accordingly.
106     exit 1
107     fi
108     done < $FOLDERLIST
109     echo
110     echo PASS
111     echo
112     nusers=$(wc -l $USERLIST | awk '{ print $1 }' )
113     n=1
114     #-----------------------------------------------------------------
115     # Iterate through user list and migrate folders.
116     while read user
117     do
118     #-----------------------------------------------------------------
119     # Step 1: Check stuff
120     if grep ^${user}: /etc/passwd &> /dev/null
121     then
122     echo -n "$n / $nusers : User \"$user\" is OK: "
123     n=$(( $n + 1 ))
124     echo "User \"$user\"" >> $MIGRATELOG
125    
126     inbox=/var/spool/mail/${user}
127    
128     if [ \( ! -f "${inbox}" \) -o \( ! -s "${inbox}" \) ]
129     then
130     echo User \"${user}\" has no inbox to convert.
131     else
132     #-----------------------------------------------------------------
133     # Step 2: Migrate user inboxes from /var/spool/mail/.
134     newdir="${NEWBASE}/${user}/"
135     $FOLDERCONVERT "$newdir" < "${inbox}" >> $MIGRATELOG 2>&1
136     chown -R ${user}:mail "${newdir}"
137     find "$newdir" -type f -exec chmod 600 {} \;
138     echo -n " inbox "
139     fi
140     #-----------------------------------------------------------------
141     # Step 3: Migrate other mail folders from user home directories.
142     while read oldfolder
143     do
144     folder=$(basename "${oldfolder}")
145     fuser="$(dirname "$oldfolder")"
146    
147     if [ "$user" = "$fuser" ]
148     then
149     if [ ! -f "/home/${oldfolder}" ]
150     then
151     echo Error folder \"${folder}\" does not exist.
152     break
153     fi
154    
155     if [ ! -d ${NEWBASE}/${fuser} ]
156     then
157     echo Error ${NEWBASE}/${fuser} does not exist.
158     break
159     fi
160    
161     newdir="${NEWBASE}/${fuser}/.$folder"
162     mkdir -p "$newdir"/cur
163     mkdir -p "$newdir"/new
164     mkdir -p "$newdir"/tmp
165     chmod -R 770 "${newdir}"
166     $FOLDERCONVERT "$newdir" < "/home/$oldfolder" >> $MIGRATELOG 2>&1
167     chown -R ${user}:mail "${newdir}"
168     #chmod 600 "$newdir/cur/*"
169     find "$newdir" -type f -exec chmod 600 {} \;
170    
171     echo "$folder" >> ${NEWBASE}/${fuser}/.subscriptions
172     chmod 600 ${NEWBASE}/${fuser}/.subscriptions
173     chown ${fuser}:mail ${NEWBASE}/${fuser}/.subscriptions
174    
175     echo -n .
176     fi
177     done < $FOLDERLIST
178     echo
179    
180     else
181     echo User "$user: is bogus."
182     fi
183    
184     done < $USERLIST
185    
186     echo
187     echo
188     echo To make the new base mail directory active, change the
189     echo mail_spool_directory setting for postfix using
190     echo postconf -e \"mail_spool_directory = ${NEWBASE}/\"
191     echo and change Dovecots default_mail_env setting in
192     echo /etc/dovecot.conf to
193     echo default_mail_env = maildir:${NEWBASE}/%u
194     echo
195    

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed