Get the new-version in preinst Debian maintenance script
I want to prevent an older Debian package from stomping over a newer installed version of the Debian package.
I'm trying to do this by comparing the current Debian package version to what is currently installed in the debian/preinst maintenance script. Ideally, I'd like to provide a warning, and a (continue y/n?) prompt.
This question is closely related to How to get the newly-installed version within a Debian postinst script?. That issue was created in '09 so I'm not sure if it's appropriate to add my question in that question or not.
The response to the older questions was, "Why can't you simply hard-code the version in your package?"
My response would be that I don't want to manage the version in yet another location. The version is already in the debian/changelog and the Python module's init.py script as version. This logic also needs to be replicated to several other internal Debian packages we're maintaining. Ideally, I'd like to make this as simple as possible by removing steps from the process of building a Debian package.
I've read the relevant Debian docs http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html and while I can get the old-version there is no way to get the version I'm currently installing.
I echoed the env within debian/preinst and it does provide an environment variable that contains the version ...: SUDO_COMMAND=/usr/bin/dpkg -i python-mypkg_1.9.3-2_all.deb. I should be able to get the version this way, but I'm not sure if I can rely on this variable to exist in every distribution this package will be deployed to. It also seems like a hack to do it this way.
I'm aware of dpkg-parsechangelog, which is a great tool!, but it only works when the package is unpacked. It clearly states this in the docs as well.
I've also tried using the Python pckg_resources module to discover the version with: pckg_resources.require("mypkg")[0].version. If the module is not yet installed on the target machine it will fail -- which makes absolute sense.
It seems like there should be an option either in the debian/control file or some开发者_C百科 tool I can use to prevent this from happening without re-inventing the wheel. Thanks all!
I'm going to use SUDO_COMMAND. This will at least make it so I don't have to hard-code the version into the preinst maintenance script (It already exists in two other locations!!). It's an extreme hack, but I haven't been able to find any useful documentation that might direct me to a more sensible approach.
FYI, the env variable, SUDO_COMMAND, seems to exists in every Debian environment I've used.
Try:
dpkg-query --show --showformat='${Version}' packagename
精彩评论