Thursday, June 03, 2010

Managing /etc/alternatives (Updated 2017-06-09)

A number of applications are configured by default to invoke the sendmail application to send mail messages. Sendmail is, of course, the iconic UNIX command to send mail. But in many cases, sendmail is overkill and most systems provide a default lightweight command, /bin/mail, that can be used instead. Another alternative is Ssmtp.

There are alternative applications for many standard applications. After all, what UNIX programmer can't think of a better or different way of doing something? But how is that choice of alternatives easily managed on a Linux system? In the old days, the sysadmin installed the alternative application and created a symlink to the alternative application in place of the expected default application, for example symlinking /bin/mail to /usr/bin/sendmail.

But the update-alternatives method provides better control, in theory at least.

My problem was that the default installation of Mandriva Linux (as of Mandriva-2010) did not provide such a choice. I filed a bug report about it since it should be an available choice from a base installation. If you install any application and intend to use it as an alternative, but it does not show up as an available choice, look at my bug report for an example one one that will be accepted as complete and then report your own experience as a bug. Here's how I added it manually and how you can add any alternative to your system.

The alternative links themselves are kept in /etc/alternatives. To see if any alternatives are available for a command, enter:
# update-alternatives --list
If the choice you seek is not listed, you may add it manually, using /bin/mail as an example, by entering:
# update-alternatives --install /etc/alternatives/sendmail-command sendmail-command /bin/mail 1

Two things of note here. For unexplained reasons, sendmail is identified as sendmail-command. The priority number helps order your choices and sets the default; the higher the number, the higher the priority. I assigned priority 1 to /bin/mail because it is the least powerful of all the choices that there could be.

To select among possible choices, enter:
# update-alternatives --config sendmail-command
Which provides the following response:

There are 2 programs which provide `sendmail-command'.

Selection Command
+ 1 /usr/sbin/ssmtp
2 /bin/mail

Enter to keep the default[*], or type selection number:

And I chose 2.

While there is a man page with a good description of all the options, a lot of information is contained within /usr/sbin/update-alternatives itself since it is a perl script.

UPDATE, 2017-06-09

Mageia 6 is almost ready to be released. I submitted a bug request long ago to have /etc/alternatives include /bin/mail as an alternative to sendmail. Not only have they not done that, but if you have any other mail agent installed (like ssmtp which is required for the google-chrome browser, it states that the primary command for sendmail-command must be /usr/sbin/sendmail.

To work around this idiocy, you must first remove ssmtp, which poses a problem because it is required by the package lsb-core-noarch. Oh, well, it's rpm to the rescue:

# rpm -evh --nodeps ssmtp

Then, the above works to redirect sendmail-command to /bin/mail.

UPDATE 2017-07-19

Mageia6 not forbids using /bin/mail as an alternative to sendmail-command, it installs postfix by default. So  . . .

# rpm -evh --nodeps postfix

and manually replace the symlink in /etc/alternatives with one pointing to /bin/mail.

No comments: