问题
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
- How can I break the execution of
%pre
from my macro? - Is it possible to return a value from the macro and store them in a variable during
%pre
?
回答1:
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.
来源:https://stackoverflow.com/questions/31341189/rpm-returning-values-from-included-rpm-macro