Saturday, February 26, 2022

[SOLVED] Rpm building and spec file for single script

Issue

I need to copy init script to /etc/init.d/ and copy others scripts to /opt//. But I would like to do it as RPM package.

I found tutorial to deploy singe file. Please check it: href="http://computernetworkingnotes.com/package-management/build-a-simple-rpm-that-packages-a-single-file.html" rel="nofollow">rpm single file tutorial

Can you explain me %install section ? What does $RPM_BUILD_ROOT refer on, if installed script is in /opt/sample_rpm and not in $RPM_BUILD_ROOT/opt/sample_rpm ?


Solution

$RPM_BUILD_ROOT is a "virtual root directory". That is when you build a RPM package you need to form a complete layout of the package, with all paths like /usr/lib/, /etc/, or as in your case /opt/<package>/. But since an ordinary user doesn't have permissions to create files in those system directories (and this is good indeed!) one should create the file system hierarchy under $RPM_BUILD_ROOT which usually resides in a temporary directory like /tmp/<mypackage>-buildroot or something similar:

So a packager creates $RPM_BUILD_ROOT/etc/, $RPM_BUILD_ROOT/usr/lib and so on and then places all the files for the package into those directories.

Some RPM variants require explicit BuildRoot: <somepath> header in the spec to set $RPM_BUILD_ROOT to a non-empty value, while other (including e.g. recent specs from Fedora/RedHat) have this header set implicitly.

All the operations to create package layout are performed in %install section of the spec, and actually %install is simply a shell script, you may do what you would usually do to create a set of files.

Then you need to specify all the files placed under $RPM_BUILD_ROOT in the %files section, this time without $RPM_BUILD_ROOT!

See e.g. this spec for Lua to understand how the things are performed. All those %{_bindir} %{_libdir} and other rpm macros are just a portable replacements for /usr/bin, /usr/lib/ etc directories. This approach allows for example to put x86-64 libraries under /usr/lib64, x86-32 ones - under /usr/lib and this all done from the same spec.



Answered By - user3159253
Answer Checked By - Cary Denson (WPSolving Admin)