Score:3

How to catch the exit codes coming from preinst file while installing debian package?

cn flag

I am trying to install a debian package on my box , through a shell script , i.e in the shell script I am giving the dpkg -i command . Internally there is a preinst file which is being used . Now in this file one of the condition is failing , let's say when x=0 I am exiting with exit 2

I want that whatever exit code that preinst file is exiting with , I should be able to catch that exit code and in my install.sh file, I will do a print statement based on it

Problem is when I am doing echo $? it always gives me 1 , stating that dpkg installation failed , but that specific return code I am not getting . Is there any way to this , Thanks in Advance

Score:1
cn flag

I am assuming that some condition is not met in preinst file of the deb package. I think it would be better to move the checks from preinst to the wrapper script i.e. install.sh file.

eg:

#!/bin/bash

if [ "$x" -eq "0" ]; then
   echo Check x = 0 failed
   exit 1;
fi
#Put all other such checks here...

dpkg -i package.deb

This is assuming you can modify preinst and installer.sh!

This blog on install wrapper is a good 10-15 min read!

Key Point from blog:

Install wrappers are usually required for one of the following reasons (not limited to these):

  1. Pre / Post-requisites
  2. Pre / Post scripting, e.g: delete a file / shortcut, create a registry key
  3. Pre-install condition checking, e.g: correct OS, correct computer name (or part of name)
  4. Check the version of an installed pre-requisite, e.g: version of MS Office
  5. Check if a user is logged on
  6. Check if a program is in use by the user, e.g: in the event of an upgrade
ThunderBird avatar
ru flag
One day, link issues may occur between this site and the blog you referred to in your answer. Could you please highlight the vital steps here if not all?
Atharva Ranade avatar
cn flag
Thanks for the suggestion!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.