0

I build my own package and I need to check something on the system before the install process.

So in my dpkg I add a preinst script which is written as follow. As an example I want to check if the arduino-cli command is available:

echo 'Check arduino cli install ...'
if ! command -v arduino-cli &> /dev/null
then
   exit 0
fi

The postinst script seems to be execute. Here is the result of the dpkg execution:

....
dpkg: error processing archive myserver-server_0_amd64.deb (--install):
...

How can I stop the other script ? I thought the exit command should work. https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html

bird12358
  • 39
  • 6
  • 1
    It is ugly and not done for such things. I think you should consider to reframe your problem and solve it properly. `arduino-cli` should come from a package, so just depend your package from such arduino package. Else you are abusing the system, so you never know if it will work on all cases (e.g. you can always `force` ignoring errors). `exit 0` will just exit the script without errors. Just exit with an error if you want to let caller known you raise an error – Giacomo Catenazzi Jun 22 '22 at 12:02
  • Thank you for the answer. What do you mean by exit "Just exit with and error". I try to replace with "exit 1" an error occurded but the other post scripts are still running. – bird12358 Jun 22 '22 at 13:06
  • Yes. Each package is independent. You are trying to do something that should not be done by packaging software. And personally I find no reason to do what you are trying to do. For this reason I asked you to reconsider, and try a different way (in other words, I think it is XY problemL you have a problem, but you are trying to solve in the wrong place). – Giacomo Catenazzi Jun 23 '22 at 06:33
  • As an aside, `&>` is not available in `sh` scripts; you want `>/dev/null 2>&1` – tripleee Jul 16 '22 at 05:43

1 Answers1

1

Agreed with what was said in comments.

Stopping an installation is not the way to go, instead assist the user at the maximum in order to install your package correctly.

Why asking people to install things manually while you can automate it?

Thus:

  • Add the dependency to the debian/control file

OR

  • Add curl dependency to the debian/control file
  • Modify your existing code to install arduino-cli by using
    if ! command -v arduino-cli &> /dev/null
    then
       curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
    fi
Arnaud F.
  • 8,252
  • 11
  • 53
  • 102