6

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.

ulidtko
  • 14,740
  • 10
  • 56
  • 88
user3520053
  • 61
  • 1
  • 2
  • You could also use rpm trigger scriptlets, if the options in my answer are not sufficient. Those are not that widely documented, but they are widely used in distributions. See http://rpm.org/api/4.4.2.2/triggers.html which covers a few examples with an explanations how the triggers are implemented. Overall ordering is shown at https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Scriptlet_Ordering – doktor5000 Dec 11 '15 at 13:32

2 Answers2

3

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
%endif

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 https://web.archive.org/web/20160513021804/http://rpm.org/wiki/DynamicDependencies

For more details on the %pre/%post and other scriptlets see e.g. https://fedoraproject.org/wiki/Packaging:ScriptletSnippets

doktor5000
  • 181
  • 6
  • 10
  • I'm pretty sure `%fi` should be `%endif`---or at least, my version of `rpmbuild` didn't like that. – KJ7LNW Jun 13 '22 at 21:07
  • @KJ7LNW That's obviously correct, typed that just from memory - corrected now, thanks :) – doktor5000 Jun 14 '22 at 16:31
  • 1
    Wiki link to rpm.org is broken as of Nov 2022. Not sure what to replace it with. – Nemo Nov 02 '22 at 01:13
  • 1
    @Nemo thanks for the hint, replaced it with the most recent archive.org snapshot as there seems to be no replacement for this anywhere else. Depending on your rpm implementation you can also search for "weak dependencies" as those differ between the rpm version used. – doktor5000 Nov 02 '22 at 15:48
0

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

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39
  • Check out my answer to [this similar question](http://stackoverflow.com/questions/12212712/can-some-specific-autodetected-dependency-be-ignored-upon-rpmbuild) for a script that can filter out things for you. – Aaron D. Marasco Apr 12 '14 at 01:03