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.
--dry-run
flag on theapt install
command andgrep
for a dependency error.--dry-run
is a synonym of--simulate
which I mentioned above. How would I do, for example, anapt install --simulate packagename (>= 1:2.8.0)
? It's possible that I have packagename in my repos but a diifferent version.apt install -s ./package.deb
then.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.