openSUSE:Migrating-to-libalternatives
Migrating to libalternatives
This page describes how to perform the migration from update-alternatives to libalternatives. For now, only the simplest scenario is documented here. But updates will be on their way, once more packages have been migrated.
Basically, we need to:
Remove all files related to update-alternatives from the package.
Remove all dependencies related to update-alternatives from the package.
Remove any
%post
,%pre
,%postun
or%preun
hooks that may be related toupdate-alternatives
.Ensure there is either a hard dependency on the
alts
package, or that an equally suitable custom binary is provided instead, by linking tolibalternatives.so.1
.4.1. If you opt for the
alts
route, then the package’s main executable binary must be a symlink toalts
.4.2. If you opt to provide a custom binary, then check how the
nodejs-common
package does it: nodejs-common.Create the appropriate priority/preferences files, located in
/usr/share/libalternatives
. These files specify both the package’s actual target binary, as well as its man pages.
To exemplify this process, the next section explains how the transmission
package was migrated.
How transmission
was migrated
The transmission
package falls into the following category: it’s a fairly simple package with binaries and man pages, but no other binary files are managed via any alternatives. Only the binaries and the man pages. So it’s a very trivial migration. A single spec file provides the transmission
, transmission-common
, transmission-daemon
, transmission-gtk
and transmission-qt
packages.
For a full diff regarding this migration, please check it here.
We removed all mentions of the
update-alternatives
package from the spec file. This includes any dependency declarations, comments, etc.We removed all files whose only purpose was to adhere to the filesystem conventions specified by
update-alternatives
. So, no files in/etc/alternatives
, and no symlinks pointing to/etc/alternatives
.We also removed any
%post
,%pre
,%postun
or%preun
hooks that were related toupdate-alternatives
.The
transmission-common
package now requiresalts
. As all other packages requiretransmission-common
,alts
will always be pulled as a dependency. Just in case, we madetransmission
,transmission-gtk
andtransmission-qt
requirealts
explicitly./usr/bin/transmission
is a symlink to/usr/bin/alts
. This is why there’s a dependency onalts
, it is the binary that will check the appropriate priority files and invoke the correct binary based on them.Each individual package (
transmission-gtk
,transmission-qt
,transmission
) creates its own priority file in/usr/share/libalternatives/transmission
.6.1. The priority file’s name must be a number which indicates that alternative’s priority. For instance, the priority file for
transmission-gtk
is named/usr/share/libalternatives/transmission/15.conf
. The priority file fortransmission-qt
is named/usr/share/libalternatives/transmission/10.conf
. So,transmission-gtk
has priority 15, andtransmission-qt
has priority 10.
For reference, here is the priority file for transmission-gtk
:
binary=/usr/bin/transmission-gtk man=transmission-gtk.1
And for transmission-qt
:
binary=/usr/bin/transmission-qt man=transmission-qt.1