How to install dependencies while creating a .deb installer?

ε祈祈猫儿з 提交于 2019-12-07 12:12:28

问题


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?`

回答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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/22907113/how-to-install-dependencies-while-creating-a-deb-installer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!