Reputation: 4101
This is a follow-up question to RPM: loading bash script in %pre scriptlet.
I am trying to define some utility functions as macros, so later I can %include
them when building other RPM packages too. Let's say I want to have a function testfunc()
which I want use to check if something is present on the target system. If the condition is unmet, I want to break the execution of my RPM %pre
scriptlet.
Things I've tried:
Defining a bash function in the macro
common.spec
%define importfunction() (testfunc() { echo "Cancelling installation!" ; exit 1 ; })
package.spec
%include SPECS/common.spec
...
%pre
%importfunction
testfunc
RPM install output
testfunc: command not found
Exiting directly from macro
common.spec
%define testfunc() (echo "Cancelling installation!" ; exit 1)
package.spec
%include SPECS/common.spec
...
%pre
%testfunc
echo "Installation still running :("
RPM install output
Cancelling installation!
Installation still running :(
The problem is that the %pre
scriptlet is not exiting in this case.
Questions
%pre
from my macro?%pre
?Upvotes: 2
Views: 1080
Reputation: 80911
Stop wrapping the macro body in ()
.
That's spawning a sub-shell and preventing the function from being seen in the first case and preventing the exit
from exiting the %pre
scriptlet itself in the second case.
Upvotes: 2