I've put some common utility scripts into common.sh
, which I want to use in my RPM specfile during %pre
. common.sh
is located in the root of the RPM package.
What I was planning to do is simply call something like source common.sh
, but how can I access common.sh
from the RPM during %pre
?
I was able to solve this using RPM macros, the following way:
Before doing rpmbuild
I have put common.spec
into the SPECS
folder.
common.spec
%define mymacro() (echo -n "My arg is %1 " ; sleep %1 ; echo done.)
I've added %include SPECS/common.spec
as the first line of my actual spec file.
Usage example
%pre
%mymacro 5
My arg is 5 done.
Multi-line macros
Pretty fragile syntactically imo, but you can put line breaks into your macros using \
. That will tell the RPM builder that it should continue parsing the macro. Given the previous macro as an example:
%define mymacro() (echo -n "My arg is %1 " ; \
sleep %1 ; \
echo done.)
This way the code will be still parsed back into a single line, hence the ;
on the first and second line.