+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
+}
+