[英]How to install dependencies while creating a .deb installer?
I have created a deb
package say abc.deb
. 我创建了一个
deb
包,说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. 现在有很少的依赖项,如
python-dev, python-mysql
等,需要作为deb安装本身的一部分安装。
(ie when user runs dpkg -i abc.deb
, the dependencies should also get installed automatically). (即当用户运行
dpkg -i abc.deb
,依赖项也应自动安装)。
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. 我正在使用一个
control
文件,其中包含一些参数,如preinst, postinst
等。我试图将Depends
添加到控制文件中,但我想,如果不存在依赖关系,则Depends
仅停止包安装。 How could I install the dependencies as a part of deb package installation itself? 我如何安装依赖项作为deb软件包安装本身的一部分? I am looking for a solution that will work on
Ubuntu 12.04
. 我正在寻找一个适用于
Ubuntu 12.04
的解决方案。
PS When I try to install dependencies in my postinst
script as PS当我尝试在我的
postinst
脚本中安装依赖项时
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?`
You can't do this through dpkg
; 你不能通过
dpkg
这样做; that's what apt-get
is for. 这就是
apt-get
的用途。 If you specify the dependencies properly in your .deb
control files, then install with apt-get
, it will install them automatically for you. 如果在
.deb
控制文件中正确指定依赖项,然后使用apt-get
安装,它将自动为您安装它们。 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. dpkg
只能安装单个包。
You should declare all your package's dependencies in the Depends
field of the control file. 您应该在控制文件的
Depends
字段中声明所有包的依赖项。
If your user then installs the package with dpkg -i package.deb
, they will get a message that dependencies are missing. 如果您的用户随后使用
dpkg -i package.deb
安装该软件包,则会收到缺少依赖项的消息。 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). 然后,用户可以调用
apt-get -f install
,以修复丢失从包库的依赖关系(这里假设你的依赖实际上是在官方仓库)。
An alternative is to use a tool such as gdebi
to install your package; 另一种方法是使用
gdebi
等工具来安装包装; gdebi
knows how to fetch missing dependencies, making the apt-get -f install
step unnecessary. gdebi
知道如何获取缺少的依赖项,使apt-get -f install
步骤apt-get -f install
不必要。
My advice is to ship your package.deb
file (with proper dependency declaration) to your users, and advise them to install it with gdebi
. 我的建议是将您的
package.deb
文件(带有适当的依赖声明)发送给您的用户,并建议他们使用gdebi
安装它。
The way I achieved this is by using the preinst
script. 我实现这一点的方法是使用
preinst
脚本。 This script executes before that package will be unpacked from its Debian archive (".deb") file. 此脚本在从Debian存档(“.deb”)文件解压缩该包之前执行。
I checked for the dependencies in preinst
script and then exited with an error if dependencies were not found. 我检查了
preinst
脚本中的依赖项,如果找不到依赖项,则退出并显示错误。 Following sample sh code shows how to check and install dependencies if unavailable : 以下示例sh代码显示了如果不可用,如何检查和安装依赖项:
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. 然后将此脚本提供给
Preinst:
控制文件的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.