Przeglądaj źródła

update-alternatives: improve --config behaviour

* scripts/update-alternatives.pl: Allow --config to continue when
the currently selected alternative doesn't match the only existing
one. Useful to be able to recover from a broken configuration.
Also offer the choice in --config mode to go back the automatic
mode. Add a new --skip-auto option to combine with --all and
easily review manual and broken alternatives.
* man/update-alternatives.8: Update the documentation accordingly.

Based on a patch by Osamu Aoki <osamu@debian.org>.
Raphael Hertzog 17 lat temu
rodzic
commit
c05d262a15
4 zmienionych plików z 56 dodań i 20 usunięć
  1. 11 0
      ChangeLog
  2. 2 0
      debian/changelog
  3. 9 5
      man/update-alternatives.8
  4. 34 15
      scripts/update-alternatives.pl

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2009-02-05  Raphael Hertzog  <hertzog@debian.org>
+	    Osamu Aoki <osamu@debian.org>
+
+	* scripts/update-alternatives.pl: Allow --config to continue when
+	the currently selected alternative doesn't match the only existing
+	one. Useful to be able to recover from a broken configuration.
+	Also offer the choice in --config mode to go back the automatic
+	mode. Add a new --skip-auto option to combine with --all and
+	easily review manual and broken alternatives.
+	* man/update-alternatives.8: Update the documentation accordingly.
+
 2009-02-04  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/Dpkg/Vendor/Ubuntu.pm: Ubuntu vendor object implementing

+ 2 - 0
debian/changelog

@@ -112,6 +112,8 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Add Ubuntu vendor object implementing lookup of launchpad bugs in
     changelogs and a safety-check for Maintainer fields of forked packages
     (launched during source build). Closes: #426752, #499924
+  * Improve behaviour of update-alternatives --config. Thanks to
+    Osamu Aoki <osamu@debian.org> for the initial patch.
 
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 9 - 5
man/update-alternatives.8

@@ -263,7 +263,9 @@ Remove all alternatives and all of their associated slave links.
 is a name in the alternatives directory.
 .TP
 .B \-\-all
-Call \fB\-\-config\fP on all alternatives.
+Call \fB\-\-config\fP on all alternatives. It can be usefully combined with
+\fB\-\-skip\-auto\fP to review and configure all alternatives which are
+not configured in automatic mode. Broken alternatives are also displayed.
 .TP
 \fB\-\-auto\fR \fIlink\fR
 Switch the master symlink
@@ -294,10 +296,7 @@ Display all targets of the link group.
 .TP
 \fB\-\-config\fR \fIlink\fR
 Show available alternatives for a link group and allow the user to
-interactively select which one to use. The link group is updated
-and taken out of
-.I auto
-mode.
+interactively select which one to use. The link group is updated.
 .TP
 .B \-\-help
 Show the usage message and exit.
@@ -315,6 +314,11 @@ different from the default.
 Specifies the administrative directory, when this is to be
 different from the default.
 .TP
+.BI \-\-skip\-auto
+Skip configuration prompt for alternatives which are properly configured
+in automatic mode. This option is only relevant with \fB\-\-config\fR or
+\fB\-\-all\fR.
+.TP
 .B \-\-verbose
 Generate more comments about what
 .B update\-alternatives

+ 34 - 15
scripts/update-alternatives.pl

@@ -23,6 +23,7 @@ my $verbosemode = 0;
 
 my $action = '';      # Action to perform (display / query / install / remove / auto / config)
 my $mode = 'auto';    # Update mode for alternative (manual / auto)
+my $skip = '';        # Skip alternatives properly configured in auto mode (for --config)
 my $state;            # State of alternative:
                       #   expected: alternative with highest priority is the active alternative
                       #   expected-inprogress: busy selecting alternative with highest priority
@@ -101,6 +102,8 @@ Commands:
 Options:
   --altdir <directory>     change the alternatives directory.
   --admindir <directory>   change the administrative directory.
+  --skip-auto              skip prompt for alternatives correctly configured
+                           in automatic mode (relevant for --config only)
   --verbose                verbose operation, more output.
   --quiet                  quiet operation, minimal output.
   --help                   show this help message.
@@ -190,7 +193,8 @@ sub find_best_version
 
 sub display_link_group
 {
-    pr(sprintf(_g("%s - status is %s."), $name, $mode));
+    pr(sprintf("%s - %s", $name,
+        ($mode eq "auto") ? _g("auto mode") : _g("manual mode")));
     $linkname = readlink("$altdir/$name");
 
     if (defined($linkname)) {
@@ -286,7 +290,8 @@ sub set_links($$)
 {
     my ($spath, $preferred) = (@_);
 
-    printf STDOUT _g("Using '%s' to provide '%s'.") . "\n", $spath, $name;
+    printf STDOUT _g("Using '%s' to provide '%s' in %s.") . "\n", $spath,
+                    $name, ($mode eq "auto" ? _g("auto mode") : _g("manual mode"));
     checked_symlink("$spath","$altdir/$name.dpkg-tmp");
     checked_mv("$altdir/$name.dpkg-tmp", "$altdir/$name");
 
@@ -371,6 +376,8 @@ while (@ARGV) {
     } elsif (m/^--admindir$/) {
         @ARGV || badusage(sprintf(_g("--%s needs a <directory> argument"), "admindir"));
         $admindir= shift(@ARGV);
+    } elsif (m/^--skip-auto$/) {
+	$skip = '--skip-auto';
     } elsif (m/^--all$/) {
 	$action = 'all';
     } else {
@@ -671,22 +678,29 @@ sub config_message {
 	          "Nothing to configure.\n"), $name;
 	return -1;
     }
-    if ($#versions == 0) {
+    if ($skip && $mode eq 'auto' && $best eq readlink("$altdir/$name")) {
 	print "\n";
-	printf _g("There is only 1 program which provides %s\n".
+        display_link_group();
+        return -1;
+    }
+    if ($#versions == 0 && $mode eq 'auto' && $best eq readlink("$altdir/$name")) {
+	print "\n";
+	printf _g("There is only 1 program which provides %s properly in auto mode\n".
 	          "(%s). Nothing to configure.\n"), $name, $versions[0];
 	return -1;
     }
     print STDOUT "\n";
     printf(STDOUT _g("There are %s alternatives which provide \`%s'.\n\n".
-                     "  Selection    Alternative\n".
+                     " Selection    Alternative\n".
                      "-----------------------------------------------\n"),
                   $#versions+1, $name);
+    printf STDOUT "%s        0    %s (%s)\n",
+        ($mode eq "auto" && readlink("$altdir/$name") eq $best) ? '*' : ' ',
+        $best, _g("auto mode");
     for (my $i = 0; $i <= $#versions; $i++) {
-	printf(STDOUT "%s%s %8s    %s\n",
-	    (readlink("$altdir/$name") eq $versions[$i]) ? '*' : ' ',
-	    ($best eq $versions[$i]) ? '+' : ' ',
-	    $i+1, $versions[$i]);
+	printf STDOUT "%s %8s    %s (%s) priority=%s\n",
+	    (readlink("$altdir/$name") eq $versions[$i] && $mode eq "manual") ? '*' : ' ',
+	    $i+1, $versions[$i], _g("manual mode"), $priorities[$i];
     }
     printf(STDOUT "\n"._g("Press enter to keep the default[*], or type selection number: "));
     return 0;
@@ -698,14 +712,19 @@ sub config_alternatives {
 	return if config_message() < 0;
 	$preferred=<STDIN>;
 	chop($preferred);
-    } until $preferred eq '' || $preferred>=1 && $preferred<=$#versions+1 &&
+    } until $preferred eq '' || $preferred>=0 && $preferred<=$#versions+1 &&
 	($preferred =~ m/[0-9]*/);
     if ($preferred ne '') {
-	$mode = "manual";
-	$preferred--;
-	my $spath = $versions[$preferred];
+        if ($preferred == 0) {
+	    $action = "auto";
+	    $mode = "auto";
+	} else {
+	    $mode = "manual";
+	    $preferred--;
+	    my $spath = $versions[$preferred];
 
-	set_links($spath, $preferred);
+	    set_links($spath, $preferred);
+	}
     }
 }
 
@@ -763,7 +782,7 @@ sub config_all {
     my @filenames = grep !/^\.\.?$/, readdir ADMINDIR;
     close ADMINDIR;
     foreach my $name (@filenames) {
-        system "$0 --config $name";
+        system "$0 $skip --config $name";
         exit $? if $?;
     }
 }