beginner RPM about %install and rpmbuild -bb
I am a bit confused about the install step of building a binary RPM. I think that the install step is designed to be run when the user installs the binary package, the .rpm.
I am trying to package a repository on gitlab. This package is very simple, compiling and installing one .so
To build the package, I do:
rpmbuild -bb ~/rpmbuild/SPECS/libinput-config.spec
The process runs the %install section of the spec file.
This upstream package does install via meson, hence I have
%install
%meson_install
The upstream's install process copies the compiled .so to a certain location, and then runs a script called preload.sh
The script hard-codes one path, seen in the PRELOAD variable:
#!/bin/sh
LIB="${1}/${2}.so"
PRELOAD='/etc/ld.so.preload'
if test -z $(grep ${LIB} ${PRELOAD} 2> /dev/null); then
echo ${LIB} >> ${PRELOAD}
fi
When I run rpmbuild -bb ~/rpmbuild/SPECS/libinput-config.spec
it fails with a permission problem because it is executing the preload.sh
script. I don't mind the permission problem, because I don't think doing rpmbuild -bb
should be actually installing anything on my system.
But it means that I don't understand when the %install
section is supposed to do.
I expected building a binary package with -bb to do the build process of the upstream package, arriving at the .so, and then collect that and store it in the binary.
Then, when the user installs the package, rpm will run the install process, using the contents of the binary rpm.
Why does rpmbuild -bb
try to run the %install section?
EDIT It seems that I should change the custom meson install script to do this:
PRELOAD="${DESTDIR}/etc/ld.so.preload"
meson makes sure that DESTDIR is in the env of custom sripts, and it seems the rpm macro %meson_install sets up this variable.
and I must create the etc
directory in buildroot
%install
mkdir -p $RPM_BUILD_ROOT/etc
%meson_install
Solution 1:
I think that the install step is designed to be run when the user installs the binary package, the .rpm.
The %install
section doesn't run when .rpm is installed. It runs during build of RPM. It's a phase of the build rather. In there you have commands which install files to the $RPM_BUILD_ROOT
which is more or a less a temporary directory where you install the files during build.
Subsequently, you have the %files
section where you list the files to be packaged into the actual .rpm. Those files are the ones installed to the RPM build root in the %install
phase.
You want to run a program/script when .rpm is installed by the end-user. Scriplets are meant for this.
%post
if [ $1 == 1 ];then
/path/to/preload.sh arg1 arg2 ...
fi