Alternc  latest
Alternc logiel libre pour l'hébergement
3.0.0~2.sh
Go to the documentation of this file.
1 #!/bin/bash
2 # Upgrading script to AlternC 1.1
3 
4 CONFIG_FILE="/etc/alternc/local.sh"
5 PATH=/sbin:/bin:/usr/sbin:/usr/bin
6 
7 umask 022
8 
9 if [ ! -r "$CONFIG_FILE" ]; then
10  echo "Can't access $CONFIG_FILE."
11  exit 1
12 fi
13 
14 if [ `id -u` -ne 0 ]; then
15  echo "3.0.0~2.sh must be launched as root"
16  exit 1
17 fi
18 
19 . "$CONFIG_FILE"
20 
21 MAIL_DIR="$ALTERNC_LOC/mail"
22 
23 ## This part update mails' file owner and group ##
24 fix_mail() {
25  read LOGIN GID || true
26  while [ "$LOGIN" ]; do
27  INITIALE=`echo $LOGIN |cut -c1`
28  MAIL=$(echo $LOGIN |sed -e 's/\@/_/')
29  REP="$ALTERNC_LOC/mail/$INITIALE/$MAIL/"
30  chown --recursive $GID:vmail "$REP"
31  read LOGIN GID || true
32  done
33 }
34 
35 query="select user,userdb_gid from dovecot_view"
36 mysql --defaults-file=/etc/alternc/my.cnf --skip-column-names -B -e "$query" |fix_mail
37 ## End of mails' files owner and group fixing part ##
38 
39 ## This part does the migration from Courier IMAP and POP3, preserving IMAP UIDs and POP3 UIDLs. ##
40 ## It reads Courier's 'courierimapuiddb' and 'courierpop3dsizelist' files and produces 'dovecot-uidlist' file from it. ##
41 # We warn user it will take some time to migrate all indexes
42 echo -e "\033[31m"
43 echo "################################################"
44 echo "# /!\ CONVERTING COURIER INDEXES TO DOVECOT /!\ "
45 echo "# /!\ THIS MAY TAKE A WHILE ! /!\ "
46 echo "# "
47 echo "# If you want to regenerate specifics indexes, "
48 echo "# remove related 'dovecot-uidlist' files in "
49 echo "# $MAIL_DIR "
50 echo "# then execute this command manually : "
51 echo "# "
52 echo "# perl \"/usr/lib/alternc/courier-dovecot-migrate.pl\" --to-dovecot --convert --recursive \"$MAIL_DIR\""
53 echo "# "
54 echo "# Add \"--overwrite\" option if you want to "
55 echo "# overwrite ALL 'dovecot-uidlist' indexes "
56 echo "################################################"
57 echo -e "\033[0m"
58 
59 
60 # Stoping dovecot service
61 invoke-rc.d dovecot stop || true
62 
63 # We call the migration script (provided by wiki.dovecot.com)
64 perl "/usr/lib/alternc/courier-dovecot-migrate.pl" --to-dovecot --convert --recursive "$MAIL_DIR"
65 
66 
67 #We have to resync maildirs quotas with dovecot informations.
68 /usr/lib/alternc/update_quota_mail.sh
69 
70 # Starting dovecot service
71 invoke-rc.d dovecot start || true
72 ## End of migration part