[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#133745: dpkg: [patch] update-alternatives is not scriptable



Package: dpkg
Version: 1.9.18
Severity: wishlist
Tags: patch

Hi,

We use update-alternatives with FAI (automatical installation)
of several computers and thus we missed these features:

a) --remove-all <name>
We for instance don't want to have a x-session-manager
(KDE/Gnome) which is read by 
50xfree86-common_determine-startup

b) --set <name> <path>
Which does the very same as --config but not-interactivily.


-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux fantasio 2.4.16 #1 Fri Dec 14 14:22:43 CET 2001 i686
Locale: LANG=C, LC_CTYPE=C

Versions of packages dpkg depends on:
ii  libc6                    2.2.5-3         GNU C Library: Shared libraries an
ii  libncurses5              5.2.20020112a-3 Shared libraries for terminal hand
ii  libstdc++2.10-glibc2.2   1:2.95.4-1      The GNU stdc++ library

--- /usr/sbin/update-alternatives	Sat Nov  3 08:15:08 2001
+++ update-alternatives	Tue Feb 12 20:51:18 2002
@@ -40,9 +40,11 @@
 Usage: update-alternatives --install <link> <name> <path> <priority>
                           [--slave <link> <name> <path>] ...
        update-alternatives --remove <name> <path>
+       update-alternatives --remove-all <name>
        update-alternatives --auto <name>
        update-alternatives --display <name>
        update-alternatives --config <name>
+       update-alternatives --set <name> <path>
 <name> is the name in /etc/alternatives.
 <path> is the name referred to.
 <link> is the link pointing to /etc/alternatives/<name>.
@@ -88,12 +90,12 @@
         ($alink,$name,$apath,$apriority,@ARGV) = @ARGV;
         $apriority =~ m/^[-+]?\d+/ || &badusage("priority must be an integer");
         $mode= 'install';
-    } elsif (m/^--remove$/) {
+    } elsif (m/^--(remove|set)$/) {
         &checkmanymodes;
-        @ARGV >= 2 || &badusage("--remove needs <name> <path>");
+        @ARGV >= 2 || &badusage("--$1 needs <name> <path>");
+        $mode= $1;
         ($name,$apath,@ARGV) = @ARGV;
-        $mode= 'remove';
-    } elsif (m/^--(display|auto|config)$/) {
+    } elsif (m/^--(display|auto|config|remove-all)$/) {
         &checkmanymodes;
         @ARGV || &badusage("--$1 needs <name>");
         $mode= $1;
@@ -119,7 +121,7 @@
 defined($aslavelink{$name}) && &badusage("name $name 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 || &badusage("need --display, --config, --set, --install, --remove, --remove-all or --auto");
 $mode eq 'install' || !%slavelink || &badusage("--slave only allowed with --install");
 
 if (open(AF,"$admindir/$name")) {
@@ -209,6 +211,14 @@
     }
 }
 
+if ($mode eq 'set') {
+    if (!$dataread) {
+	&pr("No alternatives for $name.");
+    } else {
+	&set_alternatives($name);
+    }
+}
+
 if (defined($linkname= readlink("$altdir/$name"))) {
     if ($linkname eq $best) {
         $state= 'expected';
@@ -226,7 +236,7 @@
 # Possible values for:
 #   $manual      manual, auto
 #   $state       expected, expected-inprogress, unexpected, nonexistent
-#   $mode        auto, install, remove
+#   $mode        auto, install, remove, remove-all
 # all independent
 
 if ($mode eq 'auto') {
@@ -325,6 +335,22 @@
     }
 }
 
+if ($mode eq 'remove-all') {
+   $manual= "auto";
+   my $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 ($i=0; $i<=$#versions; $i++) {
         last if $slavepath{$i,$j} ne '';
@@ -531,6 +557,40 @@
 	}
 
     }
+}
+
+sub set_alternatives {
+   $manual = "manual";
+   # Get prefered number
+   my $preferred = -1;
+   for ($i=0; $i<=$#versions; $i++) {
+     if($versions[$i] eq $apath) {
+       $preferred = $i;
+       break;
+     }
+   }
+   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( my $slnum = 0; $slnum < @slavenames; $slnum++ ) {
+     my $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: $!"); }
--- update-alternatives.8.old	Tue Feb 12 20:56:30 2002
+++ update-alternatives.8	Tue Feb 12 21:04:38 2002
@@ -24,6 +24,11 @@
 .PP
 .B update-alternatives
 .RI [ options ]
+.B --remove-all
+.I name
+.PP
+.B update-alternatives
+.RI [ options ]
 .B --auto
 .I name
 .PP
@@ -36,6 +41,11 @@
 .RI [ options ]
 .B --config
 .I name
+.PP
+.B update-alternatives
+.RI [ options ]
+.B --set
+.I name path
 .SH DESCRIPTION
 .B update-alternatives
 creates, removes, maintains and displays information about the symbolic
@@ -151,6 +161,10 @@
 mode. You will need to use the
 .I --auto
 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
 Since the activities of
 .B update-alternatives
@@ -276,6 +290,15 @@
 any other installed alternatives for this group,
 the symlinks will be updated to point to the newly added alternatives.
 .TP
+\fB--set\fR \fIname path\fR
+Set the program
+.I path
+as alternative for
+.I name.
+This is equivalent to
+.IB--configure\fR
+but is non-interactive and thus scriptable.
+.TP
 \fB--remove\fR \fIname path\fR
 Remove an alternative and all of its associated slave links.
 .I name
@@ -295,6 +318,11 @@
 .IR path ,
 no links are changed;
 only the information about the alternative is removed.
+.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
 \fB--auto\fR \fIlink\fR
 Switch the master symlink




Reply to: