首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在RPM规范文件中使操作系统依赖的需求部分

在RPM规范文件中使操作系统依赖的需求部分
EN

Unix & Linux用户
提问于 2022-01-24 15:06:29
回答 2查看 856关注 0票数 2

Situation

我有一个RPM,在安装后和卸载前阶段使用semanage (SELinux策略管理工具)和restorecon (SELinux上下文配置工具)。

不幸的是,在RHEL 6/7和8之间,包含这些工具的包从policycoreutils-python重命名为policycoreutils-python-utils

RHEL8 RPM的工作规范文件包含:

代码语言:javascript
复制
Requires(post): policycoreutils-python-utils
Requires(preun): policycoreutils-python-utils

RHEL6 6/7 RPM的工作规范文件包含:

代码语言:javascript
复制
Requires(post): policycoreutils-python
Requires(preun): policycoreutils-python

我想要实现的

我可以使用两个规范文件/两个RPM,每个OS类型都有一个,但是我很懒,我想要一个可以满足所有功能的规范。

我试过什么

我读到了包含OS版本的OS条件%{rhel}。根据“RPM手册”,以下内容应该有效:

代码语言:javascript
复制
%if %{rhel} < 8
Requires(post): policycoreutils-python
Requires(preun): policycoreutils-python
%endif 

%if %{rhel} == 8
Requires(post): policycoreutils-python-utils
Requires(preun): policycoreutils-python-utils
%endif

如果我检查目标系统上的%{rhel}变量的值,就会得到我期望的结果:

代码语言:javascript
复制
centos7-system» rpm --eval '%{rhel}'
7

centos8-system» rpm --eval '%{rhel}'
8

在CentOS 6/7实例上安装此RPM很好。但是,在CentOS 8实例上安装与操作系统无关的RPM时,我得到:

代码语言:javascript
复制
centos8-system» dnf install my-1.26-0.x86_64.rpm
<...>
Error:
 Problem: conflicting requests
  - nothing provides policycoreutils-python needed by my-1.26-0.x86_64

调试输出:

代码语言:javascript
复制
centos8-system» rpm -ivvvh my-1.26-0.x86_64.rpm 2>&1 | grep Requires
D:  Requires: /bin/bash                                     YES (db files)
D:  Requires: /bin/sh                                       YES (db files)
D:  Requires: /bin/sh                                       YES (cached)
D:  Requires: /bin/sh                                       YES (cached)
D:  Requires: /usr/bin/env                                  YES (db files)
D:  Requires: /usr/bin/perl                                 YES (db files)
D:  Requires: /usr/bin/php                                  YES (db files)
D:  Requires: nagios-plugins                                NO
D:  Requires: perl(Getopt::Long)                            YES (db provides)
D:  Requires: perl(strict)                                  YES (db provides)
D:  Requires: policycoreutils-python                        NO
D:  Requires: policycoreutils-python                        NO  (cached)
D:  Requires: policycoreutils-python                        NO
D:  Requires: rpmlib(CompressedFileNames) <= 3.0.4-1        YES (rpmlib provides)
D:  Requires: rpmlib(FileDigests) <= 4.6.0-1                YES (rpmlib provides)
D:  Requires: rpmlib(PayloadFilesHavePrefix) <= 4.0-1       YES (rpmlib provides)
D:  Requires: rpmlib(PayloadIsXz) <= 5.2-1                  YES (rpmlib provides)

似乎使用的是用于Requires 6/7场景的CentOS,而不是来自CentOS 8场景的CentOS。

我在这里看不到什么?我能做些什么来调试这个吗?

相关与源

EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2022-01-27 14:21:06

您可以省略条件并依赖于语义exectutable,而不是policycoreutils-python包:

代码语言:javascript
复制
Requires(post): %{_sbindir}/semanage
Requires(post): %{_sbindir}/restorecon

有关示例,请参阅Fedora的dokuwiki.spec。依赖于包的一个例子是bdii.spec

票数 1
EN

Unix & Linux用户

发布于 2022-02-02 15:28:22

规范文件中的条件在构建期间进行计算。因此,当您的SPEC文件包含:

代码语言:javascript
复制
%if %{rhel} < 8
Requires(post): policycoreutils-python
%endif 

%if %{rhel} == 8
Requires(post): policycoreutils-python-utils
%endif

你在RHEL 7上构建你的软件包,然后它就会有

代码语言:javascript
复制
Requires(post): policycoreutils-python

即使你在RHEL 8上安装了你的软件包,这个要求也会被使用。它不会在软件包构建后被重新评估。

如果您只想要一个二进制包,那么就需要Andreas指出的文件库所需的文件。企业解决方案是使用

代码语言:javascript
复制
Release: 1%{?dist}
...
%if %{rhel} < 8
Requires(post): policycoreutils-python
Requires(preun): policycoreutils-python
%endif 

%if %{rhel} == 8
Requires(post): policycoreutils-python-utils
Requires(preun): policycoreutils-python-utils
%endif

并使用以下方法为不同的平台构建它:

代码语言:javascript
复制
mock -r epel-7-x86_64 my.src.rpm
mock -r epel-8-x86_64 my.src.rpm

第一个命令生成my-1.0-1.el7并要求policycoreutils-python,而第二个命令生成my-1.0-1.el8并需要policycoreutils-python-utils

作为边注,条件应写成:

代码语言:javascript
复制
%if 0%{?rhel} < 8

若要防止未定义宏时出现语法错误,请执行以下操作。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/687719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档