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

三世轮回 提交于 2019-12-13 03:55:43

问题


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. Why?

Excerpt from <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.)

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. rpmbuild -ba <file>.spec completes with 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. 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.

RPM.org says:

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.

...Where am I supposed to specify the commands run prior to package installation if not in the %install field of the .spec file?


回答1:


If you want to run commands after the rpm is installed the, you need to place those commands in the %post target.

If you want the commands to be run right before the rpm itself is installed, place the commands in the %pre target.

The commands in %install is executed when you build the .rpm, it is not run when you install the .rpm.

%install is intended to install your software onto a sandboxed directory hierarchy which should then be packaged and included into the .rpm file.

Don't run commands in %install that alters any system state or that affects anything outside the $RPM_BUILD_DIR or %{buildroot}




回答2:


The %install scriptlet is run during build, not while installing.

If you wish commands to be run while installing a package, then you need to use the %post section in the spec file.




回答3:


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). 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. You need to get the python files some other way and install them into the proper locations under %{buildroot}.

RPMs should never be built as the root user nor call sudo anywhere. EVER.



来源:https://stackoverflow.com/questions/52899765/installing-rpm-doesnt-run-all-the-install-actions-listed-in-spec

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