[csw-maintainers] Alternatives

Maciej (Matchek) Blizinski maciej at opencsw.org
Sun Dec 6 14:48:15 CET 2009


On Sat, Dec 5, 2009 at 7:50 PM, Maciej (Matchek) Blizinski
<maciej at opencsw.org> wrote:
> Let's suppose functionality baz provided by either foo
> or bar.  We want to type "baz" and have the job done.  However, in
> some cases we want to use foo or bar specifically.  How do we handle
> that?

Here's an idea: reuse somebody else's work!

We start with no symlink.

netra ~ # ls -l /opt/csw/bin/sudo*
-rwsr-xr-x   1 root     bin       221736 Oct  5 19:26 /opt/csw/bin/sudoedit
-rwxr-xr-x   1 root     bin       245232 Oct  5 19:30 /opt/csw/bin/sudo.ldap
-rwsr-xr-x   1 root     bin       221736 Oct  5 19:26 /opt/csw/bin/sudo.minimal

Let's tell the alternatives system that we've got something called
'sudo' which is provided by sudo.minimal.

netra ~ # update-alternatives --install /opt/csw/bin/sudo sudo
/opt/csw/bin/sudo.minimal 40
update-alternatives: using /opt/csw/bin/sudo.minimal to provide
/opt/csw/bin/sudo (sudo) in auto mode.
netra ~ # ls -l /opt/csw/bin/sudo*
lrwxrwxrwx   1 root     root          30 Dec  6 14:41
/opt/csw/bin/sudo -> /etc/opt/csw/alternatives/sudo
-rwsr-xr-x   1 root     bin       221736 Oct  5 19:26 /opt/csw/bin/sudoedit
-rwxr-xr-x   1 root     bin       245232 Oct  5 19:30 /opt/csw/bin/sudo.ldap
-rwsr-xr-x   1 root     bin       221736 Oct  5 19:26 /opt/csw/bin/sudo.minimal

The alternatives system has chosen the best alternative, the highest
priority number.  (A bit counterintuitive direction.)  Let's see what
/etc/opt/csw/alternatives/sudo points at.

netra ~ # ls -l /etc/opt/csw/alternatives/sudo
lrwxrwxrwx   1 root     root          25 Dec  6 14:41
/etc/opt/csw/alternatives/sudo -> /opt/csw/bin/sudo.minimal

We can now add the ldap-enabled version of sudo:

netra ~ # update-alternatives --install /opt/csw/bin/sudo sudo
/opt/csw/bin/sudo.ldap 20

Let's see what the alternatives system says about sudo now.

netra ~ # update-alternatives --display sudo
sudo - auto mode
 link currently points to /opt/csw/bin/sudo.minimal
/opt/csw/bin/sudo.ldap - priority 20
/opt/csw/bin/sudo.minimal - priority 40
Current `best' version is /opt/csw/bin/sudo.minimal.

It has chosen the implementation based on priority.  Let's try to
modify it by hand.

netra ~ # update-alternatives --config sudo
There are 2 choices for the alternative sudo (providing /opt/csw/bin/sudo).

  Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /opt/csw/bin/sudo.minimal   40        auto mode
  1            /opt/csw/bin/sudo.ldap      20        manual mode
  2            /opt/csw/bin/sudo.minimal   40        manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /opt/csw/bin/sudo.ldap to provide
/opt/csw/bin/sudo (sudo) in manual mode.

...and see where the symlink points to now.

netra ~ # ls -l /opt/csw/bin/sudo*
lrwxrwxrwx   1 root     root          30 Dec  6 14:44
/opt/csw/bin/sudo -> /etc/opt/csw/alternatives/sudo
-rwsr-xr-x   1 root     bin       221736 Oct  5 19:26 /opt/csw/bin/sudoedit
-rwxr-xr-x   1 root     bin       245232 Oct  5 19:30 /opt/csw/bin/sudo.ldap
-rwsr-xr-x   1 root     bin       221736 Oct  5 19:26 /opt/csw/bin/sudo.minimal

This symlink hasn't changed, but...

netra ~ # ls -l /etc/opt/csw/alternatives/sudo
lrwxrwxrwx   1 root     root          22 Dec  6 14:44
/etc/opt/csw/alternatives/sudo -> /opt/csw/bin/sudo.ldap

This one now points at sudo.

Thoughts?

Maciej



More information about the maintainers mailing list