From Fedora Project Wiki
(add the remaining packages using each solution)
(drop the other solutions, improve documentation, reformat)
Line 1: Line 1:
{{Draft}}
{{Draft}}


== Motivation ==
== Existing guideline ==
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.
None.
 
== Proposal ==
Following change to Packaging Guidelines is proposed: Add a section '''Use of alternatives''' which would read:


== Solutions ==
== 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 <code>/usr/sbin/sendmail</code>).


All of the options below are currently used in Fedora packages.
If a package is using alternatives, the files which would otherwise conflict must be installed with an appropriate suffix (for example: <code>%{_sbindir}/sendmail.postfix</code> instead of <code>%{_sbindir}/sendmail</code>), 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.


=== Ignoring alternativized files ===
=== Examples ===
Pros:
* less work for packager(?)


Cons:
Example from antlr.spec:
* alternativized files are unowned, which means:
<pre>
** rpm -qf /usr/bin/foo doesn't work
Requires(post): %{_sbindir}/update-alternatives
** yum install /usr/bin/foo doesn't work
Requires(postun): %{_sbindir}/update-alternatives
** repoquery --whatprovides /usr/bin/foo doesn't work
...
%post
%{_sbindir}/update-alternatives --install %{_bindir}/antlr \
  %{name} %{_bindir}/antlr-java 10


Packages using this solution:
%postun
* emacs
if [ $1 -eq 0 ] ; then
* fedora-usermgmt
  %{_sbindir}/update-alternatives --remove %{name} %{_bindir}/antlr-java
* gcin
fi
* gridengine
...
* ibus
%files
* imsettings
...
* java-1.6.0-openjdk
%ghost %{_bindir}/antlr
* kinput2
%{_bindir}/antlr-java
* libextractor
</pre>
* mx4j
* nabi
* openmpi
* scim
* ssmtp (bad!)
* tomcat5
* uim
* unison213
* unison227
* ushare


=== Using %ghost ===
And a more complex example of alternatives invocation from sendmail.spec, slightly edited:
<pre>
<pre>
%files
%postun
if [ "$1" -ge "1" ]; then
if [ "`readlink %{_sysconfdir}/alternatives/mta`" == "%{_sbindir}/sendmail.sendmail" ]; then
%{_sbindir}/alternatives --set mta %{_sbindir}/sendmail.sendmail
fi
fi
 
%post
# 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
...
...
%ghost %{_bindir}/foo
 
%preun
if [ $1 = 0 ]; then
%{_sbindir}/alternatives --remove mta %{_sbindir}/sendmail.sendmail
fi
</pre>
</pre>


Pros:
== Motivation ==
* allows globs and generated file lists
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.
* alternativized files are owned, which means:
** rpm -qf /usr/bin/foo works
** yum install /usr/bin/foo works
** repoquery --whatprovides /usr/bin/foo works


Cons:
== Existing practice ==
* files owned by multiple packages are forbidden by [[Packaging:Guidelines#File_and_Directory_Ownership|FPG]].


Packages using this solution:
Packages using this solution:
Line 71: Line 84:
* xerces-j2
* xerces-j2


=== Using Provides: ===
Packages that need fixing:
<pre>
Provides: %{_bindir}/foo
</pre>
 
Pros:
* alternativized files are provided, which means:
** rpm -qf /usr/bin/foo works
** yum install /usr/bin/foo works
** repoquery --whatprovides /usr/bin/foo works
** can be processed by yum without downloading additional filelists even if the file lies outside common directories
 
Cons:
* unwieldy with lots of alternativized files
 
Packages using this solution:
* cups
* cups
* emacs
* esmtp
* esmtp
* exim
* exim
* fedora-usermgmt
* gcin
* gridengine
* ibus
* imsettings
* java-1.6.0-openjdk
* kinput2
* libextractor
* mx4j
* nabi
* openmpi
* postfix
* postfix
* scim
* sendmail
* sendmail
* ssmtp
* tomcat5
* uim
* unison213
* unison227
* ushare


[[Category:Packaging guidelines drafts]]
[[Category:Packaging guidelines drafts]]

Revision as of 17:58, 3 March 2009

Warning.png
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

None.

Proposal

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 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.

Examples

Example from antlr.spec:

Requires(post): %{_sbindir}/update-alternatives
Requires(postun): %{_sbindir}/update-alternatives
...
%post
%{_sbindir}/update-alternatives --install %{_bindir}/antlr \
  %{name} %{_bindir}/antlr-java 10

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

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

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

%post
# 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
...

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

Motivation

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