RPM conditional Requires in spec file possible

2019-07-21 04:33发布

As the subject reads, I wonder whether it is possible in the RPM spec file to make required packages dependent on a condition?

For instance check in a shell statement if on the install target e.g. the host is using bonding interfaces and only if have the Require become effective.

标签: rpm-spec
2条回答
女痞
2楼-- · 2019-07-21 04:52

No. You can hand modify the Requires line and turn off autodetection, and then handle what is optional as needed.

查看更多
不美不萌又怎样
3楼-- · 2019-07-21 05:13

As an answer to your original question - Yes this is possible, but what you can implement depends what you want to use as a condition, and those are written to the package during build-time of the package, not during installation. You could easily do something in the .spec like

%if some_condition_is_true
Requires: foo
%else
Requires: bar
%fi

Question is, how much sense does that make, and what is your particular use case?

For what you described, that is not possible in that way, as you cannot change the package during install-time. You have a few options for your scenario:

  • create two versions of your package, one for bonding, one for hosts without
  • separate the part that is necessary for bonding hosts in a subpackage, and only install that on the hosts that need it
  • put the logic for the bonding hosts in a %pre/%post script, so that it only runs conditionally.
  • use some virtual requires, which are fulfilled by multiple packages, and then add some config on the host which gives priority to the package you need, the one for bonding or for no bonding. But that is highly distro-specific ...

For more details on conditional/dynamic macros which are mostly available since rpm.org v4.12 see http://www.rpm.org/wiki/DynamicDependencies
For more details on the %pre/%post and other scriptlets see e.g. https://fedoraproject.org/wiki/Packaging:ScriptletSnippets

查看更多
登录 后发表回答