如何使用 RPM 打包创建条件包
How to create a conditional package using RPM packaging
我正在使用规范文件创建 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 条件。我做错了什么?
有一个更简单的解决方案:
在您的安装部分;只复制存在的文件;并在文件部分使用通配符:
%install
install -d -m 0755 "${RPM_BUILD_ROOT}/location/to"
cp file* ${RPM_BUILD_ROOT}/location/to/
%files
%defattr(-,root,root)
/location/to/file*
注意:这可行,但这意味着您的规范文件不会总是创建相同的包,这不是很好...
我正在使用规范文件创建 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 条件。我做错了什么?
有一个更简单的解决方案:
在您的安装部分;只复制存在的文件;并在文件部分使用通配符:
%install
install -d -m 0755 "${RPM_BUILD_ROOT}/location/to"
cp file* ${RPM_BUILD_ROOT}/location/to/
%files
%defattr(-,root,root)
/location/to/file*
注意:这可行,但这意味着您的规范文件不会总是创建相同的包,这不是很好...