User Tools

Site Tools


packages:alternatives

alternatives

update-alternatives - maintain symbolic links determining default commands.

Default implementation in PLD Linux is provided by alternatives package from chkconfig.

switching alternative

By default alternatives uses auto mode picking the “best” alternative.

TODO: how to enforce sysadmin preference

integrating

from phar-php example:

Requires:      alternatives
...
 
%install
...
# touch for ghost
%{__rm} $RPM_BUILD_ROOT%{_bindir}/phar
touch $RPM_BUILD_ROOT%{_bindir}/phar
 
%post phar
update-alternatives \
       --install %{_bindir}/phar phar %{_bindir}/phar%{ver_suffix}.phar %{ver_suffix} \
       --slave %{_mandir}/man1/phar.1 phar.1 %{_mandir}/man1/phar%{ver_suffix}.1* || :
 
%postun phar
if [ $1 -eq 0 ]; then
       update-alternatives --remove phar %{_bindir}/phar || :
fi
 
...
%files
...
%ghost %{_bindir}/phar
%ghost %{_mandir}/man1/phar.1
  1. add Requires: alternatives to runtime deps
  2. the path must be ghost and regular file, otherwise rpm will complin about file-conflicts
  3. use --install to setup the symlinks in package %post scriptlet.
  4. the --slave option is optional and may be repeated, use if you wish to “group” alternatives
  5. use proper %postun to remove alternative on package uninstall

Currently it remains unclear how to handle optional files, as for above example:

  1. %{_mandir} path can be missing if %_excludedocs is set
  2. %{_mandir} path could be .gz compressed or not, it's currently solved with a glob: %{_mandir}/man1/phar%{ver_suffix}.1*

packages/alternatives.txt · Last modified: 2016-02-01 06:25 by glen