diff options
-rw-r--r-- | perl-install/printer.pm | 42 | ||||
-rw-r--r-- | perl-install/printerdrake.pm | 65 |
2 files changed, 88 insertions, 19 deletions
diff --git a/perl-install/printer.pm b/perl-install/printer.pm index 59f4ce9a0..bf98ddc3d 100644 --- a/perl-install/printer.pm +++ b/perl-install/printer.pm @@ -1,9 +1,8 @@ package printer; # $Id$ - - - +#use diagnostics; +#use strict; use common; @@ -14,9 +13,11 @@ use run_program; my $prefix = ""; #-location of the printer database in an installed system -my $PRINTER_DB_FILE = "/usr/share/foomatic/db/compiled/overview.xml"; +my $PRINTER_DB_FILE = "/usr/share/foomatic/db/compiled/overview.xml"; +#-configuration directory of Foomatic +my $FOOMATICCONFDIR = "/etc/foomatic"; #-location of the file containing the default spooler's name -my $FOOMATIC_DEFAULT_SPOOLER = "/etc/foomatic/defaultspooler"; +my $FOOMATIC_DEFAULT_SPOOLER = "$FOOMATICCONFDIR/defaultspooler"; %spooler = ( __("CUPS - Common Unix Printing System") => "cups", @@ -72,11 +73,38 @@ sub get_default_spooler () { sub set_default_spooler ($) { my ($printer) = @_; - open DEFSPOOL, "> $prefix$FOOMATIC_DEFAULT_SPOOLER"; + # Make Foomatic config directory if it does not exist yet + if (!(-d $FOOMATICCONFDIR)) {mkdir $FOOMATICCONFDIR;} + # Mark the default driver in a file + open DEFSPOOL, "> $prefix$FOOMATIC_DEFAULT_SPOOLER" || + die "Cannot create $prefix$FOOMATIC_DEFAULT_SPOOLER!"; print DEFSPOOL $printer->{SPOOLER}; close DEFSPOOL; } +sub restart_service ($) { + my ($service) = @_; + run_program::rooted($prefix, "/etc/rc.d/init.d/$service restart") + || die "Could not restart $service!"; +} + +sub start_service ($) { + my ($service) = @_; + run_program::rooted($prefix, "/etc/rc.d/init.d/$service start") + || die "Could not start $service!"; +} + +sub stop_service ($) { + my ($service) = @_; + run_program::rooted($prefix, "/etc/rc.d/init.d/$service stop") + || die "Could not stop $service!"; +} + +sub remove_package ($) { + my ($package) = @_; + run_program::rooted($prefix, "rpm -e --nodeps $package") || do {}; +} + sub copy_printer_params($$) { my ($from, $to) = @_; map { $to->{$_} = $from->{$_} } grep { $_ ne 'configured' } keys %$from; @@ -609,7 +637,7 @@ sub restart_queue($) { for ($printer->{SPOOLER}) { /cups/ && do { #- restart cups. - run_program::rooted($prefix, "/etc/rc.d/init.d/cups start"); sleep 1; + run_program::rooted($prefix, "/etc/rc.d/init.d/cups restart"); sleep 1; last }; /lpr|lprng/ && do { #- restart lpd. diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm index 9c9106e64..8ee8c1c85 100644 --- a/perl-install/printerdrake.pm +++ b/perl-install/printerdrake.pm @@ -714,8 +714,8 @@ Does it work properly?"), 1) and last; $printer->{complete} = 1; } -sub setup_default_spooler ($$) { - my ($printer, $in) = @_; +sub setup_default_spooler ($$$) { + my ($printer, $in, $install) = @_; $printer->{SPOOLER} ||= 'cups'; my $str_spooler = $in->ask_from_list_(__("Select Printer Spooler"), @@ -724,11 +724,47 @@ sub setup_default_spooler ($$) { $printer::spooler_inv{$printer->{SPOOLER}}, ) or return; $printer->{SPOOLER} = $printer::spooler{$str_spooler}; + # Install the spooler if not done yet + install_spooler($printer, $install); # Get the queues of this spooler printer::read_configured_queues($printer); return $printer->{SPOOLER}; } +sub install_spooler ($$) { + # installs the default spooler and start its daemon + # TODO: Automatically transfer queues between LPRng and LPD, + # Turn off /etc/printcap writing in CUPS when LPD or + # LPRng is used (perhaps better to be done in CUPS/LPD/LPRng + # start-up scripts?) + my ($printer, $install) = @_; + if (!$::testing) { + if ($printer->{SPOOLER} eq "cups") { + &$install('cups'); + # Restart daemon + printer::start_service("cups"); + sleep 5; + } elsif ($printer->{SPOOLER} eq "lpd") { + # "lpr" conflicts with "LPRng", remove "LPRng" + printer::remove_package("LPRng"); + &$install('lpr'); + # Restart daemon + printer::restart_service("lpd"); + sleep 1; + } elsif ($printer->{SPOOLER} eq "lprng") { + # "LPRng" conflicts with "lpr", remove "lpr" + printer::remove_package("lpr"); + &$install('LPRng'); + # Restart daemon + printer::restart_service("lpd"); + sleep 1; + } elsif ($printer->{SPOOLER} eq "pdq") { + &$install('pdq'); + # PDQ has no daemon + } + } +} + #- Program entry point for configuration with lpr or cups (stored in $mode). sub main($$$$;$) { my ($printer, $in, $ask_multiple_printer, $install, $upNetwork) = @_; @@ -745,13 +781,15 @@ sub main($$$$;$) { $in->ask_yesorno(_("Printer"), __("Would you like to configure printing?"), 0) ? 'lp' : 'Done'; - $printer->{SPOOLER} ||= setup_default_spooler ($printer, $in) || - return; + $printer->{SPOOLER} ||= + setup_default_spooler ($printer, $in, $install) || + return; } else { # Ask for a spooler when noone is defined - $printer->{SPOOLER} ||= setup_default_spooler ($printer, $in) || - return; + $printer->{SPOOLER} ||= + setup_default_spooler ($printer, $in, $install) || + return; # Show a queue list window when there is at least one queue # or when we are in expert mode unless ((%{$printer->{configured} || {}} == ()) && (!$::expert)) { @@ -765,7 +803,7 @@ sub main($$$$;$) { [ { val => \$queue, format => \&translate, list => [ (sort keys %{$printer->{configured} || {}}), # Button to add a new queue - __("Add queue"), + __("Add printer"), # In expert mode we can change the spooler ($::expert ? ( __("Spooler: ") . @@ -773,10 +811,10 @@ sub main($$$$;$) { # Bored by configuring your printers, get out of here! __("Done") ] } ] ); - } else { $queue = 'Add queue' } #- as there are no printers - #- already configured, Add one - #- automatically. - if ($queue eq 'Add queue') { + } else { $queue = __("Add printer") }#- as there are no printers + #- already configured, Add one + #- automatically. + if ($queue eq __("Add printer")) { my %queues; @queues{map { split '\|', $_ } keys %{$printer->{configured}}} = (); my $i = ''; while ($i < 100) { last unless exists $queues{"lp$i"}; ++$i; } @@ -784,12 +822,15 @@ sub main($$$$;$) { } if ($queue =~ /^Spooler: /) { $printer->{SPOOLER} = - setup_default_spooler ($printer, $in) || $printer->{SPOOLER}; + setup_default_spooler ($printer, $in, $install) || + $printer->{SPOOLER}; next; } } # Save the default spooler printer::set_default_spooler($printer); + # install the spooler if not done yet + install_spooler($printer, $install); #- Close printerdrake $queue eq 'Done' and last; |