0

我正在尝试测试与半配置包相关的 Wazuh 配置。所以,我正在尝试创建一个.deb安装后最终配置一半的包。

我首先按照这些说明创建了一个非常简单、什么都不做的包。

我尝试将退出代码更改debian/postinst.ex为 1,但软件包仍然安装成功。

我尝试向 中添加一个不存在的文件debian/conffiles,但debuild失败了。

我还搜索了所有可能导致包配置一半但没有任何运气的信息。

谢谢!

4

1 回答 1

1

首先,我想提一下,安装失败的包有两种不同的状态:

  • half-configured:解包并开始配置,但由于某种原因尚未完成。
  • half-installed:包的安装已经开始,但是由于某种原因没有完成。

来源:https ://www.man7.org/linux/man-pages/man1/dpkg.1.html

如果您想要一个半配置的包,则必须解包该包,并且配置步骤应该失败。

现在,如果您按照与我们共享的指南进行操作,您可能会错过说明*.ex文件是示例且未在包中引入的部分,因此如果您正在修改文件postinst.ex,这些更改将不会生效。

您可以删除所有*.ex文件并创建自己的postinst文件。例如我用过这个:

root@ubuntu:/tmp/build/greetings-0.1# cat debian/postinst 
#!/bin/sh
# postinst script for greetings
#
# see: dh_installdeb(1)

set -e

case "$1" in
    configure)
        echo "configuring..."
        sleep 1
        echo "..."
        sleep 2
        echo "ERROR!"
        exit 1
    ;;

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

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


# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

使用此文件(使用正确的名称),您的代码将在包安装后执行。你会得到这样的东西:

root@ubuntu:/tmp/build# apt-get install ./greetings_0.1-1_all.deb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'greetings' instead of './greetings_0.1-1_all.deb'
The following NEW packages will be installed:
  greetings
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/2916 B of archives.
After this operation, 14.3 kB of additional disk space will be used.
Get:1 /tmp/build/greetings_0.1-1_all.deb greetings all 0.1-1 [2916 B]
Selecting previously unselected package greetings.
(Reading database ... 76875 files and directories currently installed.)
Preparing to unpack .../build/greetings_0.1-1_all.deb ...
Unpacking greetings (0.1-1) ...
Setting up greetings (0.1-1) ...
configuring...
...
ERROR!
dpkg: error processing package greetings (--configure):
 installed greetings package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 greetings
E: Sub-process /usr/bin/dpkg returned an error code (1)

然后,您可以使用-sdpkg 上的标志来检查包状态:

root@ubuntu:/tmp/build# dpkg -s greetings
Package: greetings
Status: install ok half-configured
Priority: optional
Section: unknown
Installed-Size: 14
Maintainer: Person McTester <person@company.tld>
Architecture: all
Version: 0.1-1
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>
Homepage: <insert the upstream URL, if relevant>

如您所见,由于包没有办法处理这种错误,包仍然安装,它的状态是install ok half-configured

我希望这对你有帮助:)

于 2021-03-24T10:03:33.117 回答