How to tie (enforced) a Debian package to a specific Ubuntu version

41 Views Asked by At

I have a C++ project built with CMake and packaged with CPack for Ubuntu, I am issuing packages (.deb) for both Ubuntu 20.04 and 22.04 and I want to enforce that the correct version is installed on a corresponding machine.

Installing (local package):

$ sudo dpkg -i <my-package>.deb

Current solution:

I use the preinst script (which I pass to CPack via the CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA) to check lsb_release -sr and compare against the Ubuntu version that the package was build for.

Limitation:

If the preinst script fails (e.g. when the machine and package versions do not match), the package is not installed (as expected), but the postinst script is still run.


Is there a better way to do this version match enforcement?
If not... how can I prevent postinst to run after preinst failed?

PS - I could check the version also in the postinst script and do nothing in that case, but I would leave that as a last resort.

0

There are 0 best solutions below