Installing RPM doesn't run all the %install ac

2019-08-20 05:37发布

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?

3条回答
Melony?
2楼-- · 2019-08-20 05:45

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}

查看更多
Deceive 欺骗
3楼-- · 2019-08-20 05:50

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.

查看更多
神经病院院长
4楼-- · 2019-08-20 05:51

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.

查看更多
登录 后发表回答