How to Make Debian Package Install Dependencies

Debian package, installation of dependencies

Don't use the preinst script for that! Beside from the fact that it does not work because just a single instance of dpkg can run at a time the installation of the dependencies is a job for apt. Use the control file to list your binary dependencies as described in the Debian policy: http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps

Further note that if you install a local package using dpkg -i package-name.deb, dpkg will not(!) install the dependencies listed in the control file. You still need to install them manually. If you want dependencies installed properly, you need to:

  • Setup an Debian package repository (or use a ppa on Ubuntu)
  • Place the .deb there
  • Add the repository to your sources.list
  • apt-get update or aptitude update
  • apt-get install package-name or aptitude install package-name

How to install a Debian package's Build-Depends and Depends

Assuming this is a standard package in your apt repositories, you should be able to simply run

apt-get build-dep PACKAGE [PACKAGE…]

Generally speaking, the best solution is to find a package with the same dependencies (better yet, an identical yet different version of the same package) and just build-dep it. This solves 99+% of these issues in my experience.


I don't know mk-build-deps at all, but you can run this to see what dependencies are called out in the debian/control file in package "PACKAGE":

echo $(awk '
/^(Build-)?Depends:/ || /^ / && deps {
sub(/^[^ ]+: /, "")
deps = 1
dep_str = dep_str ", " $0
next
}
{ deps=0 }
END {
split(dep_str, dep_array, /, */)
for (d in dep_array) {
dep = dep_array[d]
gsub(/[^a-z0-9_.-].*$/, "", dep)
if (dep && !seen[dep]++) print dep
}
}' PACKAGE/debian/control)

(This examines the Debian control file for Build-Depends and Depends lines and presents just the dependencies that are listed, excluding any variables (which I believe are already included in other hits from the file).

AWK code walkthrough: If it is a Build-Depends or Depends line, or it's a whitespace-indended line following such a line, remove the line label, note we're in a dependency line (dep = 1), and save it into dep_str. On other lines, remove the marker saying we're continuing a dependency line. After parsing the input, split the dependency string dep_str into an array delimited by commas and optional trailing whitespace, then iterate through that array. Scrub invalid characters from the end of the dependency name (these are version info) and if anything remains and hasn't been seen (here) before, print it on its own line.

Replace echo with apt-get install if you like, but you might need to prune out the items you're looking to customize and/or manually install first.

After that, you should have an easier time with dpkg -i *.deb. Feel free to try apt-get install --fix-broken at any time if you're stuck.

Debian package install Dependency from Git?

Debian packages are supposed to be self contained. You don't know that when the package is installed that the remote Git server will exist and that it will contain the contents that you want (e.g., they could have been deleted or replaced with malicious contents). You don't even necessarily know that you'll have a network connection at that time.

Even if, in your environment, you do know that, Debian packages don't expect that, so the files you download via Git and generate by using pip won't be removed by your package, leaving cruft on the user's system. That means that future package installs might break due to this leftover cruft, leading to hard-to-debug errors.

It is possible to do by using a postinst script, but definitely not a good idea. You'll want to package your dependency in another Debian package or use the existing package from the developer's page instead.

How to install deb dependencies without installing the package?

The short answer is that there's no proper and general way to fetch the dependencies, except for actually building the binary packages and extracting them from the .debs.

That's because there are going to be dependencies generated at build-time by either helper tooling or even by debian/rules via substvars, which might depend on dynamic checks, such as OS vendor, architectures, etc.

If you control the source package and know what are the assumptions then the snippet you provide might work, but it might still miss dependencies injected by say debhelper if you are using that.

I guess the real question is why do you need this for? For testing purposes, you would be better served with autopkgtests, which are able to declare dependencies by reference on either the source package build-dependencies or the run-time dependencies for specific binary packages being tested. If this is needed as part of the build process, then those should be listed instead in the source package build-dependencies.

For run-time dependencies you might also be missing Pre-Depends, although those are unusual. For build-dependencies, you can use apt build-dep ., but that has the problem of not tracking these via a metapackage that can be then removed to drop all the unneeded dependencies.



Related Topics



Leave a reply



Submit