【问题标题】:How to create a conditional package using RPM packaging如何使用 RPM 打包创建条件包
【发布时间】:2018-10-02 12:45:33
【问题描述】:

我正在使用规范文件来创建 RPM 包。我只想打包系统上存在的那些文件。在我的%files 部分,我正在编写要包含在我的包中的文件。条件包和非条件包的包含方式如下。

%files
    %if "%is_file1_present"
    %attr (-, root, root) /location/to/file1
    %attr (-, root, root) /location/to/file2
%endif
%attr (-, root, root) /location/to/file3
%attr (-, root, root) /location/to/file4

%is_file1_present%build 部分中定义如下。

%build
%define is_file1_present %( if [ -f /location/to/file1 ]; then echo "1" ; else echo "0"; fi )`

在尝试构建 RPM 包时,它似乎忽略了 if 条件。我做错了什么?

【问题讨论】:

标签: rpm rpmbuild rpm-spec


【解决方案1】:

有一个更简单的解决方案:

在您的安装部分;仅复制存在的文件;并在文件部分使用通配符:

%install
install -d -m 0755 "${RPM_BUILD_ROOT}/location/to"
cp file* ${RPM_BUILD_ROOT}/location/to/

%files
%defattr(-,root,root)
/location/to/file*

注意:这可行,但这意味着您的规范文件不会总是创建相同的包,这不是很好...

【讨论】:

  • 我试过这个方法,它说“glob 找不到文件”。我只是想知道为什么 if else 语句在 %files 部分不起作用
  • 尝试修改我的答案。你可以调试一下;这应该有效;我经常使用它。您可以阅读 rpmbuild 命令的输出以查看问题所在。
  • 进行一些调整后,您的解决方案奏效了。谢谢!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多