Package 为什么我的debian postinst脚本没有运行?

Package 为什么我的debian postinst脚本没有运行?,package,debian,dpkg,Package,Debian,Dpkg,我已使用以下工具制作了我的应用程序的.deb: 除此之外,postinst脚本应该为应用程序创建一个用户: #!/bin/sh set -e APP_NAME=myapp case "$1" in configure) virtualenv /home/$APP_NAME/local #supervisorctl start $APP_NAME ;; # http://www.

我已使用以下工具制作了我的应用程序的
.deb

除此之外,
postinst
脚本应该为应用程序创建一个用户:

#!/bin/sh

    set -e

    APP_NAME=myapp

    case "$1" in
        configure)
            virtualenv /home/$APP_NAME/local
            #supervisorctl start $APP_NAME
        ;;

    # http://www.debian.org/doc/manuals/securing-debian-howto/ch9.en.html#s-bpp-lower-privs
       install|upgrade)

       # If the package has default file it could be sourced, so that
       # the local admin can overwrite the defaults

       [ -f "/etc/default/$APP_NAME" ] && . /etc/default/$APP_NAME

       # Sane defaults:

       [ -z "$SERVER_HOME" ] && SERVER_HOME=/home/$APP_NAME
       [ -z "$SERVER_USER" ] && SERVER_USER=$APP_NAME
       [ -z "$SERVER_NAME" ] && SERVER_NAME=""
       [ -z "$SERVER_GROUP" ] && SERVER_GROUP=$APP_NAME

       # Groups that the user will be added to, if undefined, then none.
       ADDGROUP=""

       # create user to avoid running server as root
       # 1. create group if not existing
       if ! getent group | grep -q "^$SERVER_GROUP:" ; then
          echo -n "Adding group $SERVER_GROUP.."
          addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true
          echo "..done"
       fi
       # 2. create homedir if not existing
       test -d $SERVER_HOME || mkdir $SERVER_HOME
       # 3. create user if not existing
       if ! getent passwd | grep -q "^$SERVER_USER:"; then
         echo -n "Adding system user $SERVER_USER.."
         adduser --quiet \
                 --system \
                 --ingroup $SERVER_GROUP \
                 --no-create-home \
                 --disabled-password \
                 $SERVER_USER 2>/dev/null || true
         echo "..done"
       fi

       # … and a bunch of other stuff.
似乎是用
configure
调用
postinst
脚本,而不是用
install
调用脚本,我正在试图理解原因。在
/var/log/dpkg.log
中,我看到了我希望看到的行:

2012-06-30 13:28:36 configure myapp 9 9
2012-06-30 13:28:36 status unpacked myapp 9
2012-06-30 13:28:36 status half-configured myapp 9
2012-06-30 13:28:43 status installed myapp 9
我检查了
/etc/default/myapp
是否不存在。文件
/var/lib/dpkg/info/myapp.postinst
存在,如果我以
install
作为第一个参数手动运行它,它将按预期工作


为什么
postinst
脚本没有与
install
一起运行?如何进一步调试此脚本?

我认为您复制的示例脚本完全错误<代码>安装后不可用 应该使用任何
install
upgrade
参数调用。 dpkg格式的权威定义是Debian策略 手册当前版本在中描述了
postinst
并且仅列出
配置
中止升级
中止删除
abort-remove
abort-deconfigure
作为可能的第一个参数

我对我的答案没有完全的信心,因为你的坏榜样 仍然在debian.org上,很难相信这样一个bug会溜走
通过。

我相信艾伦·库里提供的答案是不正确的,至少在2015年及以后。
软件包的构建方式一定有问题,或者导致问题的
postinst
文件中存在错误。
您可以通过将
-D
(调试)选项添加到命令行来调试安装,即:

sudo dpkg -D2 -i yourpackage_name_1.0.0_all.deb
-D2
应解决此类问题

对于记录,调试级别如下所示:

          Number   Description
               1   Generally helpful progress information
               2   Invocation and status of maintainer scripts
              10   Output for each file processed
             100   Lots of output for each file processed
              20   Output for each configuration file
             200   Lots of output for each configuration file
              40   Dependencies and conflicts
             400   Lots of dependencies/conflicts output
           10000   Trigger activation and processing
           20000   Lots of output regarding triggers
           40000   Silly amounts of output regarding triggers
            1000   Lots of drivel about e.g. the dpkg/info dir
            2000   Insane amounts of drivel
install
命令调用
configure
选项,根据我的经验,
postinst
脚本将始终运行。有一件事可能会让你绊倒,那就是“旧”版本的
postrm
脚本,如果升级软件包,将在当前软件包
preinst
脚本之后运行,如果你不知道发生了什么,这可能会造成大破坏。
从dpkg手册页: 安装包括以下步骤:

          1. Extract the control files of the new package.

          2.  If  another version of the same package was installed before
          the new installation, execute prerm script of the old package.

          3. Run preinst script, if provided by the package.

          4. Unpack the new files, and at the same time back  up  the  old
          files, so that if something goes wrong, they can be restored.

          5.  If  another version of the same package was installed before
          the new installation, execute the postrm script of the old pack‐
          age.  Note that this script is executed after the preinst script
          of the new package, because new files are written  at  the  same
          time old files are removed.

          6.  Configure the package. 

          Configuring consists of the following steps:

          1.  Unpack  the  conffiles, and at the same time back up the old
          conffiles, so that they can be restored if something goes wrong.

          2. Run postinst script, if provided by the package.

这是一个已经解决的老问题,但在我看来,公认的解决方案并非完全正确,我认为有必要向像我一样有同样问题的人提供信息

详细说明调用preinst和postinst文件时使用的所有参数

详细介绍了安装和卸载流程

观察以下情况下发生的情况:

apt获取安装包 -它运行preinst install,然后运行postinst configure

apt获取删除包 -执行postrm remove,包将被设置为“配置文件”

要使软件包实际处于“未安装”状态,必须使用:

apt获取清除包


这是我们下次安装软件包时运行preinst installpostinst configure的唯一方法。

Ah,根据Debian Policy Manual第6.5节的规定,它看起来像是preinst与
configure
install
一起运行。Debian安全手册实际上讨论了“preinst或postinst”,因此它们的示例必须针对preinst。我会试着重新安排。啊哈!现在这是有道理的。如果您已经在preinst中执行了其他取决于所创建用户的操作,请在preinst中执行。否则postinst的$1=配置分支。根据我对/var/lib/dpkg/info/*的快速扫描,大多数软件包似乎都是这样做的。postinst可能自2012年以来有所改变,但我认为安装后会运行
postinst
s,可能只是在特定情况下。我在Debian服务器上安装phpMyAdmin,虽然安装成功,但由于其
postinst
脚本,安装失败。这导致
倾向于认为它没有正确安装。一旦我调整了
/var/lib/dpkg/info/phpmyadmin.postinst
,它就工作了。另外,我的系统有277个postinst
s,只有75个preinsts,在我看来,安装后运行脚本比删除后更受欢迎。也许这只是一个维护不当的软件包。我不完全清楚你在这里说的“安装
命令”是什么意思,但如果它能帮助任何人澄清问题,
dpkg
永远不会用$1=
install
upgrade
调用postinst脚本。如果您愿意,没有什么可以阻止您在postinst中支持额外的操作,但是dpkg不会使用它们。原始问题中发布的脚本不起作用,因为它希望使用其中一个脚本调用。也许这是fpm的错?“我不知道,”保罗说,“我以为我很清楚
install命令调用configure选项
。具体来说,它将调用带有
configure
postinst
脚本和包的
version
,例如
configure 6.4.0
(以我的经验,打包我自己的软件)
          1. Extract the control files of the new package.

          2.  If  another version of the same package was installed before
          the new installation, execute prerm script of the old package.

          3. Run preinst script, if provided by the package.

          4. Unpack the new files, and at the same time back  up  the  old
          files, so that if something goes wrong, they can be restored.

          5.  If  another version of the same package was installed before
          the new installation, execute the postrm script of the old pack‐
          age.  Note that this script is executed after the preinst script
          of the new package, because new files are written  at  the  same
          time old files are removed.

          6.  Configure the package. 

          Configuring consists of the following steps:

          1.  Unpack  the  conffiles, and at the same time back up the old
          conffiles, so that they can be restored if something goes wrong.

          2. Run postinst script, if provided by the package.