From Fedora Project Wiki

< PackagingDrafts

Revision as of 20:44, 7 April 2009 by Rathann (talk | contribs) (Use of alternatives: require touching the original file locations)

This page is a draft only
It is still under construction and content may change. Do not rely on the information on this page.

Existing guideline



Following change to Packaging Guidelines is proposed: Add a section Use of alternatives which would read:

Use of alternatives

Alternatives can be used to allow parallel installation of packages which provide the same functionality and can be used as a drop-in replacement (for example: the various MTAs which all provide /usr/sbin/sendmail).

If a package is using alternatives, the files which would otherwise conflict must be installed with an appropriate suffix (for example: %{_sbindir}/sendmail.postfix instead of %{_sbindir}/sendmail), the original locations must be touched (for example: touch %{_sbindir}/sendmail), the links set up by alternatives must be listed as %ghost in the file list and proper Requires: must be added, like in the examples below.

Putting the alternativized files in the file list ensures that they are owned by respective packages, which means that commands like:

  • rpm -qf /usr/bin/foo
  • yum install /usr/bin/foo
  • repoquery --whatprovides /usr/bin/foo

all work properly. Using %ghost for this purpose allows using globs and generated file lists.


Example from antlr.spec:

Requires(post): %{_sbindir}/update-alternatives
Requires(postun): %{_sbindir}/update-alternatives
touch %{_bindir}/antlr

%{_sbindir}/update-alternatives --install %{_bindir}/antlr \
  %{name} %{_bindir}/antlr-java 10

if [ $1 -eq 0 ] ; then
  %{_sbindir}/update-alternatives --remove %{name} %{_bindir}/antlr-java
%ghost %{_bindir}/antlr

And a more complex example of alternatives invocation from sendmail.spec, slightly edited:

Requires(post): %{_sbindir}/update-alternatives
Requires(postun): %{_sbindir}/update-alternatives
Requires(preun): %{_sbindir}/update-alternatives
# rename files for alternative usage
mv %{buildroot}%{_sbindir}/sendmail %{buildroot}%{_sbindir}/sendmail.sendmail
touch %{buildroot}%{_sbindir}/sendmail
for i in mailq newaliases rmail; do
	mv %{buildroot}%{_bindir}/$i %{buildroot}%{_bindir}/$i.sendmail
	touch %{buildroot}%{_bindir}/$i
mv %{buildroot}%{_mandir}/man1/mailq.1 %{buildroot}%{_mandir}/man1/mailq.sendmail.1
touch %{buildroot}%{_mandir}/man1/mailq.1
mv %{buildroot}%{_mandir}/man1/newaliases.1 %{buildroot}%{_mandir}/man1/newaliases.sendmail.1
touch %{buildroot}%{_mandir}/man1/newaliases.1
mv %{buildroot}%{_mandir}/man5/aliases.5 %{buildroot}%{_mandir}/man5/aliases.sendmail.5
touch %{buildroot}%{_mandir}/man5/aliases.5
mv %{buildroot}%{_mandir}/man8/sendmail.8 %{buildroot}%{_mandir}/man8/sendmail.sendmail.8
touch %{buildroot}%{_mandir}/man8/sendmail.8

if [ "$1" -ge "1" ]; then
	if [ "`readlink %{_sysconfdir}/alternatives/mta`" == "%{_sbindir}/sendmail.sendmail" ]; then
		%{_sbindir}/alternatives --set mta %{_sbindir}/sendmail.sendmail

# Set up the alternatives files for MTAs.
%{_sbindir}/alternatives --install %{_sbindir}/sendmail mta %{_sbindir}/sendmail.sendmail 90 \
	--slave %{_bindir}/mailq mta-mailq %{_bindir}/mailq.sendmail \
	--slave %{_bindir}/newaliases mta-newaliases %{_bindir}/newaliases.sendmail \
	--slave %{_bindir}/rmail mta-rmail %{_bindir}/rmail.sendmail \
	--slave /usr/lib/sendmail mta-sendmail /usr/lib/sendmail.sendmail \
	--slave %{_sysconfdir}/pam.d/smtp mta-pam %{_sysconfdir}/pam.d/smtp.sendmail \
	--slave %{_mandir}/man8/sendmail.8.gz mta-sendmailman %{_mandir}/man8/sendmail.sendmail.8.gz \
	--slave %{_mandir}/man1/mailq.1.gz mta-mailqman %{_mandir}/man1/mailq.sendmail.1.gz \
	--slave %{_mandir}/man1/newaliases.1.gz mta-newaliasesman %{_mandir}/man1/newaliases.sendmail.1.gz \
	--slave %{_mandir}/man5/aliases.5.gz mta-aliasesman %{_mandir}/man5/aliases.sendmail.5.gz \
	--initscript sendmail

if [ $1 = 0 ]; then
	%{_sbindir}/alternatives --remove mta %{_sbindir}/sendmail.sendmail

%ghost %{_sbindir}/sendmail
%ghost %{_bindir}/mailq
%ghost %{_bindir}/newaliases
%ghost %{_bindir}/rmail
%ghost /usr/lib/sendmail
%ghost %{_sysconfdir}/pam.d/smtp
%ghost %{_mandir}/man8/sendmail.8.gz
%ghost %{_mandir}/man1/mailq.1.gz
%ghost %{_mandir}/man1/newaliases.1.gz
%ghost %{_mandir}/man5/aliases.5.gz

%config(noreplace) %{_sysconfdir}/pam.d/smtp.sendmail

%attr(0755,root,root) %{_initrddir}/sendmail


Current usage of alternatives is inconsistent, and rpm -qf /some/file will often say the file is unowned, even if it's been created by some package, which is especially misleading and annoying in case of binaries.

Existing practice

Packages using this solution:

  • antlr
  • cdrkit
  • classpathx-jaf
  • classpathx-mail
  • ettercap
  • jakarta-commons-dbcp
  • java-1.5.0-gcj
  • OpenEXR_Viewers
  • pinentry
  • saxon
  • xalan-j2
  • xemacs
  • xerces-j2

Packages that need fixing:

  • cups
  • emacs
  • esmtp
  • exim
  • fedora-usermgmt
  • gcin
  • gridengine
  • ibus
  • imsettings
  • java-1.6.0-openjdk
  • kinput2
  • libextractor
  • mx4j
  • nabi
  • openmpi
  • postfix
  • scim
  • sendmail
  • ssmtp
  • tomcat5
  • uim
  • unison213
  • unison227
  • ushare