/[packages]/cauldron/cyrus-imapd/current/SOURCES/cyrus-imapd.cvt_cyrusdb_all
ViewVC logotype

Contents of /cauldron/cyrus-imapd/current/SOURCES/cyrus-imapd.cvt_cyrusdb_all

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33418 - (show annotations) (download)
Sat Jan 22 23:52:57 2011 UTC (13 years, 2 months ago) by ennael
File size: 5689 byte(s)
imported package cyrus-imapd
1 #!/bin/sh
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 # This script converts all db files of a cyrus installation from their
18 # existing format to the format required by the current installation.
19 # The format of current db files is determined using the 'file' command
20 # with a magic file added for skiplist db, the new format is read from
21 # a config file usually in /usr/share/cyrus-imapd/rpm/db.cfg, which is
22 # created while compiling. After converting, the db.cfg file is
23 # copied to a cache file usually at /var/lib/imap/rpm/db.cfg.cache to
24 # allow bypassing this converting script if both files are identical.
25 # While this is a bit less secure, it may be useful on big server where
26 # db converting is done automatically.
27 #
28 # This script can safely be run as root, it will reexec itself as user
29 # cyrus if needed.
30 #
31 # author: Simon Matter, Invoca Systems <simon.matter@invoca.ch>
32
33 # changelog
34 # v1.0.1, Oct 22 2002 Simon Matter <simon.matter@invoca.ch>
35 # - added two-step conversion method
36 #
37 # v1.0.2, Jan 10 2003 Simon Matter <simon.matter@invoca.ch>
38 # - fixed a bug where cvt_cyrusdb was called to convert empty or
39 # nonexistent files
40 #
41 # v1.0.3, Mar 14 2003 Simon Matter <simon.matter@invoca.ch>
42 # - fixed a problem with new versions of the file command
43 #
44 # v1.0.4
45 # - added GPL license
46 #
47 # v1.0.5, May 02 2003 Simon Matter <simon.matter@invoca.ch>
48 # - modified exec path
49 #
50 # Extra modifications for Mandrake RPM by
51 # Luca Olivetti <luca@olivetti.cjb.net>:
52 #
53 # - get spool directory from config file
54 # - get system_magic from file --version
55 # - Dec 01 2003 added annotations.db for cyrus-2.2.2
56 # - Dec 01 2003 changed "db3" to "berkeley"
57 # - Jan 15 2003 get db configuration from /etc/imapd.conf
58
59 if [ -n "`/sbin/pidof cyrus-master`" ]; then
60 echo "ERROR: cyrus-master is running, unable to convert mailboxes!"
61 exit 1
62 fi
63
64 if [ ! -f /etc/imapd.conf ]; then
65 echo "ERROR: configuration file not found."
66 exit 1
67 fi
68
69 # force cyrus user for security reasons
70 if [ ! $(whoami) = "cyrus" ]; then
71 exec su - cyrus -c "cd $PWD ; $0"
72 fi
73
74 # take system magic location from file --version
75 system_magic=`file --version | awk '/magic file/ {print $4}'`
76 cyrus_magic=/usr/share/cyrus-imapd/rpm/magic
77 cvt_cyrusdb=/usr/lib/cyrus-imapd/cvt_cyrusdb
78
79 # get_config [config default]
80 # extracts config option from config file
81 get_config() {
82 if config=`grep "^$1" /etc/imapd.conf` ; then
83 echo $config | cut -d: -f2 | sed -e 's/^ *//' -e 's/-nosync//' -e 's/ *$//'
84 else
85 echo $2
86 fi
87 }
88
89 # get imap directory from config file
90 imap_prefix=`get_config configdirectory /var/lib/imap`
91
92 # files get mode 0600
93 umask 166
94
95 # get database backends from config file
96 CONFIG_DB_DUPLICATE=`get_config duplicate_db berkeley`
97 CONFIG_DB_MBOX=`get_config mboxlist_db skiplist`
98 CONFIG_DB_SEEN=`get_config seenstate_db skiplist`
99 CONFIG_DB_SUBS=`get_config subscription_db flat`
100 CONFIG_DB_TLS=`get_config tlscache_db berkeley`
101 CONFIG_DB_ANNOTATION=`get_config annotation_db skiplist`
102
103 # file_type [file]
104 file_type() {
105 this_type=$(file -b -m "$system_magic:$cyrus_magic" "$1")
106 if echo "$this_type" | grep -qi skip > /dev/null 2>&1; then
107 echo skiplist
108 elif echo "$this_type" | grep -qi text > /dev/null 2>&1; then
109 echo flat
110 else
111 echo berkeley
112 fi
113 }
114
115 # cvt_file [file] [db]
116 cvt_file() {
117 target="$1"
118 new_db="$2"
119 if [ -s "$target" ]; then
120 old_db=$(file_type "$target")
121 if [ ! "$old_db" = "$new_db" ]; then
122 # The two-step conversion is paranoia against the filenames being encoded
123 # inside the database or logfiles (berkeley does this, for example).
124 rm -f "${target}.flat"
125 if [ "$old_db" = "flat" ]; then
126 cp -a "$target" "${target}.flat"
127 else
128 $cvt_cyrusdb "$target" "$old_db" "${target}.flat" flat
129 fi
130 RETVAL=$?
131 ERRVAL=$[ $ERRVAL + $RETVAL ]
132 if [ $RETVAL -eq 0 ]; then
133 rm -f "$target"
134 if [ -s "${target}.flat" ]; then
135 if [ "$new_db" = "flat" ]; then
136 cp -a "${target}.flat" "$target"
137 else
138 $cvt_cyrusdb "${target}.flat" flat "$target" "$new_db"
139 fi
140 fi
141 RETVAL=$?
142 ERRVAL=$[ $ERRVAL + $RETVAL ]
143 if [ $RETVAL -eq 0 ]; then
144 rm -f "${target}.flat"
145 else
146 echo "ERROR: unable to convert ${target}.flat from flat to $new_db"
147 fi
148 else
149 echo "ERROR: unable to convert $target from $old_db to flat"
150 fi
151 fi
152 fi
153 }
154
155 ERRVAL=0
156
157 # convert all db files
158 cvt_file "$imap_prefix/mailboxes.db" "$CONFIG_DB_MBOX"
159 cvt_file "$imap_prefix/deliver.db" "$CONFIG_DB_DUPLICATE"
160 cvt_file "$imap_prefix/tls_sessions.db" "$CONFIG_DB_TLS"
161
162 find "$imap_prefix/user/" -name '*.seen' -type f | while read db_file; do
163 cvt_file "$db_file" "$CONFIG_DB_SEEN"
164 done
165
166 find "$imap_prefix/user/" -name '*.sub' -type f | while read db_file; do
167 cvt_file "$db_file" "$CONFIG_DB_SUBS"
168 done
169
170 find "$imap_prefix/" -name 'annotations.db' -type f | while read db_file; do
171 cvt_file "$db_file" "$CONFIG_DB_ANNOTATION"
172 done
173
174 exit $ERRVAL

  ViewVC Help
Powered by ViewVC 1.1.30