summaryrefslogtreecommitdiffstats
path: root/perl-install/printer.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/printer.pm')
-rw-r--r--perl-install/printer.pm27
1 files changed, 27 insertions, 0 deletions
diff --git a/perl-install/printer.pm b/perl-install/printer.pm
index bd10417b1..454909cda 100644
--- a/perl-install/printer.pm
+++ b/perl-install/printer.pm
@@ -196,6 +196,33 @@ sub files_exist {
return 1;
}
+sub set_alternative {
+ my ($command, $executable) = @_;
+ local *F;
+ # Read the list of executables for the given command to find the number
+ # of the desired executable
+ open F, ($::testing ? "$prefix" : "chroot $prefix/ ") .
+ "/bin/sh -c \"export LC_ALL=C; /bin/echo | update-alternatives --config $command \" |" ||
+ die "Could not run \"update-alternatives\"!";
+ my $choice = 0;
+ while (<F>) {
+ chomp;
+ if ($_ =~ m/^[\* ][\+ ]\s*([0-9]+)\s+(\S+)\s*$/) { # list entry?
+ if ($2 eq $executable) {
+ $choice = $1;
+ last;
+ }
+ }
+ }
+ close F;
+ # If the executable was found, assign the command to it
+ if ($choice > 0) {
+ system(($::testing ? "$prefix" : "chroot $prefix/ ") .
+ "/bin/sh -c \"/bin/echo $choice | update-alternatives --config $command > /dev/null 2>&1\"");
+ }
+ return 1;
+}
+
sub copy_printer_params($$) {
my ($from, $to) = @_;
map { $to->{$_} = $from->{$_} } grep { $_ ne 'configured' } keys %$from;