根据Debian Policy Manual,我的postinst脚本在升级和配置时被调用,如"postinst configure old-version ",其中old-version是以前安装的版本(可能为null).我想确定新版本,即当前正在配置(升级到)的版本.
环境变量$DPKG_MAINTSCRIPT_PACKAGE
包含包名称; 似乎没有相应的_VERSION
领域. /var/lib/dpkg/status
在postinst运行之后得到更新,所以我似乎也无法解析它.
有任何想法吗?
这是解决此问题的最佳方法是在您的.postinst
(或其他控制文件)中使用占位符变量:
case "$1" in configure) new_version="__NEW_VERSION__" # Do something interesting interesting with $new_version... ;; abort-upgrade|abort-remove|abort-deconfigure) # Do nothing ;; *) echo "Unrecognized postinst argument '$1'" ;; esac
然后debian/rules
,在构建时用适当的版本号替换占位符变量:
# Must not depend on anything. This is to be called by # binary-arch/binary-indep in another 'make' thread. binary-common: dh_testdir dh_testroot dh_lintian < ... snip ... > # Replace __NEW_VERSION__ with the actual new version in any control files for pkg in $$(dh_listpackages -i); do \ sed -i -e 's/__NEW_VERSION__/$(shell $(SHELL) debian/gen_deb_version)/' debian/$$pkg/DEBIAN/*; \ done # Note dh_builddeb *must* come after the above code dh_builddeb
得到的.postinst
片断,发现debian/
,看起来像:
case "$1" in configure) new_version="1.2.3" # Do something interesting interesting with $new_version... ;; abort-upgrade|abort-remove|abort-deconfigure) # Do nothing ;; *) echo "Unrecognized postinst argument '$1'" ;; esac