1 |
#!/bin/bash |
2 |
# file: migrate-users |
3 |
# author: Richard Keech <rkeech@redhat.com> |
4 |
|
5 |
# This script assists in the conversion of mail boxes |
6 |
# in mbox format to maildir format. |
7 |
# See also migrage-folders. |
8 |
|
9 |
#This is a list of users to have their mail folders created. |
10 |
#One user per line. |
11 |
#Suggest create with cut -d: -f1 /etc/passwd > ~/migrate/u1 |
12 |
#then remove inappropriate entries by hand. |
13 |
USERLIST=/root/migrate/userlist |
14 |
|
15 |
#Specify the location of the new location for mail folders. |
16 |
#This cannot be the same as the old location because it will |
17 |
#create directory names that contend with existing file names. |
18 |
NEWBASE=/var/spool/mail2/ |
19 |
|
20 |
echo this will create user mail folders in $NEWBASE from |
21 |
echo the list of users in $USERLIST. |
22 |
echo |
23 |
echo "Do you want to continue? (y/n)" |
24 |
read ans |
25 |
if [ "$ans" != "y" ] |
26 |
then |
27 |
echo Good Bye. |
28 |
exit 0 |
29 |
fi |
30 |
|
31 |
if [ ! -f "$USERLIST" ] |
32 |
then |
33 |
echo Error: user list file \"$USERLIST\" does not exist. |
34 |
exit 1 |
35 |
fi |
36 |
|
37 |
if [ ! -d "$NEWBASE" ] |
38 |
then |
39 |
echo Error: new base directory \"$NEWBASE\" does not exist. |
40 |
exit 1 |
41 |
fi |
42 |
|
43 |
while read user |
44 |
do |
45 |
if grep ^${user}: /etc/passwd &> /dev/null |
46 |
then |
47 |
echo User \"$user\" is OK. |
48 |
else |
49 |
echo User \"$user\": is bogus. |
50 |
exit 1 |
51 |
fi |
52 |
|
53 |
mkdir ${NEWBASE}/$user |
54 |
newdir="${NEWBASE}/${user}/" |
55 |
mkdir -p "$newdir"/cur |
56 |
mkdir -p "$newdir"/new |
57 |
mkdir -p "$newdir"/tmp |
58 |
chmod -R 770 "${newdir}" |
59 |
chown -R ${user}:mail "$newdir" |
60 |
done < $USERLIST |
61 |
|
62 |
echo |
63 |
echo New mail directories have been created under $NEWBASE |
64 |
echo |
65 |
echo If required, prepare a list of existing mbox folders |
66 |
echo as /root/migrate/folderlist and run migrate-folders. |
67 |
echo |
68 |
echo To make the new base mail directory active, change the |
69 |
echo mail_spool_directory setting for postfix using |
70 |
echo postconf -e \"mail_spool_directory = ${NEWBASE}/\" |
71 |
echo and change Dovecots default_mail_env setting in |
72 |
echo /etc/dovecot.conf to |
73 |
echo default_mail_env = maildir:${NEWBASE}/%u |
74 |
echo |
75 |
echo If you want to migrate existing mail folders then defer |
76 |
echo the dovecot and postfix changes until the folder migration |
77 |
echo is complete. |