RPM conditional Requires in spec file possible

╄→гoц情女王★ 提交于 2019-12-20 03:17:10

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/22991975/rpm-conditional-requires-in-spec-file-possible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!