RPM: loading bash script in %pre scriptlet

旧时模样 提交于 2020-01-01 18:09:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31321890/rpm-loading-bash-script-in-pre-scriptlet

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