Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RPM spec file - Is it possible to dynamically populate a spec file variable

I have a spec file. I need to %define a spec variable that gets its value from a one line file on the system.

For example

%define path `cat /home/user/path_file` 

and in path_file is one line

/var/www/html/hosts 

This partially works. I say that begins in the RPM BUILD output sometimes the value of ${path} is literally my command cat /home/user/path_file and sometimes the value is the line in the path_file (/var/www/html/hosts) as it should be?

like image 483
last_shogun Avatar asked Apr 19 '12 18:04

last_shogun


People also ask

What is spec file in RPM?

What is a SPEC File? A SPEC file can be thought of as the "recipe" that the rpmbuild utility uses to actually build an RPM. It tells the build system what to do by defining instructions in a series of sections. The sections are defined in the Preamble and the Body.

What is the .spec file?

Spec files are plain-text files that are used to construct spec strings. They consist of a sequence of directives separated by blank lines. The type of directive is determined by the first non-whitespace character on the line, which can be one of the following: % command. Issues a command to the spec file processor.

What are sources in RPM build directory?

The RPMS directory is where the newly created binary package files are written. The SOURCES directory contains the original sources, patches, and icon files. The SPECS directory contains the spec files for each package to be built.


1 Answers

You can define rpmbuild variables with %(cmd) at the top of the spec file. Notice the command is in parenthesis, not curly brackets. An example:

%define whoami %(whoami) 

And elsewhere in the spec file, such as a script or the build/install sections, use the variable as normal in the curly brackets like this:

echo "The user that built this is %{whoami}" 

The cmd can be anything, including your cat command. Be careful - when another user rebuilds the spec file it may not find the file. So it'll be preferable to use the %{sourcedir} macro like this:

%define path %(cat %{sourcedir}/path_file) 

And make sure that path_file is in the source directory and included as a source in the spec file.

like image 158
Corey Henderson Avatar answered Sep 19 '22 15:09

Corey Henderson