Ver código fonte

* scripts/update-alternatives.{pl,8}:
* Apply patch that provides --set and --remove-all commands.
* --all calls --config on all alternatives.
* scripts/update-alternatives.pl:
* Alter --config prompt, to be more clear, that one must 'press' enter to
accept the default.
* Fix some -w issues.
* Check whether the target path exists when removing.

Adam Heath 23 anos atrás
pai
commit
9e001dd46a
4 arquivos alterados com 150 adições e 17 exclusões
  1. 11 0
      ChangeLog
  2. 14 3
      debian/changelog
  3. 35 0
      scripts/update-alternatives.8
  4. 90 14
      scripts/update-alternatives.pl

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+Sun Sep 14 16:53:09 CDT 2003 Adam Heath <doogie@debian.org>
+
+  * scripts/update-alternatives.{pl,8}:
+    * Apply patch that provides --set and --remove-all commands.
+    * --all calls --config on all alternatives.
+  * scripts/update-alternatives.pl:
+    * Alter --config prompt, to be more clear, that one must 'press' enter
+      to accept the default.
+    * Fix some -w issues.
+    * Check whether the target path exists when removing.
+
 Sat Sep 13 20:48:02 CDT 2003 Adam Heath <doogie@debian.org>
 Sat Sep 13 20:48:02 CDT 2003 Adam Heath <doogie@debian.org>
 
 
   * scripts/update-alternatives.8: Add --config to action section, and add
   * scripts/update-alternatives.8: Add --config to action section, and add

+ 14 - 3
debian/changelog

@@ -10,9 +10,6 @@ dpkg (1.10.11) unstable; urgency=low
     #196361
     #196361
   * Change standard_startup and standard_shutdown into macros.  Closes:
   * Change standard_startup and standard_shutdown into macros.  Closes:
     #200351.
     #200351.
-  * Sebastian Ley <sebastian.ley@mmweg.rwth-aachen.de>:
-    Fix inversion test of $state against 'expected' when removing an
-    alternative.  Closes: #203791.
   * Andrew Suffield <asuffield@debian.org>:
   * Andrew Suffield <asuffield@debian.org>:
     Fix inverted test of eof in parsedb, while looking for eof after
     Fix inverted test of eof in parsedb, while looking for eof after
     field name.  Closes: #198218
     field name.  Closes: #198218
@@ -105,6 +102,20 @@ dpkg (1.10.11) unstable; urgency=low
     Closes: #175236
     Closes: #175236
   * Yann Dirson <dirson@debian.org>:
   * Yann Dirson <dirson@debian.org>:
     Remove disabled --command-fd from help.  Closes: #169619
     Remove disabled --command-fd from help.  Closes: #169619
+  * Tobias Burnus <tburnus@physik.fu-berlin.de>:
+    Apply patch to update-alternatives that provides --set and --remove-all
+    commands.  Closes: #133745.
+  * Osamu Aoki <debian@aokiconsulting.com>:
+    Add --all to update-alternatives, that calls --config on all
+    alternatives.  Closes: #126621
+  * Dan Jacobson <jidanni@jidanni.org>:
+    Alter --config prompt, to be more clear, that one must 'press' enter to
+    accept the default.  Closes: #203557
+  * Peter Moulder <pmoulder@bowman.csse.monash.edu.au>:
+    Fix some -w issues in update-alternatives.  Closes: #137313
+  * Eduard Bloch <edi@gmx.de>:
+    Apply patch to check whether the target path exists on removing.
+    Closes: #37254
 
 
  -- Wichert Akkerman <debian@extern.wiggy.net>  UNRELEASED
  -- Wichert Akkerman <debian@extern.wiggy.net>  UNRELEASED
 
 

+ 35 - 0
scripts/update-alternatives.8

@@ -24,6 +24,15 @@ update-alternatives \- maintain symbolic links determining default commands
 .PP
 .PP
 .B update-alternatives
 .B update-alternatives
 .RI [ options ]
 .RI [ options ]
+.B --remove-all
+.I name
+.PP
+.B update-alternatives
+.RI [ options ]
+.B --all
+.PP
+.B update-alternatives
+.RI [ options ]
 .B --auto
 .B --auto
 .I name
 .I name
 .PP
 .PP
@@ -41,6 +50,11 @@ update-alternatives \- maintain symbolic links determining default commands
 .RI [ options ]
 .RI [ options ]
 .B --config
 .B --config
 .I name
 .I name
+.PP
+.B update-alternatives
+.RI [ options ]
+.B --set
+.I name path
 .SH DESCRIPTION
 .SH DESCRIPTION
 .B update-alternatives
 .B update-alternatives
 creates, removes, maintains and displays information about the symbolic
 creates, removes, maintains and displays information about the symbolic
@@ -156,6 +170,10 @@ longer be in
 mode. You will need to use the
 mode. You will need to use the
 .I --auto
 .I --auto
 option in order to return to the automatic state.
 option in order to return to the automatic state.
+.PP
+If you want to configure non-interactivily you can use the
+.I --set
+option instead (see below).
 .SH TERMINOLOGY
 .SH TERMINOLOGY
 Since the activities of
 Since the activities of
 .B update-alternatives
 .B update-alternatives
@@ -317,6 +335,15 @@ and the newly added alternatives' priority is higher than
 any other installed alternatives for this group,
 any other installed alternatives for this group,
 the symlinks will be updated to point to the newly added alternatives.
 the symlinks will be updated to point to the newly added alternatives.
 .TP
 .TP
+\fB--set\fR \fIname path\fR
+Set the program
+.I path
+as alternative for
+.I name.
+This is equivalent to
+.IB --config
+but is non-interactive and thus scriptable.
+.TP
 \fB--remove\fR \fIname path\fR
 \fB--remove\fR \fIname path\fR
 Remove an alternative and all of its associated slave links.
 Remove an alternative and all of its associated slave links.
 .I name
 .I name
@@ -337,6 +364,14 @@ If the link is not currently pointing to
 no links are changed;
 no links are changed;
 only the information about the alternative is removed.
 only the information about the alternative is removed.
 .TP
 .TP
+\fB--remove-all\fR \fIname\fR
+Remove all alternatives and all of their associated slave links.
+.I name
+is a name in the alternatives directory.
+.TP
+.B --all
+Call \fB--config\fP on all alternatives.
+.TP
 \fB--auto\fR \fIlink\fR
 \fB--auto\fR \fIlink\fR
 Switch the master symlink
 Switch the master symlink
 .I link
 .I link

+ 90 - 14
scripts/update-alternatives.pl

@@ -1,4 +1,4 @@
-#!/usr/bin/perl --
+#!/usr/bin/perl -w --
 
 
 $admindir= "/var/lib/dpkg"; # This line modified by Makefile
 $admindir= "/var/lib/dpkg"; # This line modified by Makefile
 $dpkglibdir= "../utils"; # This line modified by Makefile
 $dpkglibdir= "../utils"; # This line modified by Makefile
@@ -39,10 +39,13 @@ version 2 or later for copying conditions.  There is NO warranty.
 Usage: update-alternatives --install <link> <name> <path> <priority>
 Usage: update-alternatives --install <link> <name> <path> <priority>
                           [--slave <link> <name> <path>] ...
                           [--slave <link> <name> <path>] ...
        update-alternatives --remove <name> <path>
        update-alternatives --remove <name> <path>
+       update-alternatives --remove-all <name>
        update-alternatives --auto <name>
        update-alternatives --auto <name>
        update-alternatives --display <name>
        update-alternatives --display <name>
        update-alternatives --list <name>
        update-alternatives --list <name>
        update-alternatives --config <name>
        update-alternatives --config <name>
+       update-alternatives --set <name> <path>
+       update-alternatives --all
 <name> is the name in /etc/alternatives.
 <name> is the name in /etc/alternatives.
 <path> is the name referred to.
 <path> is the name referred to.
 <link> is the link pointing to /etc/alternatives/<name>.
 <link> is the link pointing to /etc/alternatives/<name>.
@@ -88,12 +91,12 @@ while (@ARGV) {
         ($alink,$name,$apath,$apriority,@ARGV) = @ARGV;
         ($alink,$name,$apath,$apriority,@ARGV) = @ARGV;
         $apriority =~ m/^[-+]?\d+/ || &badusage("priority must be an integer");
         $apriority =~ m/^[-+]?\d+/ || &badusage("priority must be an integer");
         $mode= 'install';
         $mode= 'install';
-    } elsif (m/^--remove$/) {
+    } elsif (m/^--(remove|set)$/) {
         &checkmanymodes;
         &checkmanymodes;
-        @ARGV >= 2 || &badusage("--remove needs <name> <path>");
+        @ARGV >= 2 || &badusage("--$1 needs <name> <path>");
         ($name,$apath,@ARGV) = @ARGV;
         ($name,$apath,@ARGV) = @ARGV;
-        $mode= 'remove';
-    } elsif (m/^--(display|auto|config|list)$/) {
+        $mode= $1;
+    } elsif (m/^--(display|auto|config|list|remove-all)$/) {
         &checkmanymodes;
         &checkmanymodes;
         @ARGV || &badusage("--$1 needs <name>");
         @ARGV || &badusage("--$1 needs <name>");
         $mode= $1;
         $mode= $1;
@@ -111,6 +114,8 @@ while (@ARGV) {
     } elsif (m/^--admindir$/) {
     } elsif (m/^--admindir$/) {
         @ARGV || &badusage("--admindir needs a <directory> argument");
         @ARGV || &badusage("--admindir needs a <directory> argument");
         $admindir= shift(@ARGV);
         $admindir= shift(@ARGV);
+    } elsif (m/^--all$/) {
+        $mode = 'all';
     } else {
     } else {
         &badusage("unknown option \`$_'");
         &badusage("unknown option \`$_'");
     }
     }
@@ -119,8 +124,12 @@ while (@ARGV) {
 defined($aslavelink{$name}) && &badusage("name $name is both primary and slave");
 defined($aslavelink{$name}) && &badusage("name $name is both primary and slave");
 $aslavelinkcount{$alink} && &badusage("link $link is both primary and slave");
 $aslavelinkcount{$alink} && &badusage("link $link is both primary and slave");
 
 
-$mode || &badusage("need --display, --config, --install, --remove or --auto");
-$mode eq 'install' || !%slavelink || &badusage("--slave only allowed with --install");
+$mode || &badusage("need --display, --config, --set, --install, --remove, --all, --remove-all or --auto");
+$mode eq 'install' || !%aslavelink || &badusage("--slave only allowed with --install");
+
+if ($mode eq 'all') {
+    &config_all();
+}
 
 
 if (open(AF,"$admindir/$name")) {
 if (open(AF,"$admindir/$name")) {
     $manual= &gl("manflag");
     $manual= &gl("manflag");
@@ -128,7 +137,7 @@ if (open(AF,"$admindir/$name")) {
     $link= &gl("link");
     $link= &gl("link");
     while (($sname= &gl("sname")) ne '') {
     while (($sname= &gl("sname")) ne '') {
         push(@slavenames,$sname);
         push(@slavenames,$sname);
-        defined($slavenum{$sname}) && &badfmt("duplicate slave $tsname");
+        defined($slavenum{$sname}) && &badfmt("duplicate slave $sname");
         $slavenum{$sname}= $#slavenames;
         $slavenum{$sname}= $#slavenames;
         $slink= &gl("slink");
         $slink= &gl("slink");
         $slink eq $link && &badfmt("slave link same as main link $link");
         $slink eq $link && &badfmt("slave link same as main link $link");
@@ -136,7 +145,7 @@ if (open(AF,"$admindir/$name")) {
         push(@slavelinks,$slink);
         push(@slavelinks,$slink);
     }
     }
     while (($version= &gl("version")) ne '') {
     while (($version= &gl("version")) ne '') {
-        defined($versionnum{$version}) && &badfmt("duplicate path $tver");
+        defined($versionnum{$version}) && &badfmt("duplicate path $version");
        if ( -r $version ) {
        if ( -r $version ) {
            push(@versions,$version);
            push(@versions,$version);
            $versionnum{$version}= $i= $#versions;
            $versionnum{$version}= $i= $#versions;
@@ -219,10 +228,18 @@ if ($mode eq 'config') {
     }
     }
 }
 }
 
 
+if ($mode eq 'set') {
+    if (!$dataread) {
+	&pr("No alternatives for $name.");
+    } else {
+	&set_alternatives($name);
+    }
+}
+
 if (defined($linkname= readlink("$altdir/$name"))) {
 if (defined($linkname= readlink("$altdir/$name"))) {
     if ($linkname eq $best) {
     if ($linkname eq $best) {
         $state= 'expected';
         $state= 'expected';
-    } elsif (defined($linkname2= readlink("$altdir/$name.dpkg-tmp"))) {
+    } elsif (defined(readlink("$altdir/$name.dpkg-tmp"))) {
         $state= 'expected-inprogress';
         $state= 'expected-inprogress';
     } else {
     } else {
         $state= 'unexpected';
         $state= 'unexpected';
@@ -236,7 +253,7 @@ if (defined($linkname= readlink("$altdir/$name"))) {
 # Possible values for:
 # Possible values for:
 #   $manual      manual, auto
 #   $manual      manual, auto
 #   $state       expected, expected-inprogress, unexpected, nonexistent
 #   $state       expected, expected-inprogress, unexpected, nonexistent
-#   $mode        auto, install, remove
+#   $mode        auto, install, remove, remove-all
 # all independent
 # all independent
 
 
 if ($mode eq 'auto') {
 if ($mode eq 'auto') {
@@ -309,7 +326,7 @@ if ($mode eq 'install') {
 }
 }
 
 
 if ($mode eq 'remove') {
 if ($mode eq 'remove') {
-    if ($manual eq "manual" and $state eq "expected") {
+    if ($manual eq "manual" and $state ne "expected" and (map { $hits += $apath eq $_ } @versions) and $hits and $linkname eq $apath) {
     	&pr("Removing manually selected alternative - switching to auto mode");
     	&pr("Removing manually selected alternative - switching to auto mode");
 	$manual= "auto";
 	$manual= "auto";
     }
     }
@@ -329,6 +346,22 @@ if ($mode eq 'remove') {
     }
     }
 }
 }
 
 
+if ($mode eq 'remove-all') {
+   $manual= "auto";
+   $k= $#versions;
+   for ($i=0; $i<=$#versions; $i++) {
+        $k--;
+        delete $versionnum{$versions[$i]};
+	$#priorities--;
+        for ($j=0; $j<=$#slavenames; $j++) {
+            $slavepath{$i,$j}= $slavepath{$k,$j};
+            delete $slavepath{$k,$j};
+        }
+      }
+   $#versions=$k;
+ }
+
+
 for ($j=0; $j<=$#slavenames; $j++) {
 for ($j=0; $j<=$#slavenames; $j++) {
     for ($i=0; $i<=$#versions; $i++) {
     for ($i=0; $i<=$#versions; $i++) {
         last if $slavepath{$i,$j} ne '';
         last if $slavepath{$i,$j} ne '';
@@ -499,7 +532,7 @@ sub config_message {
 	    ($best eq $versions[$i]) ? '+' : ' ',
 	    ($best eq $versions[$i]) ? '+' : ' ',
 	    $i+1, $versions[$i]);
 	    $i+1, $versions[$i]);
     }
     }
-    printf(STDOUT "\nEnter to keep the default[*], or type selection number: ");
+    printf(STDOUT "\nPress enter to keep the default[*], or type selection number: ");
 }
 }
 
 
 sub config_alternatives {
 sub config_alternatives {
@@ -537,6 +570,40 @@ sub config_alternatives {
     }
     }
 }
 }
 
 
+sub set_alternatives {
+   $manual = "manual";
+   # Get prefered number
+   $preferred = -1;
+   for ($i=0; $i<=$#versions; $i++) {
+     if($versions[$i] eq $apath) {
+       $preferred = $i;
+       last;
+     }
+   }
+   if($preferred == -1){
+     &quit("Cannot find alternative `$apath'.\n")
+   }
+   print STDOUT "Using \`$apath' to provide \`$name'.\n";
+   symlink("$apath","$altdir/$name.dpkg-tmp") ||
+     &quit("unable to make $altdir/$name.dpkg-tmp a symlink to $apath: $!");
+   rename_mv("$altdir/$name.dpkg-tmp","$altdir/$name") ||
+     &quit("unable to install $altdir/$name.dpkg-tmp as $altdir/$name: $!");
+   # Link slaves...
+   for( $slnum = 0; $slnum < @slavenames; $slnum++ ) {
+     $slave = $slavenames[$slnum];
+     if ($slavepath{$preferred,$slnum} ne '') {
+       checked_symlink($slavepath{$preferred,$slnum},
+		       "$altdir/$slave.dpkg-tmp");
+       checked_mv("$altdir/$slave.dpkg-tmp", "$altdir/$slave");
+     } else {
+       &pr("Removing $slave ($slavelinks[$slnum]), not appropriate with $versions[$preferred].")
+	 if $verbosemode > 0;
+       unlink("$altdir/$slave") || $! == &ENOENT ||
+	 &quit("unable to remove $altdir/$slave: $!");
+     }
+   }
+}
+
 sub pr { print(STDOUT "@_\n") || &quit("error writing stdout: $!"); }
 sub pr { print(STDOUT "@_\n") || &quit("error writing stdout: $!"); }
 sub paf {
 sub paf {
     $_[0] =~ m/\n/ && &quit("newlines prohibited in update-alternatives files ($_[0])");
     $_[0] =~ m/\n/ && &quit("newlines prohibited in update-alternatives files ($_[0])");
@@ -564,7 +631,16 @@ sub checked_mv {
     rename_mv($source, $dest) ||
     rename_mv($source, $dest) ||
 	&quit("unable to install $source as $dest: $!");
 	&quit("unable to install $source as $dest: $!");
 }
 }
-
+sub config_all {
+    opendir ADMINDIR, $admindir or die "Serious problem: $!";
+    my @filenames = grep !/^\.\.?$/, readdir ADMINDIR;
+    close ADMINDIR;
+    foreach my $name (@filenames) {
+        system "$0 --config $name";
+        exit $? if $?;
+    }
+    exit(0);
+}
 exit(0);
 exit(0);
 
 
 # vim: nowrap ts=8 sw=4
 # vim: nowrap ts=8 sw=4