TL;DR;
If somebody installs my deb package with sudo dpkg -i example.deb, is there a way to add some custom actions (shell commands, similar to postinst) in case of installation with failed dependencies (as the package is actually unpacked and present on the target machine)?
Suppose a deb package has some UI dependencies, but the target machine is Ubuntu server.
Running sudo dpkg -i example.deb leads to
(Reading database ... 59708 files and directories currently installed.)
Preparing to unpack ./example.deb ...
Unpacking example (13) over (11) ...
dpkg: dependency problems prevent configuration of example:
example depends on libappindicator1; however:
Package libappindicator1 is not installed.
dpkg: error processing package example (--install):
dependency problems - leaving unconfigured
Processing triggers for mime-support (3.64ubuntu1) ...
Errors were encountered while processing:
example
The result is - extracted package (I can find the content in /opt), the exit code is 1 (echo $?), but the postinst script is not executed. The software can work without its UI, so this is not a big deal (until I create two separate installers - one with UI and one - without).
The problem is that I have some important steps in the postinst script, but it's not executed at all.
Maybe I need to have some kind of rollback procedure or a way to handle such errors, but I wasn't able to find any way to do this, although it sounds trivial.
An alternative approach would be to execute the required steps after unpacking and before dependency reslution, but I didn't find anything like this as well.
Obviously, I'm missing something fundamental here. Any ideas?
Edit: even more, if the missing package is later present, the installation is also incomplete / broken, as postinst was never actually executed.
As this sounds pretty straight forward, I guess there's an easy solution about this, which I can't find.
sudo dpkg -i example.debbut e.g.sudo gdebi example.deb: Then the dependencies are also installed. – Knud Larsen Apr 27 '20 at 13:58