Per the Debian Policy Manual, my postinst script is getting called at upgrade and configure time, as "postinst configure old-version", where old-version is the previously installed version (possibly null). I want to determine new-version, i.e. the version that is currently being configured (upgraded to).
The environment variable $DPKG_MAINTSCRIPT_PACKAGE
contains the package name; there does not seem to be an equivalent _VERSION
field. /var/lib/dpkg/status
gets updated AFTER postinst runs, so I can't seem to parse it out of there, either.
Any ideas?
By the time postinst is run, all the package files have been installed and dpkg's data base has been updated, so you can get the just installed version with:
I use the following somewhat dirty command in the postinst script:
This is the best method I have found to resolve this issue is to use a place-holder variable in your
.postinst
(or other control files):Then in
debian/rules
, replace the placeholder variable with the proper version number at build time:The resulting
.postinst
snippet, found indebian/<package-name>/DEBIAN/postinst
, will look like:Add the following to the
debian/rules
:It will replace any occurrence of
__DEB_VERSION__
in your debian scripts with the version number.Advantages over other solutions here:
Why can't you hard-code the version into the postinst script at packaging time?