• Re: How to safely drop a dpkg-divert

    From David Kalnischkies@21:1/5 to All on Sat Jan 18 16:50:01 2025
    Hi,

    Am Fri, Jan 17, 2025 at 03:29:39PM -0700, schrieb Soren Stoutner:
    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

    The presented alternative was using a version check. I get it, it looks
    a bit more complex and you need to know the version number, but the
    benefit of the version check is that it is easy to proof that it runs
    once in the upgrade and then never again (if you pick the right number).

    By comparison, the grep-based solution is hoping that no translation, no package name and no path name now and up to the point you remove that
    code happens to contain the string you grep for.

    Sure, "courier-mta" seems like a string unlikely to appear, but can you
    be sure?


    Random example, but if we ever end up merging /usr/sbin with /usr/bin
    and the long tail turns out to be as messy as /bin with /usr/bin
    this long forgotten and done with upgrade stanza becomes suddenly very
    relevant again as courier-mta will once again appear in dpkg-divert.


    Best regards

    David Kalnischkies

    P.S.: Your grep, if it triggers, also generates output on stdout.
    At least silence it with -q.

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEE5sn+Q4uCja/tn0GrMRvlz3HQeIMFAmeLy5gACgkQMRvlz3HQ eIO8Fw//d6wF0aufT/6PG3EprFNfjBaQSozbfBjgd3zbHaV49Vlz04A5VPZ2vggP QP5uX04Dq9CgdPgf9vObS9s432ouZogVRUscLfPj4V0LxzP9vcm0iA5NKuPjrDov NH/9YHSyjcxDMKRF9n61lM9IgyGjpuHn7dramUz8kpP+PAbxNKaA5vyB0n/lrs1i ghfeH2xdZOk82nNUzt8sv2EcD1xT3ylfO0sN7o14L/drJhAqf6+6vDCu2rRDCkNU d7odx6+XnHsEljMk79jYG+R0Hp0ftFQwXINIbBXbICzn6br1PZyunO6VY4GJpSJY CZ6YPuUw5WtcCf+fFWTAF8vqpAWiHYXsUa12yNSgSznS7dKnNQ0BKocAQMuW48OP KCElYj6U1UcENWil669jg6hLMHQr8NIMsat2xLyOWTajALjZEY37QgERB00xM2xC lAoTaEctghm9HNlD+mfcJcNnj12hw/rrFnNOq0UOo60HvlW8Qcy+nrismzAF7pgT fQyWhigMdXaEAWZ7qlBrDybocGjvo7XDD+iHFJfyQ/iY2BCEy9CMXqSbh+2f/APe 1Gi6klKGLDgyMoYa8cQSYvZdubRUXthOpg6sJbP2RcCbR+2b0fuqWe+J+QBQ4HNl svE6rLSwVJoqE7UJ0UqqRLayAYlLrN07w8T6qYqj62woJN4OTsg=
    =Bxlk
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to Debian Mentors on Sat Jan 18 11:54:53 2025
    On Saturday, January 18, 2025 8:41:18 AM MST David Kalnischkies wrote:
    Hi,

    Am Fri, Jan 17, 2025 at 03:29:39PM -0700, schrieb Soren Stoutner:
    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

    The presented alternative was using a version check. I get it, it looks
    a bit more complex and you need to know the version number, but the
    benefit of the version check is that it is easy to proof that it runs
    once in the upgrade and then never again (if you pick the right number).

    By comparison, the grep-based solution is hoping that no translation, no package name and no path name now and up to the point you remove that
    code happens to contain the string you grep for.

    Sure, "courier-mta" seems like a string unlikely to appear, but can you
    be sure?

    courier-mta is the package doing the diverting. If there is ever some other package pretending to be courier-mta entering a divert line, or some other divert line using a path name that includes courier-mta, I would definitely like to know about it.

    Random example, but if we ever end up merging /usr/sbin with /usr/bin
    and the long tail turns out to be as messy as /bin with /usr/bin
    this long forgotten and done with upgrade stanza becomes suddenly very relevant again as courier-mta will once again appear in dpkg-divert.


    Best regards

    David Kalnischkies

    P.S.: Your grep, if it triggers, also generates output on stdout.
    At least silence it with -q.

    Wouldn’t output on stdout be a good thing, especially if there is ever some chance this could run when it shouldn’t.

    --
    Soren Stoutner
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmeL+P0ACgkQwufLJ66w tgO6WhAAhRrPue24AlXivQSqFeqSnAa4yUmDwlHUAq156xPzANz/Q20Px6tgS5Tk wRRYeTC4iwyOATCYzTUQXdOUhzcCyFiBU2auh9kd/Z6A8l+5hJTLp0o60f0p9vWH 6HzmKQn7IHKbk8aFEgz/x77i3gcBr/k8rLtYPJkQaUL4bWBSTp/2hPhqPyVUp6wG dgvzv9A3p8gYuloAhpufvTPgyg4duM0aHnlAUG6nf60kx3ItoBRGtnFm8hIXiBDK ALyNbCGxVU4+c2cp+HB9ib4Gz70cK7XTmnB7pk7CGoL2DxASBKcApancDhcWgdNZ X6V29S84RjTIsCBCA0ojdHOCzMdYpy+wtoUjQfhOZJoXlRurW+LK8olg+abwoEXS dboQRBPaYLRj4EISBICS3gKCgZ6nnyuZRBB6qpqII9/xgCIWtutTZCV6Z7UDWuyr BpJ9dkyZzFLMsPVdlYRHN4clw9JjpjuOZCbT7Ca5sQTRTi9ubdPsd6A3vfDht6+b wZ3gCVBdn5nrzENWo2q+tpGjYYlvaM/qffPWUYp3PWqUgBj6SQsx1kNQU1l7E+Vn 7KIK5ahLboB+5wKGUu3to3QZVGneuP6iqaqHuaPnJ9dbCXmuX/s0Yg3xIXdtMShC ZIu9B4XrKcVPf6RnfABaDngZ1Kpsa1Rdm844bop2tGl7C8lReYM=
    =oygW
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrew Bower@21:1/5 to Soren Stoutner on Sat Jan 18 21:10:01 2025
    On Sat, Jan 18, 2025 at 11:54:53AM -0700, Soren Stoutner wrote:
    On Saturday, January 18, 2025 8:41:18 AM MST David Kalnischkies wrote:
    Am Fri, Jan 17, 2025 at 03:29:39PM -0700, schrieb Soren Stoutner:
    if [ dpkg-divert --list | grep courier-mta ]; then
    Sure, "courier-mta" seems like a string unlikely to appear, but can you
    be sure?
    [..]
    P.S.: Your grep, if it triggers, also generates output on stdout.
    At least silence it with -q.

    Wouldn’t output on stdout be a good thing, especially if there is ever some chance this could run when it shouldn’t.

    In case anyone hadn't realised: dpkg-divert --list optionally takes an
    argument which is glob-matched against package name or path name, so you
    don't need grep and can decide whether you want to insist on a full
    match or catch more widely, e.g

    [ -z "$(dpkg-divert --list courier-mta)" ] || ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Kalnischkies@21:1/5 to All on Mon Jan 20 12:40:01 2025
    Am Sat, Jan 18, 2025 at 11:54:53AM -0700, schrieb Soren Stoutner:
    courier-mta is the package doing the diverting.

    That is what I meant… you are grepping in a list of ALL diversions by
    all packages and everything the local admin has configured. Nothing
    defines that the string you match for is not e.g. part of the pathname
    in a diversion unrelated to your packaging.

    In the random example I fashioned an sbin-merge thingy would introduce a
    divert on "/usr/sbin/courier-mtaconfig" – notice how that path includes courier-mta and hence matches? (IF it were fashioned after usr-merge the
    divert would also be created by your package and so be another match ~
    so whoever provides the patches will have additional work dealing with
    the no longer true assumption that your package has no diverts).

    I have no idea about courier-mta AT ALL, but is that the upstream name
    of that binary given you seem to rename it in an install rule? If so,
    how about a local admin that diverts it to the upstream name for
    $reasons. Some people divert example files into non-example locations
    and your example file is shipped in /usr/share/doc/*courier-mta*/…

    Maybe I should come up with a toy language that translates 'diversion'
    to 'courier-mta' as the output of the list is translated.

    Have you considered that generating the list of diversions could be
    an IO and/or CPU intensive task?


    That can be "fixed" by being more careful in the choice of haystack to
    grep in as well as in refining the needle to search for – or we can take
    a step back and check if this is an upgrade from a version older than
    the first one without the diverts and be done with it.


    This is your choice, you are the maintainer, I am just mentioning things
    you can look out for in case you haven't so far and want to consider them.
    And not just you, as this is the mentors list, so I would assume/hope
    that others read threads on the list and learn from it, which I hope in
    this thread is "be careful what you grep for"… evil can be everywhere[0].

    [0] https://salsa.debian.org/apt-team/apt/-/commit/9bd81ac3c85d8c9fee01d0ecfc681841aa89e6eb


    P.S.: Your grep, if it triggers, also generates output on stdout.
    At least silence it with -q.

    Wouldn’t output on stdout be a good thing, especially if there is ever some
    chance this could run when it shouldn’t.

    The removal of the diversion has dpkg already generate text, so what
    additional value does this provide to someone who already has a hard
    time finding "interesting" lines in between the upgrade noise?
    Can you name another packages maintainer script that does this?
    Do you not agree that it would be preferable if maintainer scripts
    would be silent if they have nothing of note to report?


    Best regards

    David Kalnischkies

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEE5sn+Q4uCja/tn0GrMRvlz3HQeIMFAmeONO4ACgkQMRvlz3HQ eIP2MQ/9HrWrOE5GAWuDF9+kmCSDKXzxFWv1+LjNDLiNW8XZG85FiEitx6t4rIOj EernSXh3bbzC2o6CAp7I9no397O30ZWk2l8d08enfogAcIuDFmRnLoK/XpX8i56H fMNuFMKjCFq3YTR9YE/Bfq4aUatSgoSkah91tiU2UcWaszkxQ9hpOkl6Uq7zMkeZ fq2jvmyTlzvx7woQbqEQFaCUnpGkVYNwT+TuSRY7LiPsntm7Co9N8yRT+qhzoxOJ 3L7up8xN4Yrdp0Kwvdf8HBtubb8qRLeMdRfbZ3sYUbhv/IL0csIPLoPQfnugxw0f rm4sk7t5Io6zzD5h7d8YmACMxysK+iorvtYxrLI7bEVbe/kvQCVXcKRDQwLCafsS WEyhwTpPCh064odKcICIhMjs5p10CXV/JT5tPSMIvc7VDREOg1UmlhKNeAp24IxW z583y7MzFkUMIhmf6cEU/hzlM25rBEgK/HpHi7/UkxUf9+Ct7vWXdPxCWgXaRFto 9DFQitSLoC74nBH1DaiZZQ8lqUkiijs9/m23MIx6uNgrpYiI+hKbjT+8ueh2hFss lS2FMaLSdhd4gg6W6GxszWRuf38damz3vx4heM0zi+Lncy/mnlsEOFaQr+F6qH/+ Y1YhaNfUAfTHmGuXSXkUSXmXWL0hLYphQo9Yhrc4QG1UFAnIVmk=
    =PxA6
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to Debian Mentors on Mon Jan 20 12:25:19 2025
    On Monday, January 20, 2025 4:35:15 AM MST David Kalnischkies wrote:
    Am Sat, Jan 18, 2025 at 11:54:53AM -0700, schrieb Soren Stoutner:
    courier-mta is the package doing the diverting.

    That is what I meant… you are grepping in a list of ALL diversions by
    all packages and everything the local admin has configured. Nothing
    defines that the string you match for is not e.g. part of the pathname
    in a diversion unrelated to your packaging.

    In the random example I fashioned an sbin-merge thingy would introduce a divert on "/usr/sbin/courier-mtaconfig" – notice how that path includes courier-mta and hence matches? (IF it were fashioned after usr-merge the divert would also be created by your package and so be another match ~
    so whoever provides the patches will have additional work dealing with
    the no longer true assumption that your package has no diverts).

    I have no idea about courier-mta AT ALL, but is that the upstream name
    of that binary given you seem to rename it in an install rule? If so,
    how about a local admin that diverts it to the upstream name for
    $reasons. Some people divert example files into non-example locations
    and your example file is shipped in /usr/share/doc/*courier-mta*/…

    I honestly don’t see the problem with this. Even if it does match because some other diversion contains a courier-mta string (which I consider so unlikely as to never happen), all it would do is run two very specific divert removal commands. As the two diversions it is removing should never exist under any other circumstances, no harm is done. It won’t remove any diversion
    commands that any local admin would have added.

    Have you considered that generating the list of diversions could be
    an IO and/or CPU intensive task?

    In my experience it isn’t either IO or CPU intensive, especially compared with
    all the other things that installing a package entails.

    The removal of the diversion has dpkg already generate text, so what >additional value does this provide to someone who already has a hard
    time finding "interesting" lines in between the upgrade noise?
    Can you name another packages maintainer script that does this?
    Do you not agree that it would be preferable if maintainer scripts
    would be silent if they have nothing of note to report?

    The only time any text would be generated is if there is a match, in which case, as you note, other text will also be generated. So, as you say, this script is already silent when there is nothing of note to report.

    I do appreciate you taking the time to comment. Often nobody makes any comments to questions that are asked on the forums, and reading your comments has caused me to think more deeply about dpkg-divert. In this case I personally like the original script because I find it very readable and I don’t
    feel there are any real concerns with how it functions.

    --
    Soren Stoutner
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmeOox8ACgkQwufLJ66w tgNkRxAAoYcswgIuA7C2BsPOVTeupKwuKFhRnk6M9YYOaGfq2GsYUIkLdn3NsNhP LdG2HlfY8BPXugdDC13uv+1xHPxJ5EwAINuy5jdJbtiXD19SwJFCsVfZgoDewqk6 4UvBWljQwcaeF2Y5Ke4RmfpsgCgUz7zD7elqVzO7vLL57QZEm+pQKPUIb7uYWsZA KFmwDNWSQGNtysTRj53TB539mCGpDa8T/zcPRGs0qSeJ7FjQtgKqAT5fl1R28NeD Z+3PZG1uIJQsyc/6K6/+ySPH7vkd3/hfgg1//TZEWmiftvxviyNixc+hoEoQgDpv W8pXn4jGKis0mxuJbtnAuw1crUCaDI1wRKv3en1cn9Liydzb8d0EjLhV+qRJlesf a5oyGUDZ5InYT4xPOGDGfT5IGb4zQFWNGLrOgLu5OWaQVfSC8JJRfkvRXh0RhlMi Zck2MRXDfRa0zs/ajzM1toaXfr0/q4hFy9a9xQ0obrbSCAxZtMFKV3+e0RIkP0Rd e72gY2amiBqFb457HPc5AbCq9C2/tzrkrxH9iqlJ+F7m6x87ZPE7Of5dESCEO2i2 K1+EE0IAzA/6Xfx2xKkHs/F/7VuxWdfS7XaFwGTMJDS93xLfOMqqq53gK/x+eem2 Fc6gPd73IUDRoxLy1Oh5lwrlvoGtlgbIyq9ZJleKlSCACIurBlw=
    =xWRG
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to Debian Mentors on Mon Jan 20 14:58:21 2025
    On Monday, January 20, 2025 12:25:19 PM MST Soren Stoutner wrote:
    I do appreciate you taking the time to comment. Often nobody makes any comments to questions that are asked on the forums, and reading your
    comments
    has caused me to think more deeply about dpkg-divert. In this case I personally like the original script because I find it very readable and I don’t feel there are any real concerns with how it functions.

    In case anyone ends up reading this with the view of copying this example, I realized there was a formatting problem with the check that caused it to never run. The fixed script is as follows:

    # 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 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

    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.

    --
    Soren Stoutner
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmeOxv0ACgkQwufLJ66w tgNO7BAAh5lafj0uY6X+msVdLP+jS13grhYWz96cBA6+k7NFXQ5s9t98wIpIib0G Hx8yQnXLOE8bIWtDCs4UNXgbCcq1x1so52Oz+j4rBUhnHfD8Z8kfoCDnTBOnLIcA X5uEZ0w0PjfyiZo5MVVOXWNpsH2CYqvcEPFkj2HCddSvAphOSwTDWfKnHdcn4OLx ExbgGKw2JbwvFIOpp4TjhiZPpNlMNz1hXWcTbwuifBa0X4i1eRPrKrOAlAnCNuj+ 8OAqiaeGBaymJw//it/gkHzXcBz9q6cwlMfzWcyJueUmZam4XRedBN0P8kyySFzb +Mh66x+35PYdyeFBi6ikPc8nSxRCCknRiRnrIQz9CCGAjjM0+GYE2mJ0JCOprTTv Y29YfwEQ5vsSbmrl49+IIp0eFZcXPbGDjaPx09ilr08oDaP95zDLyTl4Y5RgAZ+V P/x+fatPKmKLECg4xLYUYmGfR1aCYDTtZDjgdX4F/XHsD7zd1GSuul9HWdYUEXw0 xqO3rd24jMGm6mJy8fI3MzmyIkpPYkQbs3ZupqBG3M00iOGvGjwPaP5qwQ6OS+5I VdeKe1hgXnfKMtwjD9mrfE0mk2P/8c4/8dqGtLiiLb+EAv390kwA1cwhIRi5EbLk 5ubv5CT4nz+aL1+0iMRhVVd6sMZ12dA7cLsF2u4Mp5UW1Z/NeIk=
    =Lfyy
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Kalnischkies@21:1/5 to You can on Tue Jan 21 19:00:01 2025
    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

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEE5sn+Q4uCja/tn0GrMRvlz3HQeIMFAmeP384ACgkQMRvlz3HQ eINlwQ/+JT58fPZq3l6aCduXmAK4QS9MNBCbPnoqisbSzCw8zm8Eh+TxhmKiPWWT GnLCwM9wQ8aKFBIGQmIby4r/osyOb4a9OzcSDos5g0KVAfRmV/cPiP8DWH5hIzLo maEJoYrQyU2f8qfXH05E/1+p614PcIuvzDO3oDTxYHHQMIZ3Yi0y+J1ksxpJC93+ PETaSD69K2lNTD8GFskpvG35sZZwJaL7YMx/1bXeH8p33QG7TOo+e8dBY/J0Gm2s 4lBDs+v+OAcWEALVjBnwLv72wbcXVEGJYNgAhh4Hqkr2TZw93fWIHCCD6JU9qUBd cfhce6xo3LvFGlgl3fu1vw8QMDLNv6sz0rv5qoQlxMnvfKc/ggikmavKkPukWzj2 jjo+GdF3L/nFkGAVkBUijxrQNShIgBEC2EmQq0OA2ar1FYYku20t1BHP6Tm08Z6U HT2WeyE9VqqXCsrmHGhu+4/jYz7p2/df+40ZSN5FN9waghBcbMK/j++0dbKmDk/9 PbSAX4B0MuX2wBNsyV16lUIaLoUU6hmkZoARZh+YZ9fMXMgb4zun7adbT+tdfsqr y9TA+UpvIJLm00+ey2PiCOU8TC6toDElaUmQxgLKqu+Bs3YxPStCfNcCuDFuzL6v 2Caa/VXMkf2+F3lym+5uUCkKFiMbxTOZyhYFDTv8PKqc16HLtLs=
    =RpzA
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to Debian Mentors on Tue Jan 21 17:04:27 2025
    This is a multi-part message in MIME format.

    --nextPart10596745.nUPlyArG6x
    Content-Transfer-Encoding: quoted-printable
    Content-Type: text/plain; charset="utf-8"

    David,

    On Tuesday, January 21, 2025 10:56:31 AM MST David Kalnischkies wrote:
    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`)

    Thanks for catching that. I always run piuparts and lintian locally when building a
    package. Indeed, piuparts does flag the [[, but it still exits successfully (as can be seen in
    the log you linked to).

    Lintian also flagged it, but I missed it when I scanned through all of the linitan warnings.
    This particular package has a large number of lintian problems, which is going to take me
    several years to cleanup after salvaging the package. Having so many warnings sometimes makes it difficult to notice when a recent change adds a new one.

    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.

    I ran a number of routines on my local system, creating various diversions and see the
    results when running the logic of this part of the script against them, which, unfortunately, was running under . . . bash. So, it liked the previous version of the script
    just fine.

    Thanks again for catching this. I would have eventually have noticed the lintian warning
    as I read over those frequently. But I am sure users will appreciate having this fix sooner.

    So, for clarity of documentation in case anyone stumbles across this thread and needs to
    do something similar in the future.

    # 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 [ -n "$(dpkg-divert --list 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/ 1ec1938107a9529d9febd4a4a05c8e89e347148c/debian/courier-mta.postinst#L19

    --
    Soren Stoutner
    soren@debian.org

    --nextPart10596745.nUPlyArG6x
    Content-Transfer-Encoding: quoted-printable
    Content-Type: text/html; charset="utf-8"

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">David,</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">On Tuesday, January 21, 2025 10:56:31 AM MST David Kalnischkies wrote:</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; Am Mon, Jan 20, 2025 at 02:58:21PM -0700, schrieb Soren Stoutner:</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; if [[ `dpkg-divert --list courier-mta` ]]; then</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; </p> <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; [[ is a bashism (see checkbashisms from devscripts), so I wonder a b
  • From Soren Stoutner@21:1/5 to Debian Mentors on Thu Jan 16 14:57:29 2025
    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
    soren@debian.org
    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEEJKVN2yNUZnlcqOI+wufLJ66wtgMFAmeJgMoACgkQwufLJ66w tgPgpg//Tp/82A2lDtLEe710fZ56GyGfQdfMEPItNZdh1cRid/PzOOesplPAB5gW qvCv6oKkeUvsqQNXKYqxIxFyZoSWmAJi7M5T47FUjQvU3oqN1QhnhATCqzIohB2Z t1RJVu5Q86gh3TKkSO+w3I673uX+9ztYXnY0Yb5YLh9IhPKHUbRf/2cg3fT/08oj 91bP+MOj40X5nhWTKSMKbbYiAHeN4h2ZEIcgh2n12IibUPTihhcnkD10/8GlaG8K v2XClGDQ9iILYuNklRoXht6GEoHsmxnGqjvgisp6cjN5a3FL7K0XMxfdH6i0pA7E /8tJ93JCffUht2uIjAZquYyiBklShM5g0oQCzZRLonHeEyyBtJact9Ennwi73gfY phGMiHPSFCmWNLTKYroUZELqbX7CT2Yqy4LL6ZTC014D66Flz596KzjdY0XHjJlC fWC/Lb2X7OfQgdnwUJYnixo8h9mouwB+oSGXqu9ET2uc4kB2iGwnMqt9LCIr5YAF l5kar/+ASnV2SFOIEyqXHdTkhxxj4D3WiSXDbDoVesZ1csfFIN8XdZHr8eZj0RvX f/XQ3gZ2xPP+3m6TpgSI9Fq53/36IARPNZ2seFavktySwcgF0fjsNUpVvn7vhXbV BGdbVaiHs0mUYsj2isq/qnOfLcEbhC5NtD0+ucRHMR/g1+yhpKM=
    =GEK8
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lorenzo@21:1/5 to Soren Stoutner on Fri Jan 17 10:10:01 2025
    Hi!

    On Thu, 16 Jan 2025 14:57:29 -0700
    Soren Stoutner <soren@debian.org> wrote:

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lorenzo@21:1/5 to All on Fri Jan 17 10:20:01 2025

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Soren Stoutner@21:1/5 to Debian Mentors on Fri Jan 17 15:29:39 2025
    Copy: plorenzo@disroot.org (Lorenzo)

    This is a multi-part message in MIME format.

    --nextPart4249667.8TcEBkooeH
    Content-Transfer-Encoding: quoted-printable
    Content-Type: text/plain; charset="utf-8"

    Lorenzo,

    On Friday, January 17, 2025 2:07:22 AM MST Lorenzo wrote:
    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
    soren@debian.org

    --nextPart4249667.8TcEBkooeH
    Content-Transfer-Encoding: quoted-printable
    Content-Type: text/html; charset="utf-8"

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Lorenzo,</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">On Friday, January 17, 2025 2:07:22 AM MST Lorenzo wrote:</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; Upgrade is available in preinstall and postinstall [1] so it needs to be</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; one of the two, not sure which one is better, (maybe preinstall? but if</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; it fails it goes back the the old version, see dpkg chart)</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; </p> <p style="marg