RPM: returning values from included RPM macro

泪湿孤枕 提交于 2019-12-02 05:55:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!