首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在fakeroot deb包生成器中使用postinst脚本?

如何在fakeroot deb包生成器中使用postinst脚本?
EN

Stack Overflow用户
提问于 2014-09-16 23:09:49
回答 2查看 3.2K关注 0票数 1

下午好,

我能够使用以下方法将我的项目构建成一个deb包:

代码语言:javascript
复制
fakeroot dpkg-deb --build mypackage

接下来,我可以使用

代码语言:javascript
复制
dpkg -i mypackage.deb

当我这样做时,所有的东西都被正确地安装和复制,但是我想在包安装之后运行一些bash命令。

我知道这需要使用mypackage/DEBIAN目录中的postinst文件来完成。

我已经在网上看到了一些这个脚本的例子,但是对于如何编写一个脚本以及如何将它包含在构建中没有明确的解释。

  1. 如何确保fakeroot dpkg-deb包含此脚本,并将其放置到DEBIAN目录中?
  2. 在postinst脚本中有一个案例结构,这是为了什么,我把bash命令放在那个脚本中的哪里?
  3. 如果我用dpkg -i mypackage.deb安装包,这是否足以运行该脚本?

下面是我想要制作的一个示例脚本。

  1. “配置、中止-升级、中止-删除和中止-解构图”代表什么?
  2. “更新选项”行是做什么的。

谢谢你的帮助,

下面是后置文件。

代码语言:javascript
复制
#!/bin/sh

set -e

case "$1" in
    configure)
        # EXECUTE MY BASH COMMAND
        echo /usr/local/lib > /etc/ld.so.conf && ldconfig
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
        exit 0
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

update-alternatives --install /usr/bin/fakeroot fakeroot /usr/bin/fakeroot-ng 5 \
        --slave /usr/share/man/man1/fakeroot.1.gz \
            fakeroot.1.gz /usr/share/man/man1/fakeroot-ng.1.gz

exit 0
EN

回答 2

Stack Overflow用户

发布于 2014-09-17 17:23:31

首先,这里可能是最相关的文档:Debian策略手册:包维护人员描述和安装过程

第二,在编写或处理维护脚本时,最重要的事情是必须记住:它们必须是幂等的。假设脚本将连续运行许多次,并确保这样的脚本不会中断。

直接回答你的问题,

  1. 使用DEBIAN构建时,将其放入dpkg-deb目录是正确的。如果您使用Debhelper进行更安全或更方便的构建设置,则可以将postinst放在debian/$packagename.postinst中。
  2. postinst脚本可以在许多不同的情况下调用。你能在很多(大多数?)中找到的“案例”语句。邮递员的意思是检查是哪一种情况。一般来说,在所有可能的情况下采取大多数事后行动是有意义的,这就是为什么它们被组合在一个脚本中的原因。但有时区分比较好。我将在#4下面解释不同的场景。
  3. 是。如果存在,成功安装deb包(无论是通过dpkg -iapt-get install还是其他方式)必须涉及成功运行它的前脚本和后期脚本。可以在不运行任何维护脚本的情况下“解压”deb,但这不被认为是“安装”。
  4. 这些"action“名称对应于可以运行postinst的不同情况。
代码语言:javascript
复制
- _configure_: A package is being installed or upgraded. If the package wasn't installed before, `$2` will be empty. Otherwise `$2` will contain the old version number of the package; the version from which you are upgrading.
- _abort-upgrade_: An upgrade operation was aborted. As an example, I have version V1 of mypkg installed, and I try to upgrade it to V2. But the preinst or postinst of V1 fail to run successfully, or there is a file conflict. dpkg stops trying to install V2, and re-runs the postinst from V1 (with the "`abort-upgrade`" action) in case any state needs to be restored.
- _abort-remove_: A remove operation was aborted. For example, if I ran "dpkg -P mypkg", but mypkg's prerm script failed to run, or something else happened that made dpkg think it could not safly uninstall mypkg. So it runs mypkg's postinst again (with the "`abort-remove`" action) in case any state needs to be restored.
- _abort-deconfigure_: As you might guess, a deconfigure operation was aborted. "deconfiguring" is sort of a half-removal action used when a package being installed conflicts with others already installed. To make the explanation short, if the `abort-deconfigure` action is being run, the postinst is expected to restore any state that might have been undone by the `prerm` script with the `deconfigure` action.

要获得更多的细节,请参见https://people.debian.org/~srivasta/MaintainerScripts.html的伟大图表和解释。

  1. “更新-替代”命令更新Debian "alternatives“系统中的条目。请看手册页。在这个特定的例子中,命令告诉Debian "/usr/bin/fakeroot-ng“是fakeroot命令的另一种选择。根据这个选项的优先级和其他注册替代的优先级,以及用户的偏好,现在可以在某人运行"fakeroot“时调用fakeroot
票数 3
EN

Stack Overflow用户

发布于 2015-01-07 15:57:25

只要想想这句话:

代码语言:javascript
复制
echo /usr/local/lib > /etc/ld.so.conf && ldconfig

根据Debian政策,你不应该修改ld.so.conf

一个简单的选择是这样做:

后脚本中的 :

代码语言:javascript
复制
/usr/local/lib > /etc/ld.so.conf.d/EXAMPLE.conf && ldconfig

和postrm脚本中的

代码语言:javascript
复制
rm /etc/ld.so.conf.d/EXAMPLE.conf && ldconfig
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25879793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档