[Logcheck-commits] Frédéric Brière : Adding support for removing conffiles in logcheck-database's preinst

Frédéric Brière fbriere-guest at alioth.debian.org
Mon Aug 24 00:28:41 UTC 2009


Module: logcheck
Branch: master
Commit: 1299e472ce3f8cf26fa60c87ce0c5d541106e0ef
URL:    http://git.debian.org/?p=logcheck/logcheck.git;a=commit;h=1299e472ce3f8cf26fa60c87ce0c5d541106e0ef

Author: Frédéric Brière <fbriere at fbriere.net>
Date:   Sun Aug 23 15:48:25 2009 -0400

Adding support for removing conffiles in logcheck-database's preinst

This basically copies rm_conffile() from the Debian wiki, to deal with
the fact that dpkg does not delete conffiles after they have been
removed from a package.

This version of rm_conffile() makes sure that the conffile still belongs
to our package, since it is possible for it to have migrated to another
package through a Replaces relationship.  (See bug #532484 for an
example.)

Thanks to this check, we can also avoid bothering with version
comparisions; calling rm_conffile() on subsequent upgrades will simply
do nothing.  (Of course, we still avoid calling it uselessly on fresh
installs.)

---

 debian/logcheck-database.preinst |   40 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/debian/logcheck-database.preinst b/debian/logcheck-database.preinst
index 3ff092e..c2d6589 100644
--- a/debian/logcheck-database.preinst
+++ b/debian/logcheck-database.preinst
@@ -14,8 +14,48 @@ set -e
 # the debian-policy package
 
 
+# List of conffiles which have been removed from this package.  These will be
+# deleted (or backed away) at the next upgrade.
+#
+# Conffiles must be listed here from the very moment of their removal; adding
+# them later on will not work correctly.
+
+REMOVED_CONFFILES=""
+
+
+# Copied from <http://wiki.debian.org/DpkgConffileHandling>
+rm_conffile() {
+    local PKGNAME="$1"
+    local CONFFILE="$2"
+
+    [ -e "$CONFFILE" ] || return 0
+
+    # Do nothing if that file no longer belongs to us
+    dpkg-query --listfiles "$PKGNAME" | grep -q "^$CONFFILE$" || return 0
+
+    local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')"
+    local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PKGNAME | \
+            sed -n -e "\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
+    if [ "$md5sum" != "$old_md5sum" ]; then
+        echo "Obsolete conffile $CONFFILE has been modified by you."
+        echo "Saving as $CONFFILE.dpkg-bak ..."
+        mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
+    else
+        echo "Removing obsolete conffile $CONFFILE ..."
+        rm -f "$CONFFILE"
+    fi
+}
+
+
 case "$1" in
     install|upgrade)
+        # Remove $REMOVED_CONFFILES on upgrade, or when re-installing
+        # after the package was removed (but not purged).
+        if [ "$2" ]; then
+            for CONFFILE in $REMOVED_CONFFILES; do
+                rm_conffile logcheck-database "$CONFFILE"
+            done
+        fi
     ;;
 
     abort-upgrade)




More information about the Logcheck-commits mailing list