11

Debian Policy Manualによると、私の postinst スクリプトは、アップグレードおよび構成時に「postinst configure old-version」として呼び出されます。ここで、old-versionは以前にインストールされたバージョン (おそらく null) です。new-version、つまり現在構成されている (アップグレードされている) バージョンを特定したい。

環境変数$DPKG_MAINTSCRIPT_PACKAGEにはパッケージ名が含まれています。_VERSION同等のフィールド はないようです。/var/lib/dpkg/statuspostinst の実行後に更新されるため、そこから解析することもできないようです。

何か案は?

4

7 に答える 7

6

これは、この問題を解決するために私が見つけた最良の方法は、.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
于 2012-06-25T23:08:02.243 に答える
4
VERSION=$(zless /usr/share/doc/$DPKG_MAINTSCRIPT_PACKAGE/changelog* \
     | dpkg-parsechangelog -l- -SVersion')

ここでの他のソリューションに対する利点:

  • 変更ログが圧縮されているかどうかに関係なく機能します
  • 正規表現や awk などの代わりに dpkg の changelog パーサーを使用します。
于 2014-02-22T21:34:26.973 に答える
4

に次を追加しますdebian/rules

override_dh_installdeb:
    dh_installdeb
    for pkg in $$(dh_listpackages -i); do \
        sed -i -e 's/__DEB_VERSION__/$(DEB_VERSION)/' debian/$$pkg/DEBIAN/*; \
    done

__DEB_VERSION__これは、debian スクリプト内の の出現をバージョン番号に置き換えます。

于 2015-09-15T09:29:42.530 に答える
3

postinst スクリプトで次のやや汚れたコマンドを使用します。

NewVersion=$(zcat /usr/share/doc/$DPKG_MAINTSCRIPT_PACKAGE/changelog.gz | \
  head -1 | perl -ne '$_=~ /.*\((.*)\).*/; print $1;')
于 2011-06-13T19:00:14.170 に答える