From 6a3a2c168191ec411b938cc271535e692003dc2c Mon Sep 17 00:00:00 2001 From: Valentin Vidic Date: Fri, 7 Mar 2008 13:41:30 +0100 Subject: [PATCH] Preserve dovecot mailbox config over upgrade. --- src/actions/main.queue | 1 + src/functions.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/actions/main.queue b/src/actions/main.queue index 816024d..e2fe134 100644 --- a/src/actions/main.queue +++ b/src/actions/main.queue @@ -25,6 +25,7 @@ true restore_configs # konacno, instalacija novih paketa pkg amavisd-cn upgrade_amavis pkg apache-cn upgrade_apache +pkg dovecot-cn upgrade_dovecot pkg postfix-cn pkgadd postfix-cn pkg postgrey pkgrm postgrey # problematican pkg openldap-aai upgrade_openldap diff --git a/src/functions.sh b/src/functions.sh index f68c54b..7b9eae4 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -487,7 +487,6 @@ restore_config () { restore_configs () { pkg base-files lt 4 && restore_config /etc/issue /etc/issue.net pkg bind9 lt 1:9.3.4 && restore_config /etc/bind/named.conf.options - pkg dovecot-common lt 1.0 && restore_config /etc/dovecot/dovecot.conf pkg libpam-modules lt 0.79 && restore_config /etc/security/limits.conf pkg login lt 1:4.0.18.1 && restore_config /etc/pam.d/login pkg mysql-server lt 5.0.3 && restore_config /etc/init.d/mysql \ @@ -654,6 +653,50 @@ upgrade_openldap () { dpkg --configure -a # try postinst again } +get_variable () { + name=$1 + file=$2 + + if [ -f "$file" ]; then + val=$(sed -n "/^[[:space:]]*$name[[:space:]]*=/s/[[:space:]]*//gp" $file) + val=${val#*=} + fi + + echo $val +} + +# preserve mail location on upgrade +upgrade_dovecot () { + local default_mail_env mail_location + + # check if already upgraded + if ! pkg dovecot-common lt 1.0; then + return + fi + + # save old mail location + default_mail_env=$(get_variable default_mail_env /etc/dovecot/dovecot.conf) + + # silently upgrade package + restore_config /etc/dovecot/dovecot.conf + pkgadd dovecot-cn + + # insert old mail location + mail_location=$(get_variable mail_location /etc/dovecot/dovecot.conf) + if [ "$default_mail_env" -a ! "$mail_location" ]; then + check_and_sed '^#mail_location[[:space:]]*=' \ + "s|#mail_location[[:space:]]*=.*|mail_location = $default_mail_env|" /etc/dovecot/dovecot.conf || return 0 + + if [ -x /etc/init.d/dovecot ]; then + if [ -x /usr/sbin/invoke-rc.d ]; then + /usr/sbin/invoke-rc.d dovecot restart + else + /etc/init.d/dovecot restart + fi + fi + fi +} + # fix /etc/dpkg/dpkg.cfg comment_force_overwrite () { if [ -f /etc/dpkg/dpkg.cfg ]; then -- 1.7.10.4