假设我有一个
rpm.spec
脚本,可以构建 MyRPM.rpm
包:
-- MyRPM.rpm 的 rpm.spec
%define logdir %{my_dir}/logs/%{name}
Summary: bla bla bla
Name: MyRPM
Version: @@@version@@@
Release: @@@revision@@@
License: bla
Group: Applications/System
Requires: That-Other-RPM
%description
This is my RPM
%prep
%build
%install
doSomething //invoking a function
那里的
Requires
参数应该会触发That-Other-RPM
的安装过程。假设 doSomething
函数在 That-Other-RPM
中声明,我可以从 MyRPM 的 rpm.spec
调用它吗,因为它会触发另一个函数?
-- That-Other-RPM.rpm 的 rpm.spec
%define logdir %{my_dir}/logs/%{name}
Summary: bla bla bla
Name: That-Other-RPM
Version: @@@version@@@
Release: @@@revision@@@
License: bla
Group: Applications/System
%description
This is that other RPM
%prep
%build
%install
function doSomething {
//doing something here
}
不,你不能。
规范文件部分中的函数仅在定义它们的脚本中可用。
您的 RPM 和其他 RPM 之间没有共享 shell 会话。
这并不完全是问题的解决方案,但它解决了如何在多个
%post
或 %postun
scriptlet 在同一规范文件中使用函数的问题:
诀窍是将函数定义为宏(是的,它很丑!):
%define FOO \
foo()\
{\
echo blabla\
echo soso\
}
#...
%post
%FOO
foo
# ...
%postun
%FOO
foo
# ...
因此 %FOO
定义了该函数,并且
foo
调用它。