Tuesday, April 19, 2022

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

Issue

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?


Solution

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}



Answered By - nos
Answer Checked By - Dawn Plyler (WPSolving Volunteer)