We have a software project, which we release as a debian package. The project has a debian/ folder which contains files like changelog compat control copyright rules. We're creating debian packages with the command:

dpkg-buildpackage -us -uc -b --changes-option=-u./dist

which prints a stream of output. What we need to know, for the next step of the process, is the name of the .deb file created.

I know that debians have a predictable filename structure like [package name]_[version]_[architecture].deb but I don't have a way to get these parameters anyway.

There must be another dpkg command that can generate the would-be package name just from looking in the debian folder?

  • You'll find all you need here I think : debian-handbook – lazzio Apr 3 '15 at 13:46
  • 1
    Afraid I can't see how to generate the filename from that chapter. Do you have a specific command in mind? – Tom Viner Apr 7 '15 at 17:14

As you point out, the generated .deb files all share a common format: ${package}_${version}_${arch}.deb.

The package name comes from the Package: entries in debian/control; for a full build, one .deb file will be generated for every Package: entry. You can retrieve the values with

awk '/^Package:/ { print $2 }' debian/control

The version is based by default on the value given in debian/changelog; you can extract that with

dpkg-parsechangelog -S version

(It is possible for a build to specify a different version, but that is unusual.)

Finally, the architecture will be either all (for an Architecture: all package) or by default that of your build system (for any other Architecture:, typically Architecture: any). You can determine the architecture of your build system using

dpkg-architecture -qDEB_BUILD_ARCH

(Strictly speaking that should be -qDEB_HOST_ARCH, but in the general case BUILD and HOST are the same. I'm also ignoring cross-compilation here; if that's an issue use DEB_TARGET_ARCH instead of DEB_BUILD_ARCH.)

Thus for a fully generic solution you'd need to parse the control file to determine which package goes with which architecture; if your control file only builds one package that's not necessary.

dpkg-parsechangelog and dpkg-architecture are provided by the dpkg-dev package.

  • Seems weird there isn't a single command to do this in 1 step. But I'm grateful for your answer, and will try this out asap. – Tom Viner Apr 7 '15 at 17:16
  • You're a star @stephen-kitt : $ echo "$(awk '/^Package:/ { print $2 }' debian/control)_$(dpkg-parsechangelog --show-field version)_$(dpkg-architecture -qDEB_BUILD_ARCH).deb" mypackage_3.8.2_amd64.deb – Tom Viner Apr 8 '15 at 11:23
  • I actually found that my package filename took the Architecture: any from my control file. Where as a call to dpkg-architecture with no args reveals none of the DEB_XYZ vars contain any. The solution: awk '/^Architecture:/ { print $2 }' debian/control – Tom Viner Apr 9 '15 at 11:33
  • 1
    That's odd, "Architecture: all" packages will end up with all as their package architecture, but "Architecture: any" should have their target architecture, not any... – Stephen Kitt Apr 12 '15 at 13:16
  • We like @stephen-kitt as his comments turn out to be correct. – Tom Viner Apr 15 '15 at 14:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.