From 9e001dd46aa29612ce916edcd91daecfff8cc8b6 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Sun, 14 Sep 2003 21:54:41 +0000 Subject: [PATCH] * 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. --- ChangeLog | 11 ++++ debian/changelog | 17 +++++- scripts/update-alternatives.8 | 35 +++++++++++ scripts/update-alternatives.pl | 104 ++++++++++++++++++++++++++++----- 4 files changed, 150 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ae588c7..94fa552b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sun Sep 14 16:53:09 CDT 2003 Adam Heath + + * 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 * scripts/update-alternatives.8: Add --config to action section, and add diff --git a/debian/changelog b/debian/changelog index 2b9f0e0c..3c8dd416 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,9 +10,6 @@ dpkg (1.10.11) unstable; urgency=low #196361 * Change standard_startup and standard_shutdown into macros. Closes: #200351. - * Sebastian Ley : - Fix inversion test of $state against 'expected' when removing an - alternative. Closes: #203791. * Andrew Suffield : Fix inverted test of eof in parsedb, while looking for eof after field name. Closes: #198218 @@ -105,6 +102,20 @@ dpkg (1.10.11) unstable; urgency=low Closes: #175236 * Yann Dirson : Remove disabled --command-fd from help. Closes: #169619 + * Tobias Burnus : + Apply patch to update-alternatives that provides --set and --remove-all + commands. Closes: #133745. + * Osamu Aoki : + Add --all to update-alternatives, that calls --config on all + alternatives. Closes: #126621 + * Dan Jacobson : + Alter --config prompt, to be more clear, that one must 'press' enter to + accept the default. Closes: #203557 + * Peter Moulder : + Fix some -w issues in update-alternatives. Closes: #137313 + * Eduard Bloch : + Apply patch to check whether the target path exists on removing. + Closes: #37254 -- Wichert Akkerman UNRELEASED diff --git a/scripts/update-alternatives.8 b/scripts/update-alternatives.8 index 2f214894..fbfa4928 100644 --- a/scripts/update-alternatives.8 +++ b/scripts/update-alternatives.8 @@ -24,6 +24,15 @@ update-alternatives \- maintain symbolic links determining default commands .PP .B update-alternatives .RI [ options ] +.B --remove-all +.I name +.PP +.B update-alternatives +.RI [ options ] +.B --all +.PP +.B update-alternatives +.RI [ options ] .B --auto .I name .PP @@ -41,6 +50,11 @@ update-alternatives \- maintain symbolic links determining default commands .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 @@ -156,6 +170,10 @@ longer be in 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 @@ -317,6 +335,15 @@ and the newly added alternatives' priority is higher than 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 --config +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 @@ -337,6 +364,14 @@ If the link is not currently pointing to 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 +.B --all +Call \fB--config\fP on all alternatives. +.TP \fB--auto\fR \fIlink\fR Switch the master symlink .I link diff --git a/scripts/update-alternatives.pl b/scripts/update-alternatives.pl index 09b41787..c39d211e 100755 --- a/scripts/update-alternatives.pl +++ b/scripts/update-alternatives.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -- +#!/usr/bin/perl -w -- $admindir= "/var/lib/dpkg"; # 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 [--slave ] ... update-alternatives --remove + update-alternatives --remove-all update-alternatives --auto update-alternatives --display update-alternatives --list update-alternatives --config + update-alternatives --set + update-alternatives --all is the name in /etc/alternatives. is the name referred to. is the link pointing to /etc/alternatives/. @@ -88,12 +91,12 @@ while (@ARGV) { ($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 "); + @ARGV >= 2 || &badusage("--$1 needs "); ($name,$apath,@ARGV) = @ARGV; - $mode= 'remove'; - } elsif (m/^--(display|auto|config|list)$/) { + $mode= $1; + } elsif (m/^--(display|auto|config|list|remove-all)$/) { &checkmanymodes; @ARGV || &badusage("--$1 needs "); $mode= $1; @@ -111,6 +114,8 @@ while (@ARGV) { } elsif (m/^--admindir$/) { @ARGV || &badusage("--admindir needs a argument"); $admindir= shift(@ARGV); + } elsif (m/^--all$/) { + $mode = 'all'; } else { &badusage("unknown option \`$_'"); } @@ -119,8 +124,12 @@ while (@ARGV) { 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 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")) { $manual= &gl("manflag"); @@ -128,7 +137,7 @@ if (open(AF,"$admindir/$name")) { $link= &gl("link"); while (($sname= &gl("sname")) ne '') { push(@slavenames,$sname); - defined($slavenum{$sname}) && &badfmt("duplicate slave $tsname"); + defined($slavenum{$sname}) && &badfmt("duplicate slave $sname"); $slavenum{$sname}= $#slavenames; $slink= &gl("slink"); $slink eq $link && &badfmt("slave link same as main link $link"); @@ -136,7 +145,7 @@ if (open(AF,"$admindir/$name")) { push(@slavelinks,$slink); } while (($version= &gl("version")) ne '') { - defined($versionnum{$version}) && &badfmt("duplicate path $tver"); + defined($versionnum{$version}) && &badfmt("duplicate path $version"); if ( -r $version ) { push(@versions,$version); $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 ($linkname eq $best) { $state= 'expected'; - } elsif (defined($linkname2= readlink("$altdir/$name.dpkg-tmp"))) { + } elsif (defined(readlink("$altdir/$name.dpkg-tmp"))) { $state= 'expected-inprogress'; } else { $state= 'unexpected'; @@ -236,7 +253,7 @@ if (defined($linkname= readlink("$altdir/$name"))) { # 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') { @@ -309,7 +326,7 @@ if ($mode eq 'install') { } 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"); $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 ($i=0; $i<=$#versions; $i++) { last if $slavepath{$i,$j} ne ''; @@ -499,7 +532,7 @@ sub config_message { ($best eq $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 { @@ -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 paf { $_[0] =~ m/\n/ && &quit("newlines prohibited in update-alternatives files ($_[0])"); @@ -564,7 +631,16 @@ sub checked_mv { rename_mv($source, $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); # vim: nowrap ts=8 sw=4 -- 2.39.5