diff options
author | Francois Pons <fpons@mandriva.com> | 2000-08-31 14:58:10 +0000 |
---|---|---|
committer | Francois Pons <fpons@mandriva.com> | 2000-08-31 14:58:10 +0000 |
commit | 4518333f00c36f19b3425202e07e5db5d32a10ce (patch) | |
tree | 6862a673a807aeda6020a82302c701a2079a32c9 /perl-install | |
parent | 352b6ae2a540ce8f56e96a2284721cd27cc3d9d1 (diff) | |
download | drakx-4518333f00c36f19b3425202e07e5db5d32a10ce.tar drakx-4518333f00c36f19b3425202e07e5db5d32a10ce.tar.gz drakx-4518333f00c36f19b3425202e07e5db5d32a10ce.tar.bz2 drakx-4518333f00c36f19b3425202e07e5db5d32a10ce.tar.xz drakx-4518333f00c36f19b3425202e07e5db5d32a10ce.zip |
*** empty log message ***
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/ChangeLog | 7 | ||||
-rw-r--r-- | perl-install/install2.pm | 28 | ||||
-rw-r--r-- | perl-install/install_steps_interactive.pm | 19 | ||||
-rw-r--r-- | perl-install/printer.pm | 962 | ||||
-rw-r--r-- | perl-install/printerdrake.pm | 162 |
5 files changed, 572 insertions, 606 deletions
diff --git a/perl-install/ChangeLog b/perl-install/ChangeLog index 89c120a19..cf692c2fe 100644 --- a/perl-install/ChangeLog +++ b/perl-install/ChangeLog @@ -1,3 +1,10 @@ +2000-08-31 François Pons <fpons@mandrakesoft.com> + + * install2.pm: removed printer default config (now obsoleted). + * install_steps_interactive.pm: add cups support. + * printerdrake.pm: add cups support. + * printer.pm: add cups support. + 2000-08-31 Frederic Lepied <flepied@mandrakesoft.com> * install_any.pm (setPackages): install the right glide module diff --git a/perl-install/install2.pm b/perl-install/install2.pm index 1c5950ebd..6e7498b63 100644 --- a/perl-install/install2.pm +++ b/perl-install/install2.pm @@ -171,34 +171,6 @@ $o = $::o = { #- timezone => "Europe/Paris", #- UTC => 1, }, - printer => { - want => 0, - complete => 0, - str_type => $printer::printer_type_default, - QUEUE => "lp", - SPOOLDIR => "/var/spool/lpd/lp", - DBENTRY => "PostScript", - PAPERSIZE => "", - CRLF => 0, - AUTOSENDEOF => 1, - - DEVICE => "/dev/lp0", - - REMOTEHOST => "", - REMOTEQUEUE => "", - - NCPHOST => "", #-"printerservername", - NCPQUEUE => "", #-"queuename", - NCPUSER => "", #-"user", - NCPPASSWD => "", #-"pass", - - SMBHOST => "", #-"hostname", - SMBHOSTIP => "", #-"1.2.3.4", - SMBSHARE => "", #-"printername", - SMBUSER => "", #-"user", - SMBPASSWD => "", #-"passowrd", - SMBWORKGROUP => "", #-"AS3", - }, #- superuser => { password => 'a', shell => '/bin/bash', realname => 'God' }, #- user => { name => 'foo', password => 'bar', home => '/home/foo', shell => '/bin/bash', realname => 'really, it is foo' }, diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 1d4eab9e3..51a5cf094 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -642,7 +642,7 @@ sub configureServices { sub configurePrinter { my ($o, $clicked) = @_; - return if $::corporate; + $::corporate and return; require printer; require printerdrake; @@ -651,11 +651,20 @@ sub configurePrinter { printerdrake::auto_detect($o) or return; } - #- bring interface up for installing ethernet packages but avoid ppp by default, - #- else the guy know what he is doing... - #install_interactive::upNetwork($o, 'pppAvoided'); - + #- take default configuration, this include choosing the right system + #- currently used by the system. eval { add2hash($o->{printer} ||= {}, printer::getinfo($o->{prefix})) }; + + #- figure out what printing system to use, currently are suported cups and lpr, + #- in case this has not be detected above. + $::beginner and $o->{printer}{mode} ||= 'cups'; #'lpr'; + if (!$o->{printer}{mode}) { + $o->{printer}{mode} = $o->ask_from_list_([''], _("What printing system do you want to use?"), + [ 'cups', 'lpr', __("Cancel") ], + ); + $o->{printer}{mode} eq 'Cancel' and $o->{printer}{mode} = undef, return; + } + $o->{printer}{PAPERSIZE} = $o->{lang} eq 'en' ? 'letter' : 'a4'; printerdrake::main($o->{printer}, $o, sub { $o->pkg_install($_[0]) }, sub { install_interactive::upNetwork($o, 'pppAvoided') }); } diff --git a/perl-install/printer.pm b/perl-install/printer.pm index 704c45ec6..ad6e46359 100644 --- a/perl-install/printer.pm +++ b/perl-install/printer.pm @@ -1,227 +1,13 @@ package printer; -#-##################################################################################### - -=head1 NAME - -printer - supply methods for manage the printer related files directory handles - -=head1 SYNOPSIS - -use printer; - -=head1 DESCRIPTION - -Use the source. - -=cut - -#-##################################################################################### use diagnostics; use strict; - -#-##################################################################################### - -=head2 Exported variable - -=cut - -#-##################################################################################### -use vars qw(%thedb %thedb_gsdriver %printer_type %printer_type_inv $printer_type_default @papersize_type %fields $spooldir @entries_db_short @entry_db_description %descr_to_help %descr_to_db %db_to_descr); -#-##################################################################################### - -=head2 Imports - -=cut - -#-##################################################################################### -use Data::Dumper; - -#-##################################################################################### - -=head2 pixel imports - -=cut +use vars qw(%thedb %thedb_gsdriver %printer_type %printer_type_inv @papersize_type %fields @entries_db_short @entry_db_description %descr_to_help %descr_to_db %db_to_descr %descr_to_ppd); use common qw(:common :system :file); use commands; -#-##################################################################################### - -#-##################################################################################### - -=head2 Examples and types - -=over 4 - -=item * - -an entry in the 'printerdb' file, which describes each type of -supported printer: - - StartEntry: DeskJet550 - GSDriver: cdj550 - Description: {HP DeskJet 550C/560C/6xxC series} - About: { \ - This driver supports the HP inkjet printers which have \ - color capability using both black and color cartridges \ - simultaneously. Known to work with the 682C and the 694C. \ - Other 600 and 800 series printers may work \ - if they have this feature. \ - If your printer seems to be saturating the paper with ink, \ - try added an extra GS option of '-dDepletion=2'. \ - Ghostscript supports several optional parameters for \ - this driver: see the document 'devices.doc' \ - in the ghostscript directory under /usr/doc. \ - } - Resolution: {300} {300} {} - BitsPerPixel: {3} {Normal color printing with color cartridge} - BitsPerPixel: {8} {Floyd-Steinberg B & W printing for better greys} - BitsPerPixel: {24} {Floyd-Steinberg Color printing (best, but slow)} - BitsPerPixel: {32} {Sometimes provides better output than 24} - EndEntry - -Example of data-struct: - - my %ex_printerdb_entry = - ( - ENTRY => "DeskJet550", #-Human-readable name of the entry - GSDRIVER => "cdj550", #-gs driver used by this printer - DESCR => "HP DeskJet 550C/560C/6xxC series", #-Single line description of printer - ABOUT => " - This driver supports the HP inkjet printers which have - color capability using both black and color cartridges - ...", #-Lengthy description of printer - RESOLUTION => [ #-List of resolutions supported - { - XDPI => 300, - YDPI => 300, - DESCR => "commentaire", - }, - ], - BITSPERPIXEL => [ #-List of color depths supported - { - DEPTH => 3, - DESCR => "Normal color printing with color cartridge", - }, - ], - ) - ; - -=item * - -A printcap entry only represents a subset of possible options available -Sufficient for the simple configuration we are interested in -there is also some text in the template (.in) file in the spooldir - - # /etc/printcap - # - # Please don't edit this file directly unless you know what you are doing - # Be warned that the control-panel printtool requires a very strict forma - # Look at the printcap(5) man page for more info. - # - # This file can be edited with the printtool in the control-panel. - - ##PRINTTOOL3## LOCAL uniprint NAxNA letter {} U_NECPrinwriter2X necp2x6 1 - lpname:\ - :sd=/var/spool/lpd/lpnamespool:\ - :mx#45:\ - :sh:\ - :lp=/dev/device:\ - :if=/var/spool/lpd/lpnamespool/filter: - ##PRINTTOOL3## REMOTE st800 360x180 a4 {} EpsonStylus800 Default 1 - remote:\ - :sd=/var/spool/lpd/remotespool:\ - :mx#47:\ - :sh:\ - :rm=remotehost:\ - :rp=remotequeue:\ - :if=/var/spool/lpd/remotespool/filter: - ##PRINTTOOL3## SMB la75plus 180x180 letter {} DECLA75P Default {} - smb:\ - :sd=/var/spool/lpd/smbspool:\ - :mx#46:\ - :sh:\ - :if=/var/spool/lpd/smbspool/filter:\ - :af=/var/spool/lpd/smbspool/acct:\ - :lp=/dev/null: - ##PRINTTOOL3## NCP ap3250 180x180 letter {} EpsonAP3250 Default {} - ncp:\ - :sd=/var/spool/lpd/ncpspool:\ - :mx#46:\ - :sh:\ - :if=/var/spool/lpd/ncpspool/filter:\ - :af=/var/spool/lpd/ncpspool/acct:\ - :lp=/dev/null: - -Example of data-struct: - - my %ex_printcap_entry = - ( - QUEUE => "lpname", #-Queue name, can have multi separated by '|' - - #-if you want something different from the default - SPOOLDIR => "/var/spool/lpd/lpnamespool/", #-Spool directory - IF => "/var/spool/lpd/lpnamespool/filter", #-input filter - - #- commentaire inserer dans le printcap pour que printtool retrouve ses petits - DBENTRY => "DeskJet670", #-entry in printer database for this printer - - RESOLUTION => "NAxNA", #-ghostscript resolution to use - PAPERSIZE => "letter", #-Papersize - BITSPERPIXEL => "necp2x6", #-ghostscript color option - CRLF => 1 , #-Whether or not to do CR/LF xlation - - TYPE => "LOCAL", - - #- LOCAL - DEVICE => "/dev/device", #-Print device - - #- REMOTE (lpd) printers only - REMOTEHOST => "remotehost", #-Remote host (not used for all entries) - REMOTEQUEUE => "remotequeue", #-Queue on the remote machine - - - #-SMB (LAN Manager) only - #- in spooldir/.config - #-share='\\hostname\printername' - #-hostip=1.2.3.4 - #-user='user' - #-password='passowrd' - #-workgroup='AS3' - SMBHOST => "hostname", #-Server name (NMB name, can have spaces) - SMBHOSTIP => "1.2.3.4", #-Can optional specify and IP address for host - SMBSHARE => "printername", #-Name of share on the SMB server - SMBUSER => "user", #-User to log in as on SMB server - SMBPASSWD => "passowrd", #-Corresponding password - SMBWORKGROUP => "AS3", #-SMB workgroup name - AF => "/var/spool/lpd/smbspool/acct", #-accounting filter (needed for smbprint) - - #- NCP (NetWare) only - #- in spooldir/.config - #-server=printerservername - #-queue=queuename - #-user=user - #-password=pass - NCPHOST => "printerservername", #-Server name (NCP name) - NCPQUEUE => "queuename", #-Queue on server - NCPUSER => "user", #-User to log in as on NCP server - NCPPASSWD => "pass", #-Corresponding password - - ) - ; - -=cut - -#-##################################################################################### - -=head2 Intern constant - -=cut - -#-##################################################################################### - #-if we are in an DrakX config my $prefix = ""; @@ -229,25 +15,15 @@ my $prefix = ""; my $PRINTER_DB_FILE = "/usr/lib/rhs/rhs-printfilters/printerdb"; my $PRINTER_FILTER_DIR = "/usr/lib/rhs/rhs-printfilters"; - - - -#-##################################################################################### - -=head2 Exported constant - -=cut - -#-##################################################################################### - %printer_type = ( - __("Local printer") => "LOCAL", - __("Remote lpd") => "REMOTE", - __("SMB/Windows 95/98/NT") => "SMB", - __("NetWare") => "NCP", + __("Local printer") => "LOCAL", + __("Remote lpd") => "REMOTE", + __("SMB/Windows 95/98/NT") => "SMB", + __("NetWare") => "NCP", + __("URI for Local printer") => "URI_LOCAL", + __("URI for Network printer") => "URI_NET", ); %printer_type_inv = reverse %printer_type; -$printer_type_default = "Local printer"; %fields = ( STANDARD => [qw(QUEUE SPOOLDIR IF)], @@ -258,19 +34,20 @@ $printer_type_default = "Local printer"; NCP => [qw(NCPHOST NCPQUEUE NCPUSER NCPPASSWD)], ); @papersize_type = qw(letter legal ledger a3 a4); -$spooldir = "/var/spool/lpd"; - -#-##################################################################################### - -=head2 Functions - -=cut - -#-##################################################################################### +#------------------------------------------------------------------------------ sub set_prefix($) { $prefix = $_[0]; } -sub default_queue($) { (split '\|', $_[0])[0] } +sub default_queue($) { (split '\|', $_[0]{QUEUE})[0] } +sub default_spooldir($) { "/var/spool/lpd/" . default_queue($_[0]) } + +sub default_printer_type($) { ($_[0]{mode} eq /cups/ && "URI_") . "LOCAL" } +sub printer_type($) { + for ($_[0]{mode}) { + /cups/ && return @printer_type_inv{qw(URI_LOCAL URI_NET LOCAL REMOTE SMB)}; + /lpr/ && return @printer_type_inv{qw(LOCAL REMOTE SMB NCP)}; + } +} sub copy_printer_params($$) { my ($from, $to) = @_; @@ -282,13 +59,20 @@ sub getinfo($) { my $printer = {}; set_prefix($prefix); - read_configured_queue($printer); + + #- try to detect which printing system has been previously installed. + #- the first detected is the default. + read_printers_conf($printer); #- try to read existing cups (local only) queues. + read_configured_queue($printer); #- try to read existing lpr queues. add2hash($printer, { + #- global parameters. want => 0, complete => 0, - str_type => $printer::printer_type_default, + str_type => undef, QUEUE => "lp", + + #- lpr parameters. SPOOLDIR => "/var/spool/lpd/lp", DBENTRY => "PostScript", PAPERSIZE => "", @@ -315,141 +99,18 @@ sub getinfo($) { SMBUSER => "", #-"user", SMBPASSWD => "", #-"passowrd", SMBWORKGROUP => "", #-"AS3", + + #- cups parameters. + DeviceURI => "parallel:/dev/lp0", + Info => "", + Location => "", + State => "Idle", + Accepting => "Yes", }); $printer; } -#-***************************************************************************** -#- read function -#-***************************************************************************** -#------------------------------------------------------------------------------ -#- Read the printer database from dbpath into memory -#------------------------------------------------------------------------------ -sub read_printer_db(;$) { - my $dbpath = $prefix . ($_[0] || $PRINTER_DB_FILE); - - scalar(keys %thedb) > 4 and return; #- try reparse if using only ppa, POSTSCRIPT, TEXT. - - my %available_devices; #- keep only available devices in our database. - local *AVAIL; open AVAIL, ($::testing ? "$prefix" : "chroot $prefix/ ") . "/usr/bin/gs --help |"; - foreach (<AVAIL>) { - if (/^Available devices:/ ... /^\S/) { - @available_devices{split /\s+/, $_} = () if /^\s+/; - } - } - close AVAIL; - $available_devices{ppa} = undef; #- if -x "$prefix/usr/bin/pbm2ppa" && -x "$prefix/usr/bin/pnm2ppa"; - delete $available_devices{''}; - @available_devices{qw/POSTSCRIPT TEXT/} = (); #- these are always available. - - local $_; #- use of while (<... - local *DBPATH; #- don't have to do close ... and don't modify globals at least - open DBPATH, $dbpath or die "An error has occurred on $dbpath : $!"; - - while (<DBPATH>) { - if (/^StartEntry:\s(\w*)/) { - my $entry = { ENTRY => $1 }; - - WHILE : - while (<DBPATH>) { - SWITCH: { - /GSDriver:\s*(\w*)/ and do { $entry->{GSDRIVER} = $1; last SWITCH }; - /Description:\s*{(.*)}/ and do { $entry->{DESCR} = $1; last SWITCH }; - /About:\s*{\s*(.*?)\s*}/ and do { $entry->{ABOUT} = $1; last SWITCH }; - /About:\s*{\s*(.*?)\s*\\\s*$/ - and do { - my $string = $1; - while (<DBPATH>) { - $string =~ /\S$/ and $string .= ' '; - /^\s*(.*?)\s*\\\s*$/ and $string .= $1; - /^\s*(.*?)\s*}\s*$/ and do { $entry->{ABOUT} = $string . $1; last SWITCH }; - } - }; - /Resolution:\s*{(.*)}\s*{(.*)}\s*{(.*)}/ - and do { push @{$entry->{RESOLUTION} ||= []}, { XDPI => $1, YDPI => $2, DESCR => $3 }; last SWITCH }; - /BitsPerPixel:\s*{(.*)}\s*{(.*)}/ - and do { push @{$entry->{BITSPERPIXEL} ||= []}, {DEPTH => $1, DESCR => $2}; last SWITCH }; - - /EndEntry/ and last WHILE; - } - } - if (exists $available_devices{$entry->{GSDRIVER}}) { - $thedb{$entry->{ENTRY}} = $entry; - $thedb_gsdriver{$entry->{GSDRIVER}} = $entry; - } - } - } - - @entries_db_short = sort keys %printer::thedb; - %descr_to_db = map { $printer::thedb{$_}{DESCR}, $_ } @entries_db_short; - %descr_to_help = map { $printer::thedb{$_}{DESCR}, $printer::thedb{$_}{ABOUT} } @entries_db_short; - @entry_db_description = keys %descr_to_db; - %db_to_descr = reverse %descr_to_db; -} - - -#-****************************************************************************** -#- write functions -#-****************************************************************************** - -#------------------------------------------------------------------------------ -#- given the path queue_path, we create all the required spool directory -#------------------------------------------------------------------------------ -sub create_spool_dir($) { - my ($queue_path) = @_; - my $complete_path = "$prefix/$queue_path"; - - commands::mkdir_("-p", $complete_path); - - unless ($::testing) { - #-redhat want that "drwxr-xr-x root lp" - my $gid_lp = (getpwnam("lp"))[3]; - chown 0, $gid_lp, $complete_path - or die "An error has occurred - can't chgrp $complete_path to lp $!"; - } -} - -#------------------------------------------------------------------------------ -#-given the input spec file 'input', and the target output file 'output' -#-we set the fields specified by fieldname to the values in fieldval -#-nval is the number of fields to set -#-Doesnt currently catch error exec'ing sed yet -#------------------------------------------------------------------------------ -sub create_config_file($$%) { - my ($inputfile, $outputfile, %toreplace) = @_; - template2file("$prefix/$inputfile", "$prefix/$outputfile", %toreplace); - eval { commands::chown_("root.lp", "$prefix/$outputfile") }; -} - - -#------------------------------------------------------------------------------ -#-copy master filter to the spool dir -#------------------------------------------------------------------------------ -sub copy_master_filter($) { - my ($queue_path) = @_; - my $complete_path = "$prefix/$queue_path/filter"; - my $master_filter = "$prefix/$PRINTER_FILTER_DIR/master-filter"; - - eval { commands::cp('-f', $master_filter, $complete_path) }; - $@ and die "Can't copy $master_filter to $complete_path $!"; - eval { commands::chown_("root.lp", $complete_path); }; -} - #------------------------------------------------------------------------------ -#- given a PrintCap Entry, create the spool dir and special -#- rhs-printfilters related config files which are required -#------------------------------------------------------------------------------ -my $intro_printcap_test = " -# -# Please don't edit this file directly unless you know what you are doing! -# Look at the printcap(5) man page for more info. -# Be warned that the control-panel printtool requires a very strict format! -# -# This file can be edited with printerdrake or printtool. -# - -"; - sub read_configured_queue($) { my ($printer) = @_; my $current = undef; @@ -461,7 +122,7 @@ sub read_configured_queue($) { }; #- read /etc/printcap file. - local *PRINTCAP; open PRINTCAP, "$prefix/etc/printcap" or die "Can't open $prefix/etc/printcap file: $!"; + local *PRINTCAP; open PRINTCAP, "$prefix/etc/printcap" or return; foreach (<PRINTCAP>) { chomp; my $p = '(?:\{(.*?)\}|(\S+))'; @@ -576,210 +237,413 @@ sub read_configured_queue($) { close F; } } + + #- assume this printing system. + $printer->{mode} ||= 'lpr'; } -sub configure_queue($) { - my ($entry) = @_; - my $queue_path = "$entry->{SPOOLDIR}"; - create_spool_dir($queue_path); +sub read_printer_db(;$) { + my $dbpath = $prefix . ($_[0] || $PRINTER_DB_FILE); - my $get_name_file = sub { - my ($name) = @_; - ("$PRINTER_FILTER_DIR/$name.in", "$entry->{SPOOLDIR}/$name") - }; - my ($filein, $file); - my %fieldname = (); - my $dbentry = $thedb{($entry->{DBENTRY})} or die "no dbentry"; - - #- make general.cfg - ($filein, $file) = &$get_name_file("general.cfg"); - $fieldname{ascps_trans} = $entry->{ASCII_TO_PS} || $dbentry->{GSDRIVER} eq 'ppa' ? "YES" : "NO"; - $fieldname{desiredto} = $dbentry->{GSDRIVER} ne "TEXT" ? "ps" : "asc"; - $fieldname{papersize} = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter"; - $fieldname{printertype} = $entry->{TYPE}; - create_config_file($filein, $file, %fieldname); - - #- now do postscript.cfg - ($filein, $file) = &$get_name_file("postscript.cfg"); - %fieldname = (); - $fieldname{gsdevice} = $dbentry->{GSDRIVER}; - $fieldname{papersize} = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter"; - $fieldname{resolution} = $entry->{RESOLUTION}; - $fieldname{color} = $entry->{BITSPERPIXEL} ne "Default" && - (($dbentry->{GSDRIVER} ne "uniprint" && "-dBitsPerPixel=") . $entry->{BITSPERPIXEL}); - $fieldname{reversepages} = $entry->{REVERSE_ORDER} ? "YES" : ""; - $fieldname{extragsoptions} = "\"$entry->{EXTRA_GS_OPTIONS}\""; - $fieldname{pssendeof} = $entry->{AUTOSENDEOF} ? ($dbentry->{GSDRIVER} eq "POSTSCRIPT" ? "YES" : "NO") : "NO"; - $fieldname{nup} = $entry->{NUP}; - $fieldname{rtlftmar} = $entry->{RTLFTMAR}; - $fieldname{topbotmar} = $entry->{TOPBOTMAR}; - create_config_file($filein, $file, %fieldname); - - #- finally, make textonly.cfg - ($filein, $file) = &$get_name_file("textonly.cfg"); - %fieldname = (); - $fieldname{textonlyoptions} = "\"$entry->{TEXTONLYOPTIONS}\""; - $fieldname{crlftrans} = $entry->{CRLF} ? "YES" : ""; - $fieldname{textsendeof} = $entry->{AUTOSENDEOF} ? ($dbentry->{GSDRIVER} eq "POSTSCRIPT" ? "NO" : "YES") : "NO"; - create_config_file($filein, $file, %fieldname); - - if ($entry->{TYPE} eq "SMB") { - #- simple config file required if SMB printer - my $config_file = "$prefix$queue_path/.config"; - local *F; - open F, ">$config_file" or die "Can't create $config_file $!"; - print F "share='\\\\$entry->{SMBHOST}\\$entry->{SMBSHARE}'\n"; - print F "hostip=$entry->{SMBHOSTIP}\n"; - print F "user='$entry->{SMBUSER}'\n"; - print F "password='$entry->{SMBPASSWD}'\n"; - print F "workgroup='$entry->{SMBWORKGROUP}'\n"; - close F; - eval { chmod 0640, $config_file; commands::chown_("root.lp", $config_file) }; - } elsif ($entry->{TYPE} eq "NCP") { - #- same for NCP printer - my $config_file = "$prefix$queue_path/.config"; - local *F; - open F, ">$config_file" or die "Can't create $config_file $!"; - print F "server=$entry->{NCPHOST}\n"; - print F "queue=$entry->{NCPQUEUE}\n"; - print F "user=$entry->{NCPUSER}\n"; - print F "password=$entry->{NCPPASSWD}\n"; - close F; - eval { chmod 0640, $config_file; commands::chown_("root.lp", $config_file) }; - } + scalar(keys %thedb) > 4 and return; #- try reparse if using only ppa, POSTSCRIPT, TEXT. - copy_master_filter($queue_path); - - #-now the printcap file, note this one contains all the printer (use configured for that). - local *PRINTCAP; - open PRINTCAP, ">$prefix/etc/printcap" or die "Can't open printcap file $!"; - print PRINTCAP $intro_printcap_test; - foreach (values %{$entry->{configured}}) { - $_->{DBENTRY} = $thedb_gsdriver{$_->{GSDRIVER}}{ENTRY} unless defined $_->{DBENTRY}; - my $db_ = $thedb{$_->{DBENTRY}} or next; #die "no dbentry"; - - $_->{SPOOLDIR} ||= "$spooldir/" . default_queue($_->{QUEUE}); - $_->{IF} ||= "$_->{SPOOLDIR}/filter"; - $_->{AF} ||= "$_->{SPOOLDIR}/acct"; - - printf PRINTCAP "##PRINTTOOL3## %s %s %s %s %s %s %s%s\n", - $_->{TYPE} || '{}', - $db_->{GSDRIVER} || '{}', - $_->{RESOLUTION} || '{}', - $_->{PAPERSIZE} || '{}', - '{}', - $db_->{ENTRY} || '{}', - $_->{BITSPERPIXEL} || '{}', - $_->{CRLF} ? " 1" : ""; - - print PRINTCAP "$_->{QUEUE}:\\\n"; - print PRINTCAP "\t:sd=$_->{SPOOLDIR}:\\\n"; - print PRINTCAP "\t:mx#0:\\\n\t:sh:\\\n"; - - if ($_->{TYPE} eq "LOCAL") { - print PRINTCAP "\t:lp=$_->{DEVICE}:\\\n"; - } elsif ($_->{TYPE} eq "REMOTE") { - print PRINTCAP "\t:rm=$_->{REMOTEHOST}:\\\n"; - print PRINTCAP "\t:rp=$_->{REMOTEQUEUE}:\\\n"; - } else { - #- (pcentry->Type == (PRINTER_SMB | PRINTER_NCP)) - print PRINTCAP "\t:lp=/dev/null:\\\n"; - print PRINTCAP "\t:af=$_->{AF}\\\n"; + my %available_devices; #- keep only available devices in our database. + local *AVAIL; open AVAIL, ($::testing ? "$prefix" : "chroot $prefix/ ") . "/usr/bin/gs --help |"; + foreach (<AVAIL>) { + if (/^Available devices:/ ... /^\S/) { + @available_devices{split /\s+/, $_} = () if /^\s+/; } + } + close AVAIL; + $available_devices{ppa} = undef; #- if -x "$prefix/usr/bin/pbm2ppa" && -x "$prefix/usr/bin/pnm2ppa"; + delete $available_devices{''}; + @available_devices{qw/POSTSCRIPT TEXT/} = (); #- these are always available. - #- cheating to get the input filter! - print PRINTCAP "\t:if=$_->{IF}:\n"; - print PRINTCAP "\n"; + local $_; #- use of while (<... + local *DBPATH; #- don't have to do close ... and don't modify globals at least + open DBPATH, $dbpath or die "An error has occurred on $dbpath : $!"; + + while (<DBPATH>) { + if (/^StartEntry:\s(\w*)/) { + my $entry = { ENTRY => $1 }; + + WHILE : + while (<DBPATH>) { + SWITCH: { + /GSDriver:\s*(\w*)/ and do { $entry->{GSDRIVER} = $1; last SWITCH }; + /Description:\s*{(.*)}/ and do { $entry->{DESCR} = $1; last SWITCH }; + /About:\s*{\s*(.*?)\s*}/ and do { $entry->{ABOUT} = $1; last SWITCH }; + /About:\s*{\s*(.*?)\s*\\\s*$/ + and do { + my $string = $1; + while (<DBPATH>) { + $string =~ /\S$/ and $string .= ' '; + /^\s*(.*?)\s*\\\s*$/ and $string .= $1; + /^\s*(.*?)\s*}\s*$/ and do { $entry->{ABOUT} = $string . $1; last SWITCH }; + } + }; + /Resolution:\s*{(.*)}\s*{(.*)}\s*{(.*)}/ + and do { push @{$entry->{RESOLUTION} ||= []}, { XDPI => $1, YDPI => $2, DESCR => $3 }; last SWITCH }; + /BitsPerPixel:\s*{(.*)}\s*{(.*)}/ + and do { push @{$entry->{BITSPERPIXEL} ||= []}, {DEPTH => $1, DESCR => $2}; last SWITCH }; + + /EndEntry/ and last WHILE; + } + } + if (exists $available_devices{$entry->{GSDRIVER}}) { + $thedb{$entry->{ENTRY}} = $entry; + $thedb_gsdriver{$entry->{GSDRIVER}} = $entry; + } + } } - eval { commands::chown_("root.lp", "$prefix/etc/printcap") }; - my $useUSB = 0; - foreach (values %{$entry->{configured}}) { - $useUSB ||= $_->{DEVICE} =~ /usb/; + @entries_db_short = sort keys %printer::thedb; + %descr_to_db = map { $printer::thedb{$_}{DESCR}, $_ } @entries_db_short; + %descr_to_help = map { $printer::thedb{$_}{DESCR}, $printer::thedb{$_}{ABOUT} } @entries_db_short; + @entry_db_description = keys %descr_to_db; + %db_to_descr = reverse %descr_to_db; +} + +#------------------------------------------------------------------------------ +sub read_printers_conf { + my ($printer) = @_; + my $current = undef; + + #- read /etc/cups/printers.conf file. + #- according to this code, we are now using the following keys for each queues. + #- DeviceURI > lpd://printer6/lp + #- Info > Info Text + #- Location > Location Text + #- State > Idle|Stopped + #- Accepting > Yes|No + local *PRINTERS; open PRINTERS, "$prefix/etc/cups/printers.conf" or return; + foreach (<PRINTERS>) { + chomp; + /^\s*#/ and next; + if (/^\s*<(?:DefaultPrinter|Printer)\s+([^>]*)>/) { $current = { QUEUE => $1, } } + elsif (/\s*<\/Printer>/) { $current->{QUEUE} && $current->{DeviceURI} or next; #- minimal check of synthax. + add2hash($printer->{configured}{$current->{QUEUE}} ||= {}, $current); $current = undef } + elsif (/\s*(\S*)\s+(.*)/) { $current->{$1} = $2 } } - if ($useUSB) { - my $f = "$prefix/etc/sysconfig/usb"; - my %usb = getVarsFromSh($f); - $usb{PRINTER} = "yes"; - setVarsInSh($f, \%usb); + close PRINTERS; + + #- assume this printing system. + $printer->{mode} ||= 'cups'; +} + +sub get_direct_uri { + #- get the local printer to access via a Device URI. + my @direct_uri; + local *F; open F, "chroot $prefix/ /usr/sbin/lpinfo -v |"; + foreach (<F>) { + /^(direct|usb|serial)\s+(\S*)/ and push @direct_uri, $2; } + close F; + @direct_uri; } -sub restart_queue($) { - my ($queue) = @_; +sub get_descr_from_ppd { + my ($printer) = @_; + my %ppd; - #- restart lpd after cleaning the queue. - foreach (("/var/spool/lpd/$queue/lock", "/var/spool/lpd/lpd.lock")) { - my $pidlpd = (cat_("$prefix$_"))[0]; - kill 'TERM', $pidlpd if $pidlpd; - unlink "$prefix$_"; + local *F; open F, "$prefix/etc/cups/ppd/$printer->{QUEUE}.ppd" or return; + foreach (<F>) { + /^\*([^\s:]*)\s*:\s*\"([^\"]*)\"/ and do { $ppd{$1} = $2; next }; + /^\*([^\s:]*)\s*:\s*([^\s\"]*)/ and do { $ppd{$1} = $2; next }; } - require run_program; - run_program::rooted($prefix, "lprm", "-P$queue", "-"); sleep 1; - run_program::rooted($prefix, "lpd"); sleep 1; + close F; + + $ppd{Manufacturer} . '|' . ($ppd{NickName} || $ppd{ShortNickName} || $ppd{ModelName}) . + ($ppd{LanguageVersion} && (" (" . lc(substr($ppd{LanguageVersion}, 0, 2)) . ")")); } -sub print_pages($@) { - my ($queue, @pages) = @_; +sub poll_ppd_base { + #- before trying to poll the ppd database available to cups, we have to make sure + #- the file /etc/cups/ppds.dat is no more modified. + #- if cups continue to modify it (because it reads the ppd files available), the + #- poll_ppd_base program simply cores :-) + run_program::rooted($prefix, "/etc/rc.d/init.d/cups start"); - require run_program; - foreach (@pages) { - run_program::rooted($prefix, "lpr", "-P$queue", $_); + foreach (1..10) { + local *PPDS; open PPDS, "chroot $prefix/ /usr/bin/poll_ppd_base -a |"; + foreach (<PPDS>) { + chomp; + my ($ppd, $mf, $descr, $lang) = split /\|/; + $ppd && $mf && $descr and $descr_to_ppd{"$mf|$descr" . ($lang && " ($lang)")} = $ppd; + } + close PPDS; + scalar(keys %descr_to_ppd) > 5 and last; + sleep 1; #- we have to try again running the program, wait here a little before. } +} - sleep 5; #- allow lpr to send pages. - local *F; - open F, "chroot $prefix/ /usr/bin/lpq -P$queue |"; - my @lpq_output = grep { !/^no entries/ && !(/^Rank\s+Owner/ .. /^\s*$/) } <F>; - close F; +#-****************************************************************************** +#- write functions +#-****************************************************************************** - @lpq_output; +#------------------------------------------------------------------------------ +#- given the path queue_path, we create all the required spool directory +#------------------------------------------------------------------------------ +sub create_spool_dir($) { + my ($queue_path) = @_; + my $complete_path = "$prefix/$queue_path"; + + commands::mkdir_("-p", $complete_path); + + unless ($::testing) { + #-redhat want that "drwxr-xr-x root lp" + my $gid_lp = (getpwnam("lp"))[3]; + chown 0, $gid_lp, $complete_path + or die "An error has occurred - can't chgrp $complete_path to lp $!"; + } } #------------------------------------------------------------------------------ -#- interface function +#-given the input spec file 'input', and the target output file 'output' +#-we set the fields specified by fieldname to the values in fieldval +#-nval is the number of fields to set +#-Doesnt currently catch error exec'ing sed yet #------------------------------------------------------------------------------ +sub create_config_file($$%) { + my ($inputfile, $outputfile, %toreplace) = @_; + template2file("$prefix/$inputfile", "$prefix/$outputfile", %toreplace); + eval { commands::chown_("root.lp", "$prefix/$outputfile") }; +} + #------------------------------------------------------------------------------ -#- fonction de test +#-copy master filter to the spool dir #------------------------------------------------------------------------------ -sub test { - $::testing = 1; - $printer::prefix=""; - - read_printer_db(); - - print "the dump\n"; - print Dumper(%thedb); - - - # - #eval { printer::create_spool_dir("/tmp/titi/", ".") }; - #print $@; - #eval { printer::copy_master_filter("/tmp/titi/", ".") }; - #print $@; - # - # - #eval { printer::create_config_file("files/postscript.cfg.in", "files/postscript.cfg","./", - # ( - # gsdevice => "titi", - # resolution => "tata", - # )); - # }; - #print $@; - # - # - # - #printer::configure_queue(\%printer::ex_printcap_entry, "/"); +sub copy_master_filter($) { + my ($queue_path) = @_; + my $complete_path = "$prefix/$queue_path/filter"; + my $master_filter = "$prefix/$PRINTER_FILTER_DIR/master-filter"; + + eval { commands::cp('-f', $master_filter, $complete_path) }; + $@ and die "Can't copy $master_filter to $complete_path $!"; + eval { commands::chown_("root.lp", $complete_path); }; } -#-###################################################################################### -#- Wonderful perl :( -#-###################################################################################### -1; # +#------------------------------------------------------------------------------ +#- given a PrintCap Entry, create the spool dir and special +#- rhs-printfilters related config files which are required +#------------------------------------------------------------------------------ +my $intro_printcap_test = " +# +# Please don't edit this file directly unless you know what you are doing! +# Look at the printcap(5) man page for more info. +# Be warned that the control-panel printtool requires a very strict format! +# +# This file can be edited with printerdrake or printtool. +# + +"; + +sub configure_queue($) { + my ($entry) = @_; + + for ($entry->{mode}) { + /cups/ && do { + #- at this level, we are using lpadmin to create a local printer (only local + #- printer are supported with printerdrake). + require run_program; + run_program::rooted($prefix, "lpadmin", + "-p", $entry->{QUEUE}, + $entry->{State} eq 'Idle' && $entry->{Accepting} eq 'Yes' ? ("-E") : (), + "-v", $entry->{DeviceURI}, + "-m", $entry->{cupsPPD}, + $entry->{Info} ? ("-D", $entry->{Info}) : (), + $entry->{Location} ? ("-L", $entry->{Location}) : (), + ); + last }; + /lpr/ && do { + #- old style configuration scheme for lpr. + my $queue_path = "$entry->{SPOOLDIR}"; + create_spool_dir($queue_path); + + my $get_name_file = sub { + my ($name) = @_; + ("$PRINTER_FILTER_DIR/$name.in", "$entry->{SPOOLDIR}/$name") + }; + my ($filein, $file); + my %fieldname = (); + my $dbentry = $thedb{($entry->{DBENTRY})} or die "no dbentry"; + + #- make general.cfg + ($filein, $file) = &$get_name_file("general.cfg"); + $fieldname{ascps_trans} = $entry->{ASCII_TO_PS} || $dbentry->{GSDRIVER} eq 'ppa' ? "YES" : "NO"; + $fieldname{desiredto} = $dbentry->{GSDRIVER} ne "TEXT" ? "ps" : "asc"; + $fieldname{papersize} = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter"; + $fieldname{printertype} = $entry->{TYPE}; + create_config_file($filein, $file, %fieldname); + + #- now do postscript.cfg + ($filein, $file) = &$get_name_file("postscript.cfg"); + %fieldname = (); + $fieldname{gsdevice} = $dbentry->{GSDRIVER}; + $fieldname{papersize} = $entry->{PAPERSIZE} ? $entry->{PAPERSIZE} : "letter"; + $fieldname{resolution} = $entry->{RESOLUTION}; + $fieldname{color} = $entry->{BITSPERPIXEL} ne "Default" && + (($dbentry->{GSDRIVER} ne "uniprint" && "-dBitsPerPixel=") . $entry->{BITSPERPIXEL}); + $fieldname{reversepages} = $entry->{REVERSE_ORDER} ? "YES" : ""; + $fieldname{extragsoptions} = "\"$entry->{EXTRA_GS_OPTIONS}\""; + $fieldname{pssendeof} = $entry->{AUTOSENDEOF} ? ($dbentry->{GSDRIVER} eq "POSTSCRIPT" ? "YES" : "NO") : "NO"; + $fieldname{nup} = $entry->{NUP}; + $fieldname{rtlftmar} = $entry->{RTLFTMAR}; + $fieldname{topbotmar} = $entry->{TOPBOTMAR}; + create_config_file($filein, $file, %fieldname); + + #- finally, make textonly.cfg + ($filein, $file) = &$get_name_file("textonly.cfg"); + %fieldname = (); + $fieldname{textonlyoptions} = "\"$entry->{TEXTONLYOPTIONS}\""; + $fieldname{crlftrans} = $entry->{CRLF} ? "YES" : ""; + $fieldname{textsendeof} = $entry->{AUTOSENDEOF} ? ($dbentry->{GSDRIVER} eq "POSTSCRIPT" ? "NO" : "YES") : "NO"; + create_config_file($filein, $file, %fieldname); + + if ($entry->{TYPE} eq "SMB") { + #- simple config file required if SMB printer + my $config_file = "$prefix$queue_path/.config"; + local *F; + open F, ">$config_file" or die "Can't create $config_file $!"; + print F "share='\\\\$entry->{SMBHOST}\\$entry->{SMBSHARE}'\n"; + print F "hostip=$entry->{SMBHOSTIP}\n"; + print F "user='$entry->{SMBUSER}'\n"; + print F "password='$entry->{SMBPASSWD}'\n"; + print F "workgroup='$entry->{SMBWORKGROUP}'\n"; + close F; + eval { chmod 0640, $config_file; commands::chown_("root.lp", $config_file) }; + } elsif ($entry->{TYPE} eq "NCP") { + #- same for NCP printer + my $config_file = "$prefix$queue_path/.config"; + local *F; + open F, ">$config_file" or die "Can't create $config_file $!"; + print F "server=$entry->{NCPHOST}\n"; + print F "queue=$entry->{NCPQUEUE}\n"; + print F "user=$entry->{NCPUSER}\n"; + print F "password=$entry->{NCPPASSWD}\n"; + close F; + eval { chmod 0640, $config_file; commands::chown_("root.lp", $config_file) }; + } + + copy_master_filter($queue_path); + + #-now the printcap file, note this one contains all the printer (use configured for that). + local *PRINTCAP; + open PRINTCAP, ">$prefix/etc/printcap" or die "Can't open printcap file $!"; + print PRINTCAP $intro_printcap_test; + foreach (values %{$entry->{configured}}) { + $_->{DBENTRY} = $thedb_gsdriver{$_->{GSDRIVER}}{ENTRY} unless defined $_->{DBENTRY}; + my $db_ = $thedb{$_->{DBENTRY}} or next; #die "no dbentry"; + + $_->{SPOOLDIR} ||= default_spooldir($_); + $_->{IF} ||= "$_->{SPOOLDIR}/filter"; + $_->{AF} ||= "$_->{SPOOLDIR}/acct"; + + printf PRINTCAP "##PRINTTOOL3## %s %s %s %s %s %s %s%s\n", + $_->{TYPE} || '{}', + $db_->{GSDRIVER} || '{}', + $_->{RESOLUTION} || '{}', + $_->{PAPERSIZE} || '{}', + '{}', + $db_->{ENTRY} || '{}', + $_->{BITSPERPIXEL} || '{}', + $_->{CRLF} ? " 1" : ""; + + print PRINTCAP "$_->{QUEUE}:\\\n"; + print PRINTCAP "\t:sd=$_->{SPOOLDIR}:\\\n"; + print PRINTCAP "\t:mx#0:\\\n\t:sh:\\\n"; + + if ($_->{TYPE} eq "LOCAL") { + print PRINTCAP "\t:lp=$_->{DEVICE}:\\\n"; + } elsif ($_->{TYPE} eq "REMOTE") { + print PRINTCAP "\t:rm=$_->{REMOTEHOST}:\\\n"; + print PRINTCAP "\t:rp=$_->{REMOTEQUEUE}:\\\n"; + } else { + #- (pcentry->Type == (PRINTER_SMB | PRINTER_NCP)) + print PRINTCAP "\t:lp=/dev/null:\\\n"; + print PRINTCAP "\t:af=$_->{AF}\\\n"; + } + + #- cheating to get the input filter! + print PRINTCAP "\t:if=$_->{IF}:\n"; + print PRINTCAP "\n"; + } + eval { commands::chown_("root.lp", "$prefix/etc/printcap") }; + + my $useUSB = 0; + foreach (values %{$entry->{configured}}) { + $useUSB ||= $_->{DEVICE} =~ /usb/; + } + if ($useUSB) { + my $f = "$prefix/etc/sysconfig/usb"; + my %usb = getVarsFromSh($f); + $usb{PRINTER} = "yes"; + setVarsInSh($f, \%usb); + } + last }; + } +} + +#- use the queue currently configured at the top of printer hash. +sub remove_queue($) { + my ($printer) = @_; + $printer->{configured}{$printer->{QUEUE}} or return; #- something strange at this point. + + if ($printer->{mode} eq 'cups') { + require run_program; + run_program::rooted($prefix, "lpadmin", "-x", $printer->{QUEUE}); + } + delete $printer->{configured}{$printer->{queue}}; +} -=head1 AUTHOR +sub restart_queue($) { + my ($printer) = @_; + my $queue = default_queue($printer); + + for ($printer->{mode}) { + /cups/ && do { + #- restart cups before cleaning the queue. + require run_program; + run_program::rooted($prefix, "/etc/rc.d/init.d/cups start"); sleep 1; + run_program::rooted($prefix, "lprm-cups", "-P$queue", "-"); + last }; + /lpr/ && do { + #- restart lpd after cleaning the queue. + foreach (("/var/spool/lpd/$queue/lock", "/var/spool/lpd/lpd.lock")) { + my $pidlpd = (cat_("$prefix$_"))[0]; + kill 'TERM', $pidlpd if $pidlpd; + unlink "$prefix$_"; + } + require run_program; + run_program::rooted($prefix, "lprm-lpd", "-P$queue", "-"); sleep 1; + run_program::rooted($prefix, "lpd"); sleep 1; + last }; + } +} -pad. +sub print_pages($@) { + my ($printer, @pages) = @_; + my $queue = default_queue($printer); + my ($lpr, $lpq); + + for ($printer->{mode}) { + /cups/ and ($lpr, $lpq) = ("/usr/bin/lpr-cups", "/usr/bin/lpq-cups"); + /lpr/ and ($lpr, $lpq) = ("/usr/bin/lpq-lpd", "/usr/bin/lpq-lpd"); + } -=cut + require run_program; + foreach (@pages) { + run_program::rooted($prefix, $lpr, "-P$queue", $_); + } + sleep 5; #- allow lpr to send pages. + local *F; open F, "chroot $prefix/ $lpq -P$queue |"; + my @lpq_output = grep { !/^no entries/ && !(/^Rank\s+Owner/ .. /^\s*$/) } <F>; + close F; + @lpq_output; +} + +#-###################################################################################### +#- Wonderful perl :( +#-###################################################################################### +1; diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm index bb3acd9fc..cd8ee038b 100644 --- a/perl-install/printerdrake.pm +++ b/perl-install/printerdrake.pm @@ -32,7 +32,8 @@ sub setup_local($$$) { my @str = (); my @parport = auto_detect($in); foreach (@parport) { - push @str, _("A printer, model \"%s\", has been detected on ", $_->{val}{DESCRIPTION}) . $_->{port}; + $_->{val}{DESCRIPTION} and push @str, _("A printer, model \"%s\", has been detected on ", + $_->{val}{DESCRIPTION}) . $_->{port}; } if (@str) { @port = map { $_->{port} } @parport; @@ -47,7 +48,10 @@ sub setup_local($$$) { _("Printer Device") => {val => \$printer->{DEVICE}, list => \@port } ], ); - #- select right DBENTRY according to device selected. + #- make the DeviceURI from DEVICE. + $printer->{DeviceURI} = ($printer->{DEVICE} =~ /usb/ ? "usb:" : "parallel:") . $printer->{DEVICE}; + + #- select right DBENTRY according to device selected. #- TODO with cups (keep all configuration files) foreach (@parport) { $printer->{DEVICE} eq $_->{port} or next; $printer->{DBENTRY} = $printer::descr_to_db{common::bestMatchSentence2($parport[0]{val}{DESCRIPTION}, @@ -56,6 +60,18 @@ _("Printer Device") => {val => \$printer->{DEVICE}, list => \@port } ], 1; } +sub setup_uri_local($$$) { + my ($printer, $in, $install) = @_; + + my @direct_uri = printer::get_direct_uri(); + return if !$in->ask_from_entries_refH(_("Local Printer Device (URI)"), + _("What URI device is your printer connected to +(note that parallel:/dev/lp0 is equivalent to LPT1:)?"), [ +_("Printer Device URI") => { val => \$printer->{DeviceURI}, list => \@direct_uri } ], + ); + 1; +} + sub setup_remote($$$) { my ($printer, $in, $install) = @_; @@ -66,6 +82,8 @@ on that server which jobs should be placed in."), [ _("Remote hostname") => \$printer->{REMOTEHOST}, _("Remote queue") => \$printer->{REMOTEQUEUE}, ], ); + #- make the DeviceURI from DEVICE. + $printer->{DeviceURI} = "lpd://$printer->{REMOTEHOST}/$printer->{REMOTEQUEUE}"; } sub setup_smb($$$) { @@ -92,7 +110,16 @@ _("Workgroup") => \$printer->{SMBWORKGROUP} ], return 0; }, ); + #- make the DeviceURI from DEVICE, try to probe for available variable to build a some suitable URI. + #- Yes, SMBWORKGROUP is not used here, seems to be not usefull for cups. + $printer->{DeviceURI} = join '', ("smb://", + ($printer->{SMBUSER} && ($printer->{SMBUSER} . + ($printer->{SMBPASSWD} && ":$printer->{SMBPASSWD}") . "@")), + ($printer->{SMBHOST} || $printer->{SMBHOSTIP}), + "/$printer->{SMBSHARE}"); + &$install('samba'); + $printer->{mode} eq 'cups' and printer::restart_queue($printer); 1; } @@ -113,8 +140,74 @@ _("Password") => {val => \$printer->{NCPPASSWD}, hidden => 1} ], 1; } +sub setup_uri_net($$$) { + my ($printer, $in, $install) = @_; + + return if !$in->ask_from_entries_refH(_("Network Printer Options (URI)"), +_("Choose the right Device URI for a network printer or a local file. Examples: + file:/path/to/filename.prn + http://hostname:631/ipp/port1 + ipp://hostname/ipp/port1 + lpq://hostname/queue + socket://hostname + socket://hostname:9100"), [ +_("Printer Device URI") => \$printer->{DeviceURI} ], + ); + 1; +} + sub setup_gsdriver($$$;$) { my ($printer, $in, $install, $upNetwork) = @_; + for ($printer->{mode}) { + /cups/ && return setup_gsdriver_cups($printer, $in, $install, $upNetwork); + /lpr/ && return setup_gsdriver_lpr($printer, $in, $install, $upNetwork); + die "mode not chosen to configure a printer"; + } +} + +sub setup_gsdriver_cups($$$;$) { + my ($printer, $in, $install, $upNetwork) = @_; + my $testpage = "/usr/share/cups/data/testprint.ps"; + + while (1) { + $printer->{cupsDescr} ||= printer::get_descr_from_ppd($printer); + print ">> $printer->{cupsDescr}\n"; + $printer->{cupsDescr} = $in->ask_from_treelist('', _("What type of printer do you have?"), '|', + [ keys %printer::descr_to_ppd ], $printer->{cupsDescr}) or return; + $printer->{cupsPPD} = $printer::descr_to_ppd{$printer->{cupsDescr}}; + + $printer->{complete} = 1; + printer::copy_printer_params($printer, $printer->{configured}{$printer->{QUEUE}} ||= {}); + printer::configure_queue($printer); + $printer->{complete} = 0; + + if ($in->ask_yesorno('', _("Do you want to test printing?"), 1)) { + my @lpq_output; + { + my $w = $in->wait_message('', _("Printing test page(s)...")); + + $upNetwork and do { &$upNetwork(); undef $upNetwork; sleep(1) }; + @lpq_output = printer::print_pages($printer, $testpage); + } + + if (@lpq_output) { + $in->ask_yesorno('', _("Test page(s) have been sent to the printer daemon. +This may take a little time before printer start. +Printing status:\n%s\n\nDoes it work properly?", "@lpq_output"), 1) and last; + } else { + $in->ask_yesorno('', _("Test page(s) have been sent to the printer daemon. +This may take a little time before printer start. +Does it work properly?"), 1) and last; + } + } else { + last; + } + } + $printer->{complete} = 1; +} + +sub setup_gsdriver_lpr($$$;$) { + my ($printer, $in, $install, $upNetwork) = @_; my $action; my @action = qw(ascii ps both done); my %action = ( @@ -132,13 +225,13 @@ sub setup_gsdriver($$$;$) { [ @printer::entry_db_description ], { %printer::descr_to_help }, $printer::db_to_descr{$printer->{DBENTRY}}, - ) - }; + ) + }; }; $@ =~ /^ask_from_list cancel/ and return; my %db_entry = %{$printer::thedb{$printer->{DBENTRY}}}; - #- specific printer driver to install. + #- specific printer drivers to install. &$install('pnm2ppa') if $db_entry{GSDRIVER} eq 'ppa'; my @list_res = @{$db_entry{RESOLUTION} || []}; @@ -209,8 +302,8 @@ _("Extra Text options") => \$printer->{TEXTONLYOPTIONS}, my $w = $in->wait_message('', _("Printing test page(s)...")); $upNetwork and do { &$upNetwork(); undef $upNetwork; sleep(1) }; - printer::restart_queue(printer::default_queue($printer->{QUEUE})); - @lpq_output = printer::print_pages(printer::default_queue($printer->{QUEUE}), @testpages); + printer::restart_queue($printer); + @lpq_output = printer::print_pages($printer, @testpages); } if (@lpq_output) { @@ -227,7 +320,7 @@ Does it work properly?"), 1) ? 'done' : 'change'; $printer->{complete} = 1; } -#- Program entry point. +#- Program entry point for configuration with lpr or cups (stored in $mode). sub main($$$;$) { my ($printer, $in, $install, $upNetwork) = @_; my ($queue, $continue) = ('', 1); @@ -251,51 +344,71 @@ You can add some more or change the existing ones."), } $queue eq 'Done' and last; - &$install('rhs-printfilters') unless $::testing; - printer::read_printer_db(); + #- switch according to what is being installed: cups, lpr or other. + for ($printer->{mode}) { + /cups/ && do { &$install('cups') unless $::testing; + printer::poll_ppd_base(); last }; + /lpr/ && do { &$install('rhs-printfilters') unless $::testing; + printer::read_printer_db(); last }; + } printer::copy_printer_params($printer->{configured}{$queue}, $printer) if $printer->{configured}{$queue}; $printer->{OLD_QUEUE} = $printer->{QUEUE} = $queue; #- keep in mind old name of queue (in case of changing) while ($continue) { - $printer->{TYPE} = 'LOCAL' unless $printer::printer_type_inv{$printer->{TYPE}}; + $printer::printer_type_inv{$printer->{TYPE}} or $printer->{TYPE} = printer::default_printer_type($printer); $printer->{str_type} = $printer::printer_type_inv{$printer->{TYPE}}; if ($::beginner) { $printer->{str_type} = $in->ask_from_list_(_("Select Printer Connection"), _("How is the printer connected?"), - [ keys %printer::printer_type ], + [ printer::printer_type($printer) ], $printer->{str_type}, ); } else { - $in->ask_from_entries_refH([_("Select Printer Connection"), _("Ok"), $::beginner ? () : _("Remove queue")], + if ($printer->{mode} eq 'cups') { + $in->ask_from_entries_refH([_("Select Printer Connection"), _("Ok"), $::beginner ? () : _("Remove queue")], +_("Every printer managed by CUPS need a name (for example lp). +Other parameter like the description of the printer or its location +can be defined. What name should be used for this printer and +how is the printer connected?"), [ +_("Name of printer") => { val => \$printer->{QUEUE} }, +_("Description") => { val => \$printer->{Info} }, +_("Location") => { val => \$printer->{Location} }, +_("Printer Connection") => { val => \$printer->{str_type}, not_edit => 1, list => [ printer::printer_type($printer) ] }, + ], + ) or printer::remove_queue($printer), $continue = 1, last; + } else { + $in->ask_from_entries_refH([_("Select Printer Connection"), _("Ok"), $::beginner ? () : _("Remove queue")], _("Every print queue (which print jobs are directed to) needs a name (often lp) and a spool directory associated with it. What name and directory should be used for this queue and how is the printer connected?"), [ _("Name of queue") => { val => \$printer->{QUEUE} }, _("Spool directory") => { val => \$printer->{SPOOLDIR} }, -_("Printer Connection") => { val => \$printer->{str_type}, not_edit => 1, list => [ keys %printer::printer_type ] }, +_("Printer Connection") => { val => \$printer->{str_type}, not_edit => 1, list => [ printer::printer_type($printer) ] }, ], changed => sub { - $printer->{SPOOLDIR} = "$printer::spooldir/" . - printer::default_queue($printer->{QUEUE}) unless $_[0]; + $printer->{SPOOLDIR} = printer::default_spooldir($printer) unless $_[0]; } - ) or delete $printer->{configured}{$queue}, $continue = 1, last; + ) or printer::remove_queue($printer), $continue = 1, last; + } } $printer->{TYPE} = $printer::printer_type{$printer->{str_type}}; $continue = 0; - for ($printer->{TYPE}) { - /LOCAL/ and setup_local ($printer, $in, $install) and last; - /REMOTE/ and setup_remote($printer, $in, $install) and last; - /SMB/ and setup_smb ($printer, $in, $install) and last; - /NCP/ and setup_ncp ($printer, $in, $install) and last; + for ($printer->{TYPE}) { #- chooser lpr/cups ? not good ! + /URI_LOCAL/ and setup_uri_local($printer, $in, $install) and last; + /URI_NET/ and setup_uri_net ($printer, $in, $install) and last; + /LOCAL/ and setup_local ($printer, $in, $install) and last; + /REMOTE/ and setup_remote ($printer, $in, $install) and last; #- make common for cups/lpr ? + /SMB/ and setup_smb ($printer, $in, $install) and last; #- make common for cups/lpr ? + /NCP/ and setup_ncp ($printer, $in, $install) and last; $continue = 1; last; } } - #- configure ghostscript driver to be used. - if (!$continue && setup_gsdriver($printer, $in, $install, $printer->{TYPE} ne 'LOCAL' && $upNetwork)) { + #- configure specific part according to lpr/cups. + if (!$continue && setup_gsdriver($printer, $in, $install, $printer->{TYPE} !~ /LOCAL/ && $upNetwork)) { delete $printer->{OLD_QUEUE} if $printer->{QUEUE} ne $printer->{OLD_QUEUE} && $printer->{configured}{$printer->{QUEUE}}; $continue = !$::beginner; @@ -304,3 +417,4 @@ _("Printer Connection") => { val => \$printer->{str_type}, not_edit => 1, list = } } } + |