How to install dependencies while creating a .deb installer?

痞子三分冷 提交于 2019-12-05 22:39:35

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.

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.

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.

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