8

I had a problem with my apt packages which I resolved. The problem and resolution are discussed here: Aptitude says that lots of my packages need to be removed ...?

However, in discussing this, I realized that I have an ancillary question about apt which I'd like to find the answer to, which is why I'm posting this current question.

I did something accidentally which caused more than 1,400 "auto" packages to become orphaned, and they were were listed as "no longer in use" and flagged for removal in aptitude. It seems now that the reason for this is because they all were ultimately dependent on some base-level package or meta-package that was incorrectly deleted.

If that is the case, is there a utility or procedure I can use to take a list of apt packages as input, and produce a dependency tree for this entire set of packages, taken as a whole? If so, I would probably have been able to identify the package at the top of this tree that I accidentally deleted, and I then could have reinstalled this package in order to fix my problem.

In other words, I'm looking for some procedure or utility which would take a list of packages as input and produce something similar to this as output ...

top-package
|--package-000
|-+package-001
| |--package-002
|-+package-003
| |--package-004
| |--package-005
| |-+package-006
| | |--package-007
| |--package-008
|--package-009
... etc. ...

... where package-NNN are my list of input packages plus any other packages they happen to be dependencies for, and top-package is the root of the dependency tree. If my hypothesis is correct that my problem was due to a high-level meta-package having been accidentally deleted, then top-package would identify that deleted package. I could then reinstall top-package and presumably fix my problem.

To be clear, I want to repeat that I already solved my specific problem in a different way (see the referenced discussion). I'm asking this here not to solve that particular problem, but rather, because I would like to have some sort of dependency-tree-listing tool like I described above, in order to help diagnose and fix other similar problems which might occur in the future.

Thank you very much for any references or suggestions.

6
  • 1
    Not sure if this helps, but when the Debian Python team was planning the removal of python2, we had to figure out the order in which to remove packages (starting with leaf packages with 0 rdeps). One of the members came up with a pretty cool script for it here: github.com/sandrotosi/debian-tools. You could probably modify this script to build yourself a tree structure. But in short, it's a matter of choose a base package, then recursively parsing apt-cache rdepends <package>.
    – Stewart
    Apr 7, 2021 at 16:31
  • I'll look into this script. Thank you very much! I'm not sure whether or not this will help me, because I am searching for the base package, and I don't know it in advance. That script might be performing an inverse operation. But I'll look through that code and see if it can still help me.
    – HippoMan
    Apr 7, 2021 at 16:38
  • 1
    If you don't know the package, then you can recursively apt-cache depends <package> to build a dependency tree of what's needed for your package. Do this one a few packages at the same time and filter to only what's common for all packages.
    – Stewart
    Apr 7, 2021 at 16:43
  • Yes, thank you. Doing this on a few of the packages should be able to narrow down the search pretty quickly.
    – HippoMan
    Apr 7, 2021 at 16:54
  • Oh, by the way. That script I mention generates/updates this webpage: sandrotosi.me/debian/py2removal/index.html
    – Stewart
    Apr 7, 2021 at 16:55

2 Answers 2

5

You can use :

apt depends <package>
apt-cache depends <package>   

Or debtree :

sudo apt install debtree
debtree <package>

man debtree:

Generates dependency graphs (in `dot' syntax) for the specified package...

Dependency graphs will by default show (pre-)dependencies, recommended packages, unversioned conflicts, and virtual packages provided by the requested package. Optionally, suggested packages and versioned conflicts can also be included.

Put the list of package into a file, then:

cat file |xargs -n 1 apt-cache depends
cat file |xargs -n 1 debtree
6
  • Thank you very much. I have a large list of packages. So I guess I could run debtree or apt depend against each of them and then somehow unify the results to find a common ancestor. I'm just wondering if someone has already come up with a tool to do this with a collection of packages. I don't want to "re-invent the wheel".
    – HippoMan
    Apr 7, 2021 at 16:42
  • PS: apt depend fails: "E: Invalid operation depend". I'm running apt version 2.0.5. But debtree at least works for me.
    – HippoMan
    Apr 7, 2021 at 16:47
  • 1
    "dot syntax" is actually very nice for this. It's not the most obvious thing to read as a human, but you can feed the output of this into dot (from the graphviz package) to generate a graph in an image. Good answer!
    – Stewart
    Apr 7, 2021 at 16:47
  • Thank you. I'll study graphviz and figure out how to reformat debtree dependency output into something that the dot syntax module understands.
    – HippoMan
    Apr 7, 2021 at 16:50
  • Oh, it's not apt depend, but rather, apt-cache depends. That indeed works for me, also. I could also reformat its output for dot.
    – HippoMan
    Apr 7, 2021 at 16:53
2

I tried the suggestion above, but it didn't give me what I am looking for. I did the following:

I put the list of 1,400+ package names into a file called no-longer-in-use.txt, one package name per line.

Then, I ran this command:

% xargs -n 1 debtree <no-longer-in-use.txt | dot -Tjpg >depgraph.jpg

It ran for 2 or 3 hours, and the resulting depgraph.jpg file took up more than 3.4Gb of disk space.

When I tried to view this file, all I saw was one small 4-item graph. I'm guessing that the command ended up producing 1,400+ separate graphs and then simply appended them one after the other into the output. This meant that my image viewer only saw the first one.

In any case, I want them combined into one, single graph, not multiple individual graphs. I think that in order to accomplish this, the output of debtree (or of apt-cache depends, for that matter) would have to be pre-processed into something which represents the unificiation of all of the individual package dependencies into one, encompassing dependency tree.

And that is what could be fed through dot.

But this could still end up being a huge image file, and I don't need that kind of view.

Instead of that approach, I am going to try the following:

Run apt-cache depends against each package, and format the output into a CSV file by using the package name and the data from each Depends: line as follows. For example, using the ftp package:

apt-cache depends ftp output:

ftp
  Depends: libc6
  Depends: libreadline8
  Depends: netbase
  Replaces: <netstd>

Processed CSV output:

ftp,libc6
ftp,libreadline8
ftp,netbase

Do this for all 1,400+ packages, and then concatenate their individual CSV outputs into one, big CSV file

Then, use this big CSV file as input to a program which generates a dependency tree out of it. Actually, this might produce multiple trees. The roots of each of these trees are the values that I am interested in.

I'll be working on this program in my spare time over the next few days, and I will post it once I have completed it.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .