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

Re: cleanly getting rid of manually installed transitional packages due to rename



On 2020-04-28 10:21:16 -0500, David Wright wrote:
> On Sat 25 Apr 2020 at 21:41:09 (+0200), Vincent Lefevre wrote:
> > I think that you are over-optimistic. Imagine the following case.
> > The pdftk package has been manually installed in the past and is
> > now a transitional package to pdftk-java (currently, this is like
> > your example). But the system has some package that depends on
> > pdftk-java. So, when you run
> > 
> >   apt-get -s purge pdftk
> > 
> > you won't have any message about pdftk-java.
> 
> Sure, that could happen, and the solution is pretty much the same as
> getting too many packages: there's bound to be a dependent
> relationship between pdftk and whatever the replacement is.
> So in either eventuality, you would either have included that check
> in your script, or would kick yourself that you hadn't.

Well, I think that the solution is not to get the information
via "apt-get -s purge" but via "apt-cache depends". This would
be the following zsh script:

------------------------------------------------------------------
#!/usr/bin/env zsh

set -e

setopt EXTENDED_GLOB

if [[ $# -ne 1 ]] then
  echo "Usage: $0 <package>" >&2
  exit 1
fi

if [[ -z "$(apt-mark showmanual $1)" ]] then
  echo "$0: package $1 is not marked as manually installed" >&2
  exit 2
fi

if ! dpkg -s $1 | grep -iq '^Description:.*transitional'; then
  echo "$0: package $1 is not a transitional package" >&2
  exit 2
fi

dep=()

apt-cache depends $1 | while read line
  do
    case $line in
      \|*)
        echo "$0: unexpected OR dependency, aborting" >&2
        exit 2
        ;;
      Depends:*)
        dep+=${line##Depends: #}
        ;;
    esac
  done

for i in $dep
do
  apt-mark manual $i
done

apt purge $1
------------------------------------------------------------------

Note: "apt-cache depends" is multiarch-aware, i.e. it will append
the architecture when need be, which is a good thing here (and when
doing things manually, e.g. by looking at the "dpkg -s" output, it
can be easy to forget that).

> As I said, this has to be done so infrequently (in stable, at least),

I use unstable. I doubt that packages get renamed in stable
(except between full upgrades, where the issue has already
been solved with the oldlibs section).

> that I've never bothered to think about scripting it, which means
> that interactively you just deal with any corner cases as they arise.

Yes, one can do that manually. But one important issue is that one may
forget to do that and use "apt purge ..." directly without remembering
that one also needs to mark the dependencies as manually installed
(and the script does not solve this particular issue, since one may
forget to run it, at least when one has taken the habit to use
"apt purge ..." directly).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Reply to: