按照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/<package-name>/DEBIAN/postinst
代码段如下所示: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
关于shell - 如何在Debian postinst脚本中获取新安装的版本?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/715313/