如何在 Debian postinst 脚本中获取新安装的版本? [英] How to get the newly-installed version within a Debian postinst script?

查看:35
本文介绍了如何在 Debian postinst 脚本中获取新安装的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Debian 政策手册,我的 postinst 脚本是在升级和配置时被调用,如postinst configure old-version",其中 old-version 是先前安装的版本(可能为 null).我想确定new-version,即当前正在配置(升级到)的版本.

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).

环境变量$DPKG_MAINTSCRIPT_PACKAGE包含包名;似乎没有等效的 _VERSION 字段./var/lib/dpkg/status 在 postinst 运行后得到更新,所以我似乎也无法从那里解析它.

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.

有什么想法吗?

推荐答案

我发现解决此问题的最佳方法是在 .postinst 中使用占位符变量(或其他控制文件):

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):

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 中,在构建时将占位符变量替换为正确的版本号:

Then in debian/rules, replace the placeholder variable with the proper version number at build time:

# 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//DEBIAN/postinst 中,如下所示:

The resulting .postinst snippet, found in debian/<package-name>/DEBIAN/postinst, will look like:

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

这篇关于如何在 Debian postinst 脚本中获取新安装的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆