RPM conditional Requires in spec file possible

前端 未结 2 567
旧巷少年郎
旧巷少年郎 2021-01-21 06:23

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

2条回答
  •  [愿得一人]
    2021-01-21 07:12

    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

提交回复
热议问题