如何故意将包配置一半?
How to intentionally leave a package half configured?
我正在尝试测试与半配置包相关的 Wazuh 配置。所以,我正在尝试创建一个 .deb
包,它在安装时将配置一半。
我开始关注 these instructions 创建一个非常简单、什么都不做的包。
我尝试将 debian/postinst.ex
的退出代码更改为 1,但无论如何安装包都成功了。
我尝试将一个不存在的文件添加到 debian/conffiles
,但是 debuild
失败了。
我还到处搜索有关可能导致包配置一半的信息,但运气不佳。
谢谢!
首先,我想提一下安装失败的包有两种不同的状态:
- 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 "" 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 \`'" >&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)
然后,您可以使用 dpkg 上的 -s
标志来检查软件包状态:
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
希望对您有所帮助:)
我正在尝试测试与半配置包相关的 Wazuh 配置。所以,我正在尝试创建一个 .deb
包,它在安装时将配置一半。
我开始关注 these instructions 创建一个非常简单、什么都不做的包。
我尝试将 debian/postinst.ex
的退出代码更改为 1,但无论如何安装包都成功了。
我尝试将一个不存在的文件添加到 debian/conffiles
,但是 debuild
失败了。
我还到处搜索有关可能导致包配置一半的信息,但运气不佳。
谢谢!
首先,我想提一下安装失败的包有两种不同的状态:
- 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 "" 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 \`'" >&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)
然后,您可以使用 dpkg 上的 -s
标志来检查软件包状态:
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
希望对您有所帮助:)