RPM: loading bash script in %pre scriptlet

穿精又带淫゛_ 提交于 2019-12-04 17:03:26

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.

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