Package: dpkg
Version: 1.10.28
Severity: normal
Tags: patch
update-alternatives --display does not support the --quiet option, which
could be used in scripts (see bug #13187).
For instance, multiple Java JDK have been installed on a computer, which
are managed by alternatives. The tomcat server needs a JAVA_HOME
environment variable to be set. This variable should be set to the base
JDK directory of the current selected Java JVM.
An option could be to define a new java_home alternative as a --slave of the
various java/javac/javah... alternatives. This solution makes
alternatives management more complex, and is only usable with this
example.
Another solution is to be able to obtain the current java alternative, in a
format usefull for shell scripting and then extract the basename directory.
At the present time, update-alternatives is too verbose and doesn't
support the --quiet option in the --display mode to be easily
scriptable (you have to parse the output).
Perhaps a better option would have been to define a
--query={status|link|priory|best} mode to extract the required
information, but the changes would be bigger and the --quiet option is
already documented and not used.
This patch adds quiet display.
It also adds error exit codes when symlinks are broken.
Example of execution:
# update-alternatives --display editor
editor - status is auto.
link currently points to /usr/bin/vim
/bin/ed - priority -100
slave editor.1.gz: /usr/share/man/man1/ed.1.gz
/bin/nano - priority 40
slave editor.1.gz: /usr/share/man/man1/nano.1.gz
/usr/bin/nvi - priority 19
slave editor.1.gz: /usr/share/man/man1/nvi.1.gz
/usr/bin/vim - priority 120
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
Current `best' version is /usr/bin/vim.
# update-alternatives --quiet --display editor
/usr/bin/vim
It's possible to simply know the best alternative from a script
without having to parse output:
1) Save the current alternative (--quiet --display)
2) Switch to auto to use the best one (--auto)
3) Display current alternative (--quiet --display)
4) Switch back to original (--set)
# diff -u update-alternatives.orig update-alternatives
--- update-alternatives.orig 2005-05-26 13:42:35.000000000 -0400
+++ update-alternatives 2005-10-27 14:13:50.537579960 -0400
@@ -11,6 +11,7 @@
# $apriority Priority of link (only when we are installing an
alternative)
# $mode action to perform (display / install / remove / display /
auto / config)
# $manual update-mode for alternative (manual / auto)
+# $verbosemode verbose (+1) or quiet (-1)
# $state State of alternative:
# expected: alternative with highest priority is the
active alternative
# expected-inprogress: busy selecting alternative with
highest priority
@@ -173,16 +174,27 @@
if ($mode eq 'display') {
if (!$dataread) {
- &pr("No alternatives for $name.");
- exit 1;
+ &pr("No alternatives for $name.")
+ if $verbosemode >= 0;
+ exit 1;
} else {
- &pr("$name - status is $manual.");
+ &pr("$name - status is $manual.")
+ if $verbosemode >= 0;
if (defined($linkname= readlink("$altdir/$name"))) {
- &pr(" link currently points to $linkname");
+ if ($verbosemode >= 0) {
+ &pr(" link currently points to $linkname");
+ } else {
+ &pr("$linkname");
+ exit 0;
+ }
} elsif ($! == &ENOENT) {
- &pr(" link currently absent");
+ &pr(" link currently absent")
+ if ($verbosemode >= 0);
+ exit 1;
} else {
- &pr(" link unreadable - $!");
+ &pr(" link unreadable - $!")
+ if $verbosemode >= 0;
+ exit 1;
}
$best= '';
for ($i=0; $i<=$#versions; $i++) {
-- System Information:
Debian Release: 3.1
Architecture: i386 (i686)
Kernel: Linux 2.6.8-2-686-smp
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Versions of packages dpkg depends on:
ii dselect 1.10.28 a user tool to manage Debian packa
ii libc6 2.3.2.ds1-22 GNU C Library: Shared libraries an
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]