简体   繁体   English

安装RPM不会运行.spec中列出的所有%install操作。

[英]Installing RPM doesn't run all the %install actions listed in .spec

TL;DR: I made a .spec file that successfully builds a .rpm , but rpm -i <file>.rpm doesn't do all the actions I think it should. TL; DR:我制作了一个.spec文件,该文件成功构建了.rpm ,但是rpm -i <file>.rpm并没有执行我认为应该执行的所有操作。 Why? 为什么?

Excerpt from <file>.spec : 摘录自<file>.spec

%install
sudo python2.7 -m pip install 'tornado<5'
...#other pip commands...
cp -r $RPM_BUILD_DIR/%{name}-%{version}/* %{buildroot}

(I know this isn't the ideal way to do it, but I'm forced to use CentOS 6 and can't upgrade the system version of python because corporate/shared environment so this was the best way I could figure out.) (我知道这不是理想的方法,但是由于公司/共享环境,我被迫使用CentOS 6并且无法升级python的系统版本,所以这是我能想到的最佳方法。)

All the commands under %install are correctly run when building the .rpm , so all of the pip packages get installed on the machine creating the .rpm from the .spec . 生成.rpm%install下的所有命令都可以正确运行,因此所有pip软件包都将安装在从.spec创建.rpm.spec rpmbuild -ba <file>.spec completes with exit 0 . rpmbuild -ba <file>.spec exit 0 However, when I try to install the .noarch.rpm file that is created (on another system with identical OS/architecture), all that happens is the rpm-specified dependencies get installed and the files get shoved to the correct directories, but the other commands from %install are not run. 但是,当我尝试安装创建的.noarch.rpm文件(在具有相同OS /体系结构的另一个系统上)时,所有发生的事情是安装了rpm指定的依赖项,并将文件推到了正确的目录,但是%install中的其他命令未运行。 What ends up happening is that I try to call the executable that gets made and it errors out because of the missing python packages. 最终发生的事情是,我尝试调用生成的可执行文件,并且由于缺少python软件包而出错。

RPM.org says: RPM.org说:

Performing any tasks required before the install: 执行安装前所需的所有任务:

There are cases where one or more commands must be given prior to the actual installation of a package. 在某些情况下,必须在实际安装软件包之前发出一个或多个命令。 RPM performs these commands exactly as directed by the package builder, thus eliminating a common source of problems during installations. RPM完全按照软件包构建器的指示执行这些命令,从而消除了安装过程中常见的问题根源。

...Where am I supposed to specify the commands run prior to package installation if not in the %install field of the .spec file? ...如果不在.spec文件的%install字段中,我应该在哪里指定在安装软件包之前运行的命令?

If you want to run commands after the rpm is installed the, you need to place those commands in the %post target. 如果要在安装rpm之后运行命令,则需要将这些命令放在%post目标中。

If you want the commands to be run right before the rpm itself is installed, place the commands in the %pre target. 如果要在安装rpm本身之前立即运行命令,请将命令放在%pre目标中。

The commands in %install is executed when you build the .rpm, it is not run when you install the .rpm. %install的命令在生成.rpm时执行,而在安装.rpm时不会运行。

%install is intended to install your software onto a sandboxed directory hierarchy which should then be packaged and included into the .rpm file. %install旨在将软件安装到沙盒目录层次结构中,然后将其打包并包含在.rpm文件中。

Don't run commands in %install that alters any system state or that affects anything outside the $RPM_BUILD_DIR or %{buildroot} 不要在%install中运行会更改任何系统状态或影响$ RPM_BUILD_DIR或%{buildroot}之外的任何内容的命令

The %install scriptlet is run during build, not while installing. %install scriptlet在构建过程中运行,而不是在安装过程中运行。

If you wish commands to be run while installing a package, then you need to use the %post section in the spec file. 如果希望在安装软件包时运行命令,则需要使用spec文件中的%post部分。

As others noted, %install is the script section within a specfile to copy the files that have already been compiled during the %build phase (which can be a no-op for python). 就像其他人指出的那样, %install是specfile中的脚本部分,用于复制 %build阶段(对于python而言,它是no-op)已经编译的文件。 However, others have not yet noted that sudo python2.7 -m pip install 'tornado<5' is definitely not a command that you should be using in a specfile. 但是,其他人尚未注意到sudo python2.7 -m pip install 'tornado<5'绝对不是您应该在specfile中使用的命令。 You need to get the python files some other way and install them into the proper locations under %{buildroot} . 您需要以其他方式获取python文件,并将它们安装到%{buildroot}下的正确位置。

RPMs should never be built as the root user nor call sudo anywhere . RPM 绝对不能以root用户身份建立,也不能在任何地方调用sudo EVER. EVER。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM