3

I have created a deb package say abc.deb. Now there are few dependencies like python-dev, python-mysql etc., which are needed to be installed as a part of deb installation itself.

(i.e. when user runs dpkg -i abc.deb, the dependencies should also get installed automatically).

I am using a control file which contains few parameters like preinst, postinst etc. I tried to add Depends to the control file, but I guess, Depends only stops package installation if dependencies mentioned are not present. How could I install the dependencies as a part of deb package installation itself? I am looking for a solution that will work on Ubuntu 12.04.

P.S. When I try to install dependencies in my postinst script as

sudo apt-get install python-dev -y

I gives me an error:

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) 
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?`
exAres
  • 4,806
  • 16
  • 53
  • 95

3 Answers3

1

You can't do this through dpkg; that's what apt-get is for. If you specify the dependencies properly in your .deb control files, then install with apt-get, it will install them automatically for you. You shouldn't be trying to call the higher-level tool from the lower-level one. By that time, it's too late.

BRPocock
  • 13,638
  • 3
  • 31
  • 50
  • Hi @BRPocock, thanks a lot for your reply. What if I do not wish to install the dependencies, but would want to let the user know what error is and then revert the installed packages (i.e. something effective to `dpkg -r abc.deb` so that my apt-get will remain clean)? – exAres Apr 07 '14 at 14:06
  • Just list them as dependencies. `dpkg` will give an informative error; `apt-get` will offer to install them. The user decides whether to do so. – BRPocock Apr 13 '14 at 04:15
1

dpkg can only install single packages.

You should declare all your package's dependencies in the Depends field of the control file.

If your user then installs the package with dpkg -i package.deb, they will get a message that dependencies are missing. The user can then invoke apt-get -f install to fix missing dependencies from the package repository (this assumes that your dependencies actually are in the official repositories).

An alternative is to use a tool such as gdebi to install your package; gdebi knows how to fetch missing dependencies, making the apt-get -f install step unnecessary.

My advice is to ship your package.deb file (with proper dependency declaration) to your users, and advise them to install it with gdebi.

Sigi
  • 1,784
  • 13
  • 19
0

The way I achieved this is by using the preinst script. This script executes before that package will be unpacked from its Debian archive (".deb") file.

I checked for the dependencies in preinst script and then exited with an error if dependencies were not found. Following sample sh code shows how to check and install dependencies if unavailable :

  dpkg -s "python-pip" >/dev/null 2>&1 && {
    echo "python-pip is installed."
    echo
  } || {
    echo "ERROR: python-pip is not installed."
    //you may install python-pip here if you wish
  }

Then this script is provided to Preinst: parameter of control file.

exAres
  • 4,806
  • 16
  • 53
  • 95
  • This is bad advice. "preinst" hooks are not supposed to install other packages. The package needs to declare `Depends:`. – Sigi Apr 28 '14 at 04:41