openSUSE:Packaging Multiple Version guidelines

Jump to: navigation, search


Even if the standard behavior of RPM is to update a single package always to the highest version, it is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time.

For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice of editor to invoke if the user has not specified a particular preference. Therefore, some standards can and should be defined, so programs can fall back to these standards.

Package naming

For different versions of the same software, heed openSUSE:Package_naming_guidelines#Multiple_packages_for_the_same_software.

Maintain default commands and libraries

update-alternatives mechanism

The update-alternatives package creates, removes, maintains and displays information about the symbolic links comprising the alternatives system. A packager can use this package to define default applications in a running system without getting in conflict with other packages.

Name:           vim
Requires(post): update-alternatives
Requires(postun): update-alternatives

%install
# create a dummy target for /etc/alternatives/vim
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
ln -s -f %{_sysconfdir}/alternatives/vim %{buildroot}%{_bindir}/vim

%post
update-alternatives --install \
   %{_bindir}/vim vim %{_bindir}/vim-normal 15

%post enhanced
update-alternatives --install \
   %{_bindir}/vim vim %{_bindir}/vim-enhanced  20

%postun
if [ ! -f %{_bindir}/vim-normal ] ; then
   update-alternatives --remove vim %{_bindir}/vim-normal
fi

%postun enhanced
if [ ! -f %{_bindir}/vim-enhanced ] ; then
   update-alternatives --remove vim %{_bindir}/vim-enhanced
fi

%files
%_bindir/vim-normal
%_bindir/vim
%ghost %_sysconfdir/alternatives/vim

%files enhanced
%_bindir/vim-enhanced
%_bindir/vim
%ghost %_sysconfdir/alternatives/vim

In this example, if vim-enhanded is selected, the link chain will be: /usr/bin/vim -> /etc/alternatives/vim -> /usr/bin/vim-enhanced. The link marked in italics is provided by the package itself.

The update-alternatives priority handling does not update the file list if the priorities are same before and after. In case you update the list of slaves or change path for the file you should bump the priority.

%postun section if construction is needed for the following reason : If the package is being uninstalled, the tested file does not exist in the %postun phase anymore. We want to remove the update-alternatives entry.
However, if the package is being upgraded, the file still exists and in this case we do not want to remove the entry, because the installation in %post is already done.

We used to write the check as if [ $1 -eq 0 ], using RPM's feature for upgrade detection. This would however do the wrong thing when the upgrading package is a renamed version. Testing for existence of the file is safer.

In a case where the file is dynamically changed during the updates you should keep the dynamic content part of the priority instead of static number

# wrong
update-alternatives --install %{_bindir}/python python %{_bindir}/python-%{py_ver} 20
#right
update-alternatives --install %{_bindir}/python python %{_bindir}/python-%{py_ver} $(echo %{py_ver} | sed 's/\.//g')