openSUSE:Removing update-alternatives support
Removing update-alternatives support
The following guide describes the steps necessary to remove update-alternatives
from a given spec file.
This is the first step towards a migration from update-alternatives
to any other technical solution we have at the moment.
It’s documented separately as it’s a prerequisite for these other solutions.
Remove the dependencies on update-alternatives
As we won’t be requiring update-alternatives
anymore, we must remove any mention of it from the dependencies.
Anything such as the following should be removed:
BuildRequires: update-alternatives Requires: update-alternatives BuildRequires(post): update-alternatives Requires(post): update-alternatives BuildRequires(postun): update-alternatives Requires(postun): update-alternatives Suggests: update-alternatives Recommends: update-alternatives
Remove the symlinks update-alternatives
requires in the %install
section
As update-alternatives
requires a certain symlink structure to work properly, and these are typically defined in the %install
section, we must remove them.
The following example was taken from the transmission
package, adapt as needed.
The %install
script would be creating the following structure:
# this is the directory that controls which alternatives are currently chosen/selected # the script creates this directory as it may not have been previously created by another package, just to be sure mkdir /etc/alternatives # this creates the symlink that will act as the regular executable (/usr/bin/transmission) # it's linked back to /etc/alternatives/transmission so that by changing that symlink, we indirectly control # what /usr/bin/transmission invokes, when executed ln -s -f /etc/alternatives/transmission %{buildroot}/usr/bin/transmission # and the same applies to the man page ln -s -f /etc/alternatives/transmission.1.gz %{buildroot}/usr/share/man/man1/transmission.1.gz
So basically just delete these lines. But make sure you understand what’s happening, of course.
%install mkdir -p %{buildroot}%{_sysconfdir}/alternatives ln -s -f %{_sysconfdir}/alternatives/transmission \ %{buildroot}/%{_bindir}/transmission ln -s -f %{_sysconfdir}/alternatives/transmission.1.gz \ %{buildroot}/%{_mandir}/man1/transmission.1.gz
Again, this example is from the transmission
package, adapt as needed.
These scripts won’t be required anymore, as there will be no more state (symlinks and files) related to update-alternatives
on the filesystem anymore.
Basically, each subpackage (-qt
, -gtk
, -cli
, etc) will have its own %post
and %postun
scripts. These register the alternative when the package is installed, and remove it when it is uninstalled. As we won’t be using update-alternatives
anymore, there’s no sense in keeping these scripts in the spec file.
This is from the transmission-cli
subpackage, from the same spec file. Notice the priority 5 here. We’ll be keeping this same priority if we migrate to libalternatives
. We don’t want to lose that priority, so make a note if you plan on migrating to libalternatives.
%post update-alternatives \ --install %{_bindir}/transmission transmission \ %{_bindir}/transmission-cli 5 \ --slave %{_mandir}/man1/transmission.1.gz transmission.1.gz \ %{_mandir}/man1/transmission-cli.1.gz %postun # Note: we don't use "$1 -eq 0", to avoid issues if the package gets renamed if [ ! -f %{_bindir}/transmission-cli ]; then update-alternatives --remove transmission %{_bindir}/transmission-cli fi
And this is from the transmission-gtk
subpackage, from the same spec file. Notice the priority 15 here. We’ll be keeping this same priority if we migrate to libalternatives
.
%post update-alternatives \ --install %{_bindir}/transmission transmission \ %{_bindir}/transmission-gtk 15 \ --slave %{_mandir}/man1/transmission.1.gz transmission.1.gz \ %{_mandir}/man1/transmission-gtk.1.gz %postun gtk # Note: we don't use "$1 -eq 0", to avoid issues if the package gets renamed if [ ! -f %{_bindir}/transmission-gtk ]; then update-alternatives --remove transmission %{_bindir}/transmission-gtk fi
Adjust the %files
section
We must now remove the related files from the %files
section.
For any subpackage that lists the structure in its %files
section, we simply delete those lines:
%ghost %{_sysconfdir}/alternatives/%{name} # executable %ghost %{_sysconfdir}/alternatives/%{name}.1.gz # man page
As a reminder, for each subpackage, these lines would have been expanded as follows:
# -cli subpackage %ghost /etc/alternatives/transmission # executable %ghost /etc/alternatives/transmission.1.gz # man page # -gtk subpackage %ghost /etc/alternatives/transmission # executable %ghost /etc/alternatives/transmission.1.gz # man page
Decide on a migration strategy for the package
The package should now be free from update-alternatives
. We have:
- Removed its dependencies on the
update-alternatives
package. - Removed the initial filesystem structure creation in the
%install
section. - Removed all of its
%post
and%postun
scripts related toupdate-alternatives
. - Removed all the related files from the
%files
section.
Naturally, the next step that follows is deciding what to do with the package next.
Here are the solutions we currently support:
- Migrating to libalternatives by leveraging the
alts
package. - Migrating to libalternatives through a custom executable.
- Migrating to a conflict-based implementation