Michal Hlavinka 9d65fa
#!/bin/bash
John Dennis 38f226
John Dennis 38f226
# This program is free software; you can redistribute it and/or modify
John Dennis 38f226
# it under the terms of the GNU General Public License as published by
John Dennis 38f226
# the Free Software Foundation; either version 2 of the License, or
John Dennis 38f226
# (at your option) any later version.
John Dennis 38f226
#
John Dennis 38f226
# This program is distributed in the hope that it will be useful,
John Dennis 38f226
# but WITHOUT ANY WARRANTY; without even the implied warranty of
John Dennis 38f226
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
John Dennis 38f226
# GNU General Public License for more details.
John Dennis 38f226
#
John Dennis 38f226
# You should have received a copy of the GNU General Public License
John Dennis 38f226
# along with this program; if not, write to the Free Software
John Dennis 38f226
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
John Dennis 38f226
John Dennis 38f226
# This script converts all db files of a cyrus installation from their
John Dennis 38f226
# existing format to the format required by the current installation.
John Dennis 38f226
# The format of current db files is determined using the 'file' command
John Dennis 38f226
# with a magic file added for skiplist db, the new format is read from
John Dennis 38f226
# a config file usually in /usr/share/cyrus-imapd/rpm/db.cfg, which is
John Dennis 38f226
# created while compiling. After converting, the db.cfg file is
John Dennis 38f226
# copied to a cache file usually at /var/lib/imap/rpm/db.cfg.cache to
John Dennis 38f226
# allow bypassing this converting script if both files are identical.
John Dennis 38f226
# While this is a bit less secure, it may be useful on big server where
John Dennis 38f226
# db converting is done automatically.
John Dennis 38f226
#
John Dennis 38f226
# This script can safely be run as root, it will reexec itself as user
John Dennis 38f226
# cyrus if needed.
John Dennis 38f226
#
John Dennis 38f226
# author: Simon Matter, Invoca Systems <simon.matter@invoca.ch>
John Dennis 38f226
John Dennis 38f226
# changelog
John Dennis 38f226
# v1.0.1, Oct 22 2002 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - added two-step conversion method
John Dennis 38f226
#
John Dennis 38f226
# v1.0.2, Jan 10 2003 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - fixed a bug where cvt_cyrusdb was called to convert empty or
John Dennis 38f226
#   nonexistent files
John Dennis 38f226
#
John Dennis 38f226
# v1.0.3, Mar 14 2003 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - fixed a problem with new versions of the file command
John Dennis 38f226
#
John Dennis 38f226
# v1.0.4
John Dennis 38f226
# - added GPL license
John Dennis 38f226
#
John Dennis 38f226
# v1.0.5, May 02 2003 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - modified exec path
John Dennis 38f226
#
John Dennis 38f226
# v1.0.6, Jul 18 2003 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - changed db3 to berkeley
John Dennis 38f226
# - added new db backends for 2.2
John Dennis 38f226
#
John Dennis 38f226
# v1.0.7, Jan 23 2004 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - included some modifications from Luca Olivetti <luca@olivetti.cjb.net>
John Dennis 38f226
# - added masssievec functionality
John Dennis 38f226
#
John Dennis 38f226
# v1.0.8, Jan 28 2004 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - convert sieve scripts to UTF-8 before calling masssievec
John Dennis 38f226
#
John Dennis 38f226
# v1.0.9, Jan 29 2004 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - convert sieve scripts to UTF-8 only if sievec failed before
John Dennis 38f226
#
John Dennis 38f226
# v1.0.10, Feb 24 2004 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - change su within init script to get input from
John Dennis 38f226
#   /dev/null, this prevents hang when running in SELinux
John Dennis 38f226
#
John Dennis 38f226
# v1.0.11, Mar 02 2004 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - fixed SELinux fix
John Dennis 38f226
#
John Dennis 38f226
# v1.0.12, Dec 16 2004 Simon Matter <simon.matter@invoca.ch>
John Dennis 38f226
# - use runuser instead of su if available
John Dennis 9e566a
#
John Dennis 9e566a
# v1.0.13, Jul 15 2005 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - don't use flat in the two step conversion, use skiplist instead
John Dennis 9e566a
#
John Dennis 9e566a
# v1.0.14, Jul 18 2005 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - replace the order of the magic files in the file call to make
John Dennis 9e566a
#   sure skiplist is detected correctly.
John Dennis 9e566a
#
John Dennis 9e566a
# v1.0.15, Aug 17 2005 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - add functionality to export all berkeley db files to skiplist
John Dennis 9e566a
#
John Dennis 9e566a
# v1.1.0, Aug 18 2005 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - fix export functionality, try to recover Berkeley databases
John Dennis 9e566a
#   as much as possible before any conversion.
John Dennis 9e566a
#
John Dennis 9e566a
# v1.1.1, Dec 05 2005 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - run db_checkpoint in background with a timeout to prevent
John Dennis 9e566a
#   that cyrus-imapd doesn't start at all if it hangs.
John Dennis 9e566a
#
John Dennis 9e566a
# v1.1.2, Dec 06 2005 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - make handling of db_checkpoint more robust
John Dennis 9e566a
#
John Dennis 9e566a
# v1.2.0, Jan 12 2006 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - adopt for cyrus-imapd-2.3
John Dennis 9e566a
#
John Dennis 9e566a
# v1.2.1, Jan 13 2006 Simon Matter <simon.matter@invoca.ch>
John Dennis 9e566a
# - code cleanup
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.2.2, Nov 29 2007 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - add ability to handle "@include" options in imapd.conf, patch
Michal Hlavinka 9d65fa
#   provided by Tim Bannister
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.2.3, Feb 07 2008 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - add ability to handle tabs in imapd.conf, patch provided
Michal Hlavinka 9d65fa
#   by Franz Knipp
Michal Hlavinka 9d65fa
# - disable default values for some config options like sievedir
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.2.4, Apr 23 2008 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - add support for statuscache.db
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.3.0, Sep 29 2008 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - add multi-instance support
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.3.1, Oct 09 2008 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - improve variable handling
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.3.2, May 26 2009 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - add some sanity checks to multi-instance support
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.3.3, May 27 2009 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - make some cosmetic changes
Michal Hlavinka 9d65fa
#
Michal Hlavinka 9d65fa
# v1.3.4, Dec 22 2009 Simon Matter <simon.matter@invoca.ch>
Michal Hlavinka 9d65fa
# - add support for user_deny.db
John Dennis 9e566a
Michal Hlavinka 9d65fa
VERSION=1.3.4
John Dennis 38f226
Michal Hlavinka 9d65fa
PIDFILE=/var/run/cyrus-master${INSTANCE}.pid
Michal Hlavinka 9d65fa
Michal Hlavinka 9d65fa
# instance config
Michal Hlavinka 9d65fa
CYRUSCONF=/etc/cyrus${INSTANCE}.conf
Michal Hlavinka 9d65fa
IMAPDCONF=/etc/imapd${INSTANCE}.conf
Michal Hlavinka 9d65fa
Michal Hlavinka 9d65fa
# make sure what we have is a valid instance
Michal Hlavinka 9d65fa
# and that config files are present
Michal Hlavinka 9d65fa
if [ -n "$INSTANCE" ]; then
Michal Hlavinka 9d65fa
  [ -L /etc/rc.d/init.d/${BASENAME} ] || exit 0
Michal Hlavinka 9d65fa
fi
Michal Hlavinka 9d65fa
[ -f $CYRUSCONF ] || exit 0
Michal Hlavinka 9d65fa
[ -f $IMAPDCONF ] || exit 0
Michal Hlavinka 9d65fa
Michal Hlavinka 9d65fa
if [ -f $PIDFILE ]; then
Michal Hlavinka 9d65fa
  read CYRUS_PID < $PIDFILE
Michal Hlavinka 9d65fa
  if [ -n "$CYRUS_PID" ]; then
Michal Hlavinka 9d65fa
    if ps -p $CYRUS_PID > /dev/null 2>&1; then
Michal Hlavinka 9d65fa
      echo "ERROR: cyrus-master is running, unable to convert mailboxes!"
Michal Hlavinka 9d65fa
      exit 1
Michal Hlavinka 9d65fa
    fi
Michal Hlavinka 9d65fa
  fi
John Dennis 38f226
fi
John Dennis 38f226
Michal Hlavinka 9d65fa
if [ ! -f $IMAPDCONF ]; then
Michal Hlavinka 9d65fa
  echo "ERROR: configuration file '${IMAPDCONF}' not found, exiting!"
John Dennis 38f226
  exit 1
John Dennis 38f226
fi
John Dennis 38f226
John Dennis 38f226
# fallback to su if runuser not available
John Dennis 38f226
if [ -x /sbin/runuser ]; then
John Dennis 38f226
  RUNUSER=runuser
John Dennis 38f226
else
John Dennis 38f226
  RUNUSER=su
John Dennis 38f226
fi
John Dennis 38f226
John Dennis 38f226
# force cyrus user for security reasons
John Dennis 38f226
if [ ! $(whoami) = "cyrus" ]; then
Michal Hlavinka 9d65fa
  exec $RUNUSER - cyrus -c "cd $PWD < /dev/null ; INSTANCE=$INSTANCE $0 $*"
John Dennis 38f226
fi
John Dennis 38f226
John Dennis 9e566a
# special function for migration
John Dennis 9e566a
EXPORT=$1
John Dennis 9e566a
John Dennis 38f226
# files get mode 0600
John Dennis 38f226
umask 166
John Dennis 38f226
John Dennis 9e566a
# show version info in log files
John Dennis 9e566a
echo "cvt_cyrusdb_all version: $VERSION"
John Dennis 9e566a
Michal Hlavinka 9d65fa
# expand_config <path>
Michal Hlavinka 9d65fa
# handle "@include" sections from imapd style config file
Michal Hlavinka 9d65fa
expand_config() {
Michal Hlavinka 9d65fa
  while read line; do
Michal Hlavinka 9d65fa
    if printf "%s\n" "${line}" | grep -q '^@include:'; then
Michal Hlavinka 9d65fa
      expand_config "$( printf "%s\n" "${line}" | cut -d : -f 2- | sed -e 's/^[\t ]*//' )"
Michal Hlavinka 9d65fa
    else
Michal Hlavinka 9d65fa
      printf "%s\n" "${line}"
Michal Hlavinka 9d65fa
    fi
Michal Hlavinka 9d65fa
  done < $1
Michal Hlavinka 9d65fa
}
Michal Hlavinka 9d65fa
Michal Hlavinka 9d65fa
# get_config <config> [<default>]
John Dennis 38f226
# extracts config option from config file
John Dennis 38f226
get_config() {
Michal Hlavinka 9d65fa
  searchstr=$1
Michal Hlavinka 9d65fa
  if config="$(expand_config $IMAPDCONF | egrep "^${searchstr}:")"; then
Michal Hlavinka 9d65fa
    CFGVAL="$(printf "%s\n" "$config" | cut -d : -f 2- | sed -e 's/^[\t ]*//')"
John Dennis 38f226
  else
Michal Hlavinka 9d65fa
    if [ -z "$2" ]; then
Michal Hlavinka 9d65fa
      echo "ERROR: config option '$1' not found in ${IMAPDCONF}, exiting!" 1>&2
Michal Hlavinka 9d65fa
      return 1
Michal Hlavinka 9d65fa
    fi
Michal Hlavinka 9d65fa
    CFGVAL="$2"
John Dennis 38f226
  fi
Michal Hlavinka 9d65fa
  echo "get_config ${1}: $CFGVAL" 1>&2
Michal Hlavinka 9d65fa
  echo "$CFGVAL"
John Dennis 38f226
}
John Dennis 38f226
John Dennis 38f226
# where to find files and directories
John Dennis 9e566a
data_dir=/usr/share/cyrus-imapd/rpm
John Dennis 9e566a
lib_dir=/usr/lib/cyrus-imapd
John Dennis 38f226
system_magic=$(file --version | awk '/magic file/ {print $4}')
John Dennis 9e566a
cyrus_magic=${data_dir}/magic
John Dennis 9e566a
cvt_cyrusdb=${lib_dir}/cvt_cyrusdb
John Dennis 9e566a
sievec=${lib_dir}/sievec
John Dennis 9e566a
masssievec=${lib_dir}/masssievec
Michal Hlavinka 9d65fa
imap_prefix=$(get_config configdirectory) || exit 1
Michal Hlavinka 9d65fa
sieve_dir=$(get_config sievedir) || exit 1
John Dennis 9e566a
db_cfg=${data_dir}/db.cfg
John Dennis 38f226
db_current=${imap_prefix}/rpm/db.cfg.current
John Dennis 38f226
db_cache=${imap_prefix}/rpm/db.cfg.cache
John Dennis 38f226
John Dennis 38f226
# source default db backend config
John Dennis 38f226
. $db_cfg
John Dennis 38f226
John Dennis 38f226
# get configured db backend config
Michal Hlavinka 9d65fa
duplicate_db=$(get_config duplicate_db $duplicate_db) || exit 1
Michal Hlavinka 9d65fa
mboxlist_db=$(get_config mboxlist_db $mboxlist_db) || exit 1
Michal Hlavinka 9d65fa
seenstate_db=$(get_config seenstate_db $seenstate_db) || exit 1
Michal Hlavinka 9d65fa
subscription_db=$(get_config subscription_db $subscription_db) || exit 1
Michal Hlavinka 9d65fa
tlscache_db=$(get_config tlscache_db $tlscache_db) || exit 1
Michal Hlavinka 9d65fa
annotation_db=$(get_config annotation_db $annotation_db) || exit 1
Michal Hlavinka 9d65fa
mboxkey_db=$(get_config mboxkey_db $mboxkey_db) || exit 1
Michal Hlavinka 9d65fa
ptscache_db=$(get_config ptscache_db $ptscache_db) || exit 1
Michal Hlavinka 9d65fa
quota_db=$(get_config quota_db $quota_db) || exit 1
Michal Hlavinka 9d65fa
statuscache_db=$(get_config statuscache_db $statuscache_db) || exit 1
Michal Hlavinka 9d65fa
userdeny_db=$(get_config userdeny_db $userdeny_db) || exit 1
John Dennis 38f226
John Dennis 38f226
# remember current db backend config
John Dennis 38f226
{
Michal Hlavinka 9d65fa
echo "duplicate_db=${duplicate_db}"
Michal Hlavinka 9d65fa
echo "mboxlist_db=${mboxlist_db}"
Michal Hlavinka 9d65fa
echo "seenstate_db=${seenstate_db}"
Michal Hlavinka 9d65fa
echo "subscription_db=${subscription_db}"
Michal Hlavinka 9d65fa
echo "tlscache_db=${tlscache_db}"
Michal Hlavinka 9d65fa
echo "annotation_db=${annotation_db}"
Michal Hlavinka 9d65fa
echo "mboxkey_db=${mboxkey_db}"
Michal Hlavinka 9d65fa
echo "ptscache_db=${ptscache_db}"
Michal Hlavinka 9d65fa
echo "quota_db=${quota_db}"
Michal Hlavinka 9d65fa
echo "statuscache_db=${statuscache_db}"
Michal Hlavinka 9d65fa
echo "userdeny_db=${userdeny_db}"
Michal Hlavinka 9d65fa
echo "sieve_version=${sieve_version}"
John Dennis 9e566a
} | sort > $db_current
John Dennis 38f226
Michal Hlavinka 9d65fa
# file_type <file>
John Dennis 38f226
file_type() {
Michal Hlavinka 9d65fa
  this_type=$(file -b -m "${cyrus_magic}:${system_magic}" "$1" 2> /dev/null)
John Dennis 38f226
  if echo "$this_type" | grep -qi skip > /dev/null 2>&1; then
John Dennis 38f226
    echo skiplist
John Dennis 38f226
  elif echo "$this_type" | grep -qi text > /dev/null 2>&1; then
John Dennis 38f226
    echo flat
John Dennis 38f226
  else
John Dennis 38f226
    echo berkeley
John Dennis 38f226
  fi
John Dennis 38f226
}
John Dennis 38f226
Michal Hlavinka 9d65fa
# cvt_file <file> <db>
John Dennis 38f226
cvt_file() {
John Dennis 38f226
  target="$1"
John Dennis 38f226
  new_db="$2"
John Dennis 38f226
  if [ -s "$target" ]; then
John Dennis 38f226
    old_db=$(file_type "$target")
John Dennis 38f226
    if [ ! "$old_db" = "$new_db" ]; then
John Dennis 38f226
      # The two-step conversion is paranoia against the filenames being encoded
John Dennis 38f226
      # inside the database or logfiles (berkeley does this, for example).
John Dennis 9e566a
      rm -f "${target}.skiplist"
John Dennis 9e566a
      if [ "$old_db" = "skiplist" ]; then
John Dennis 9e566a
        cp -a "$target" "${target}.skiplist"
John Dennis 38f226
      else
Michal Hlavinka 9d65fa
        $cvt_cyrusdb -C $IMAPDCONF "$target" "$old_db" "${target}.skiplist" skiplist
John Dennis 38f226
      fi
John Dennis 38f226
      RETVAL=$?
Michal Hlavinka 9d65fa
      ERRVAL=$(( $ERRVAL + $RETVAL ))
John Dennis 38f226
      if [ $RETVAL -eq 0 ]; then
John Dennis 38f226
        rm -f "$target"
John Dennis 9e566a
        if [ -s "${target}.skiplist" ]; then
John Dennis 9e566a
          if [ "$new_db" = "skiplist" ]; then
John Dennis 9e566a
            cp -a "${target}.skiplist" "$target"
John Dennis 38f226
          else
Michal Hlavinka 9d65fa
            $cvt_cyrusdb -C $IMAPDCONF "${target}.skiplist" skiplist "$target" "$new_db"
John Dennis 38f226
          fi
John Dennis 38f226
        fi
John Dennis 38f226
        RETVAL=$?
Michal Hlavinka 9d65fa
        ERRVAL=$(( $ERRVAL + $RETVAL ))
John Dennis 38f226
        if [ $RETVAL -eq 0 ]; then
John Dennis 9e566a
          rm -f "${target}.skiplist"
John Dennis 38f226
        else
John Dennis 9e566a
          echo "ERROR: unable to convert ${target}.skiplist from skiplist to $new_db"
John Dennis 38f226
        fi
John Dennis 38f226
      else
John Dennis 9e566a
        echo "ERROR: unable to convert $target from $old_db to skiplist"
John Dennis 38f226
      fi
John Dennis 38f226
    fi
John Dennis 38f226
  fi
John Dennis 38f226
}
John Dennis 38f226
Michal Hlavinka 9d65fa
# cvt_to_utf8 <file>
John Dennis 38f226
cvt_to_utf8() {
John Dennis 38f226
  target="$1"
John Dennis 38f226
  if [ -s "$target" ]; then
Michal Hlavinka 9d65fa
    if ! $sievec -C $IMAPDCONF "$target" "${target}.sievec"; then
John Dennis 38f226
      iconv --from-code=ISO-8859-1 --to-code=UTF-8 --output="${target}.UTF-8" "$target"
John Dennis 38f226
      if [ -s "${target}.UTF-8" ]; then
John Dennis 38f226
        # preserve timestamp
Michal Hlavinka 9d65fa
        touch --reference="${target}" "${target}.UTF-8"
John Dennis 38f226
        mv -f "${target}.UTF-8" "$target"
John Dennis 38f226
      else
Michal Hlavinka 9d65fa
        ERRVAL=$(( $ERRVAL + 1 ))
John Dennis 38f226
      fi
John Dennis 38f226
    fi
John Dennis 38f226
    rm -f "${target}.sievec"
John Dennis 38f226
  fi
John Dennis 38f226
}
John Dennis 38f226
John Dennis 38f226
ERRVAL=0
John Dennis 38f226
John Dennis 9e566a
# make sure our Berkeley databases are in a sane state
John Dennis 9e566a
# wait for db_checkpoint to end successfully or kill it after a timeout
Michal Hlavinka 9d65fa
db_checkpoint -v -1 -h ${imap_prefix}/db &
John Dennis 9e566a
DB_CHECK_PID=$!
John Dennis 9e566a
CNT=0
John Dennis 9e566a
while [ $CNT -lt 60 ]; do
John Dennis 9e566a
  if ! kill -0 $DB_CHECK_PID > /dev/null 2>&1; then
John Dennis 9e566a
    break
John Dennis 9e566a
  fi
John Dennis 9e566a
  sleep 1
John Dennis 9e566a
  let CNT+=1
John Dennis 9e566a
done
John Dennis 9e566a
if kill -0 $DB_CHECK_PID > /dev/null 2>&1; then
John Dennis 9e566a
  kill -USR1 $DB_CHECK_PID > /dev/null 2>&1
John Dennis 9e566a
  sleep 1
John Dennis 9e566a
  kill -KILL $DB_CHECK_PID > /dev/null 2>&1
John Dennis 9e566a
  wait $DB_CHECK_PID > /dev/null 2>&1
John Dennis 9e566a
fi
John Dennis 9e566a
John Dennis 9e566a
# do a normal recovery
Michal Hlavinka 9d65fa
db_recover -v -h ${imap_prefix}/db
John Dennis 9e566a
RETVAL=$?
John Dennis 9e566a
if [ $RETVAL -ne 0 ]; then
John Dennis 9e566a
  # try a catastrophic recovery instead of normal recovery
Michal Hlavinka 9d65fa
  db_recover -v -c -h ${imap_prefix}/db
John Dennis 9e566a
  RETVAL=$?
Michal Hlavinka 9d65fa
  ERRVAL=$(( $ERRVAL + $RETVAL ))
John Dennis 9e566a
  if [ $RETVAL -ne 0 ]; then
John Dennis 9e566a
    echo "ERROR: catastrophic recovery of Berkeley databases failed"
John Dennis 9e566a
  fi
John Dennis 9e566a
fi
John Dennis 9e566a
John Dennis 9e566a
if [ "$EXPORT" = "export" ]; then
Michal Hlavinka 9d65fa
  # convert all db files to portable format for migration
John Dennis 9e566a
  # TODO: quota_db, we don't touch it for now
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/deliver.db           "skiplist"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/mailboxes.db         "skiplist"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/tls_sessions.db      "skiplist"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/annotations.db       "skiplist"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/ptclient/ptscache.db "skiplist"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/statuscache.db       "skiplist"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/user_deny.db         "flat"
Michal Hlavinka 9d65fa
  rm -vf ${imap_prefix}/db/log.*
Michal Hlavinka 9d65fa
  rm -vf ${imap_prefix}/db/__db.*
John Dennis 9e566a
else
John Dennis 9e566a
  # always convert db files which have been converted to skiplist
John Dennis 9e566a
  # TODO: quota_db, we don't touch it for now
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/deliver.db           "$duplicate_db"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/mailboxes.db         "$mboxlist_db"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/tls_sessions.db      "$tlscache_db"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/annotations.db       "$annotation_db"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/ptclient/ptscache.db "$ptscache_db"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/statuscache.db       "$statuscache_db"
Michal Hlavinka 9d65fa
  cvt_file ${imap_prefix}/user_deny.db         "$userdeny_db"
John Dennis 9e566a
  # do we have to convert all databases?
John Dennis 9e566a
  if ! cmp -s $db_current $db_cache; then
John Dennis 9e566a
    # we treat sieve scripts the same way like db files
John Dennis 9e566a
    find ${sieve_dir}/ -name "*.script" -type f | while read db_file trash; do
John Dennis 9e566a
      cvt_to_utf8 "$db_file"
John Dennis 9e566a
    done
Michal Hlavinka 9d65fa
    $masssievec $sievec $IMAPDCONF
John Dennis 9e566a
    # convert all db files left
John Dennis 9e566a
    find ${imap_prefix}/user/ -name "*.seen" -type f | while read db_file trash; do
John Dennis 9e566a
      cvt_file "$db_file" "$seenstate_db"
John Dennis 9e566a
    done
John Dennis 9e566a
    find ${imap_prefix}/user/ -name "*.sub" -type f | while read db_file trash; do
John Dennis 9e566a
      cvt_file "$db_file" "$subscription_db"
John Dennis 9e566a
    done
John Dennis 9e566a
    find ${imap_prefix}/user/ -name "*.mboxkey" -type f | while read db_file trash; do
John Dennis 9e566a
      cvt_file "$db_file" "$mboxkey_db"
John Dennis 9e566a
    done
John Dennis 9e566a
  fi
John Dennis 38f226
fi
John Dennis 38f226
John Dennis 9e566a
# update the config cache file so we can check whether something has changed
John Dennis 38f226
if [ $ERRVAL -eq 0 ]; then
John Dennis 38f226
  mv -f $db_current $db_cache
John Dennis 38f226
else
John Dennis 38f226
  rm -f $db_cache
John Dennis 38f226
  rm -f $db_current
John Dennis 38f226
fi
John Dennis 38f226
John Dennis 38f226
exit $ERRVAL