[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to safely drop a dpkg-divert



Am Mon, Jan 20, 2025 at 02:58:21PM -0700, schrieb Soren Stoutner:
>     if [[ `dpkg-divert --list courier-mta` ]]; then

[[ is a bashism (see checkbashisms from devscripts), so I wonder a bit
how that worked for you in testing and why lintian and co haven't
screamed at you.

You can see the call fail e.g. in piuparts:
https://piuparts.debian.org/sid/pass/courier-mta_1.3.13-4.log
| /var/lib/dpkg/info/courier-mta.postinst: 23: [[: not found

(It doesn't fail the script, as using an unknown binary like
 this is technically the same as writing `if false; then`)


You can write this line in (da)sh compatible way e.g. so:

|     if [ -n "$(dpkg-divert --list courier-mta)" ]; then

(Realising that [ is not syntax but an actual command name
 might help in understanding why [[ is not bad syntax either)


> One of the advantages of using this check instead of a package version number 
> is that it can be tested on a machine by manually creating diversions and then 
> running the script to see if it removes them, which is how I caught the 
> problem.

Well, given a version check is done via parameter $2 to the maintainer
script (see d-policy) I suppose testing this is equally hard… as it is
mostly about how you call it (did you call it with
   bash courier-mta.postinst configure 1.3.13-4
perhaps?) correctly and in the same way it would be called in various
situations by dpkg which is the non-trivial part that e.g. piuparts
is supposed to help you with by testing various scenarios.


Best regards

David Kalnischkies

Attachment: signature.asc
Description: PGP signature


Reply to: