Discussion:
How to safely drop a dpkg-divert
Add Reply
Soren Stoutner
2025-01-16 22:00:01 UTC
Reply
Permalink
I am in the process of salvaging courier. In doing so, I discovered the
package was using dpkg-divert. In discussion with upstream, I found a
solution that doesn’t require dpkg-divert.

https://github.com/svarshavchik/courier/issues/56

My question now is how to safely drop the diversion. Currently courier-
mta.preinst includes:

if [ "$1" = "install" ]; then
dpkg-divert --package courier-mta --add --rename \
--divert /usr/bin/addcr.ucspi-tcp /usr/bin/addcr
dpkg-divert --package courier-mta --add --rename \
--divert /usr/share/man/man1/addcr.ucspi-tcp.1.gz /usr/
share/man/man1/addcr.1.gz
fi

https://salsa.debian.org/debian/courier/-/blob/master/debian/courier-mta.preinst?ref_type=heads

And ourier-mta.postrm includes:

if [ "$1" = "remove" ]; then
dpkg-divert --package courier-mta --remove --rename \
--divert /usr/bin/addcr.ucspi-tcp /usr/bin/addcr
dpkg-divert --package courier-mta --remove --rename \
--divert /usr/share/man/man1/addcr.ucspi-tcp.1.gz /usr/
share/man/man1/addcr.1.gz
fi

https://salsa.debian.org/debian/courier/-/blob/master/debian/courier-mta.postrm?ref_type=heads

Removing the preinst is easy so that the diversion doesn’t happen on new
installs, but my question is how to correctly handle the postrm so that the
diversion is removed from current installs on upgrade.
--
Soren Stoutner
***@debian.org
Lorenzo
2025-01-17 09:10:01 UTC
Reply
Permalink
Hi!

On Thu, 16 Jan 2025 14:57:29 -0700
Removing the preinst is easy so that the diversion doesn’t happen on
new installs, but my question is how to correctly handle the postrm
so that the diversion is removed from current installs on upgrade.
Upgrade is available in preinstall and postinstall [1] so it needs to be
one of the two, not sure which one is better, (maybe preinstall? but if
it fails it goes back the the old version, see dpkg chart)

I'm not sure, but I would try something like

if [ "$1" = "upgrade" ]; then
#test if the diversion is installed and then remove it
fi

to test if the diversion is installed you can probably use

dpkg-divert --list | grep courier-mta

or use package versions provided by dpkg to maintscripts

if dpkg --compare-versions "$2" le-nl "1.3.13-1"; then

Lorenzo

[1]https://www.debian.org/doc/debian-policy/ap-flowcharts.html
Lorenzo
2025-01-17 09:20:01 UTC
Reply
Permalink
Post by Lorenzo
Upgrade is available in preinstall and postinstall [1] so it needs to
be one of the two, not sure which one is better, (maybe preinstall?
but if it fails it goes back the the old version, see dpkg chart)
thinking a bit more, it needs to be postinstall
Soren Stoutner
2025-01-17 22:40:02 UTC
Reply
Permalink
Lorenzo,
Post by Lorenzo
Upgrade is available in preinstall and postinstall [1] so it needs to be
one of the two, not sure which one is better, (maybe preinstall? but if
it fails it goes back the the old version, see dpkg chart)
I'm not sure, but I would try something like
if [ "$1" = "upgrade" ]; then
#test if the diversion is installed and then remove it
fi
to test if the diversion is installed you can probably use
dpkg-divert --list | grep courier-mta
Thanks for the pointer. I have added the following code:

# Delete the old diversions if they exist, which are no longer needed.
# These commands can be removed in trixie +1.
# See <https://github.com/svarshavchik/courier/issues/56>
# See also <https://lists.debian.org/debian-mentors/2025/01/msg00219.html>
if [ dpkg-divert --list | grep courier-mta ]; then
dpkg-divert --package courier-mta --remove --rename \
--divert /usr/bin/addcr.ucspi-tcp /usr/bin/addcr
dpkg-divert --package courier-mta --remove --rename \
--divert /usr/share/man/man1/addcr.ucspi-tcp.1.gz /usr/share/man/man1/addcr.1.gz
fi
https://salsa.debian.org/debian/courier/-/blob/master/debian/courier-mta.postinst?
ref_type=heads#L19
--
Soren Stoutner
***@debian.org
Loading...