+ dpkg --configure -a
+
+ # remove ldap user if openldap works
+ if getent passwd ldap > /dev/null && \
+ getent passwd openldap > /dev/null && \
+ pgrep -U openldap slapd > /dev/null
+ then
+ log "userdel ldap (replaced by openldap)"
+ userdel ldap || true
+ fi
+}
+
+# fix postgresql deinstallation during upgrade
+upgrade_postgresql () {
+ if check_services show 2>&1 | grep -qw postgresql; then
+ apt-get install -y postgresql || apt-get -yf install
+ fi
+}
+
+# upgrade the MTA
+upgrade_postfix () {
+ pkgadd postfix-cn
+
+ if pkg postgrey; then
+ pkgrm postgrey # not used by postfix-cn anymore
+ fi
+}
+
+get_variable () {
+ local name=$1 file=$2 val
+
+ 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 dovecot-cn dovecot-common 1.0 /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
+}
+
+# restore munin configs for silent upgrade
+upgrade_munin () {
+ local config backup hostname domain
+
+ for pkg_name in munin munin-node; do
+ pkg $pkg_name lt '1.2.6-10~lenny1' || continue
+
+ config=/etc/munin/$pkg_name.conf
+ backup=$config.$backup_ext
+ if [ -f $config -a ! -f $backup ]; then
+ hostname=$(hostname)
+ domain=$(hostname --domain)
+
+ cp -av $config $backup
+ check_and_sed "$hostname.$domain" \
+ "s/$hostname.$domain/localhost.localdomain/g" $config
+ fi
+ pkgadd $pkg_name
+ done
+
+ # force localhost -> hostname replacement in config files
+ pkgadd munin-cn
+ dpkg-reconfigure munin-cn