How to intentionally leave a package half configured?

1.4k Views Asked by At

I'm trying to test Wazuh configuration related to half-configured packages. So, I'm trying to create a .deb package that will end up half configured when installed.

I started by following these instructions for creating a dirt-simple, do-nothing package.

I tried changing the exit code of debian/postinst.ex to 1, but the package installed successfully anyway.

I tried adding a non-existing file to debian/conffiles, but debuild failed.

I've also searched all over for information on the things that can cause a package to be left half configured, without any luck.

Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

First of all, I want to mention that there are two different status for failed installed packages:

  • half-configured: The package is unpacked and configuration has been started, but not yet completed for some reason.
  • half-installed: The installation of the package has been started, but not completed for some reason.

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

If you want a half-configured package, then the package must be unpackaged and it is the configuration step the one that should fail.

Now, if you follow the guide you shared with us, you may have missed the part where it says that the *.ex files are examples and are not introduced in the package so if you're modifying the file postinst.ex, these changes will no take effect.

You can remove all the *.ex files and create your own postinst file. For example I've used this one:

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

Using this file (with the correct name), your code will be executed after the package installation. And you will get something like this:

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)

Then, you could use the -s flag on dpkg to check the package status:

root@ubuntu:/tmp/build# dpkg -s greetings
Package: greetings
Status: install ok half-configured
Priority: optional
Section: unknown
Installed-Size: 14
Maintainer: Person McTester <[email protected]>
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>

As you can see, as the package has no way to handle this kind of error, the package is still installed and its status is install ok half-configured

I hope this has helped you :)