[Logcheck-devel] Bug#542265: sendmail-base and logcheck-database: error when trying to install together
Frédéric Brière
fbriere at fbriere.net
Mon Aug 24 00:52:09 UTC 2009
Here's the commit I made to allow removing conffiles in the future.
(Specific filenames were added in later commits.) It's rather
straightforward (mostly copied from the Debian wiki), but I wouldn't
mind peer review just in case I screwed up.
As mentioned in the description, I decided to eschew the whole version
comparison bit. Unlike most packages, we're likely to drop many more
conffiles in the future, and I wanted to come up with an easy solution
that would not result in a dozen of if/then blocks, or figuring out
which version to check for every time.
When you remove a rule files, all you have to do is remember to add it
to the list. That's it!
commit 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.)
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)
--
* liw prefers not to have Linus run Debian, because then /me would
have to run Red Hat, just to keep the power balance :)
-- #Debian
More information about the Logcheck-devel
mailing list