I want to check, using a script, if a dependency of a package is satisfiable.

I'm not checking if it is installed, just installable. I'm not trying to install a package. I'm also not asking how to fix or resolve issues with dependencies. I just need my function to answer yes or no.

For example:

somepackage (= 11.0.6-4)
anotherone (>> 1.1.2)
yetanother (>= 1.0.16)
andanother (>= 1:2.8.0)

For the first one, I can do an apt-get --simulate install somepackage=11.0.6-4 and see if it fails. For the others, apt-get does not have a feature to install >= or strictly >>.

Also, what if my repos has something like 11.0.6-4ubuntu1 or some PPA string like 11.0.6-4ubuntu1~ubuntu20.04.1~ppa1? In my tests the equal sign will fail even if it is acceptable as a dependency by apt.

For the others, I'm thinking of using apt-cache policy and checking the Candidate: line and doing a numerical comparison. This will fail though for version numbers like 1:2.8.0 where the actual version there is 2.8.0 and not 1. Also, Candidate gives the newest version, which may not always be the desired version.

It's also possible that apt will say "this package is not available but this package provides it" or "installing package1 instead of package2" which makes my manual comparison wrong.

Hence, I want to do this in a way that is consistent with how APT compares packages and version numbers. I don't want my manual comparisons to have false positives or false negatives. I might end up installing something that would cause a broken system, or on the other hand, rejecting to install something that is otherwise installable. Even better if I can tap the apt system itself to tell my if my repos satisfy the needed packages and versions.

Some programs can do this, so I think what I want is doable. If I open a deb package in gdebi, it tells me if there are unsatisfiable dependencies. Gdebi says Error: Dependency is not satisfiable: packagename (>= 1:2.8.0). Basically I would want to do what gdebi does.

  • On a basic level, you could use the --dry-run flag on the apt install command and grep for a dependency error.
    – Jos
    Oct 30, 2020 at 10:11
  • --dry-run is a synonym of --simulate which I mentioned above. How would I do, for example, an apt install --simulate packagename (>= 1:2.8.0) ? It's possible that I have packagename in my repos but a diifferent version.
    – bamm
    Oct 30, 2020 at 11:42
  • Gdebi asks apt for the information (it's in the source code), and apt does all the solving. Gdebi is written in Python3, so not too hard to decipher how to query apt.
    – user535733
    Oct 30, 2020 at 11:57
  • Do you have said package at hand as a .deb file? I guess you could simply apt install -s ./package.deb then.
    – danzel
    Oct 30, 2020 at 12:06
  • @danzel apt install doesn't work on deb files, it only works on package names in a repository. Also, -s is a synonym for --simulate which I've discussed already. Also, I'm not trying to install a package. I want to check, using a script, if a dependency of a package is satisfiable.
    – bamm
    Oct 30, 2020 at 12:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy