User:Allan/Alternatives

From ArchWiki
Jump to navigation Jump to search

The Idea

Provide an alternatives system to allow users to select which package provides a file.

Current Situation

'/usr/bin/sh' is a symlink to 'bash'. People may want to use a different shell interpreter for 'sh', e.g. 'dash', but this is currently not possible without rebuilding the bash package to remove the symlink first.

Proposal

makepkg

An alternative would be specified in a PKGBUILD as:

 alternative=('usr/bin/sh->usr/bin/bash')

If full path is not specified, binary and symlink are assumed to be in '/usr/bin', so this is equivalent

 alternative=('sh->bash')

Makepkg would add this information to the .PKGINFO file:

 alternative = sh->usr/bin/bash

TODO bikeshed the separator

pacman

On installation of a package with a specified alternative, there are two options. Check if the alternative symlink is there and

1) if not present, create the symlink

or

2) if present, do "nothing".

  • Should also issue a warning if the alternative symlink is not pointing to another file with the same alternative.
  • output notification like optdepends?


New pacman option examples

List all alternatives from installed packages

 pacman -A
   python ->
      usr/bin/python3  (python3 3.7.2-3)
      usr/bin/python3.6  (python3 3.6.7-1)
   sh ->
      usr/bin/bash  (bash 5.0.002-1)
      usr/bin/dash  (dash 0.5.10.2-1)

List installed alternatives for a given command

 pacman -A sh
   usr/bin/bash  (bash 5.0.002-1)
   usr/bin/dash  (dash 0.5.10.2-1)

Update alternative by package (print error if mismatch):

 pacman -Au sh dash
   sh -> /usr/bin/dash

Update alternative by path (print error if mismatch):

 pacman -Au sh /usr/bin/dash
   sh -> /usr/bin/dash

Other options requiring behaviour changes

pacman -Si <pkg>
pacman -Qi <pkg>    - also note whether alternative is active
pacman -Qo <alternative>
pacman -Ql <pkg>

Also?

pacman -F...