diff options
author | Till Kamppeter <tkamppeter@mandriva.com> | 2002-02-05 23:42:28 +0000 |
---|---|---|
committer | Till Kamppeter <tkamppeter@mandriva.com> | 2002-02-05 23:42:28 +0000 |
commit | d91e657e98161963aee317bf02d64ad2b64f835c (patch) | |
tree | ad10acf692d5bd2c1bd318caafbe985765b24947 | |
parent | c01a3f6418564b123763043bb8be29c4a326d426 (diff) | |
download | drakx-d91e657e98161963aee317bf02d64ad2b64f835c.tar drakx-d91e657e98161963aee317bf02d64ad2b64f835c.tar.gz drakx-d91e657e98161963aee317bf02d64ad2b64f835c.tar.bz2 drakx-d91e657e98161963aee317bf02d64ad2b64f835c.tar.xz drakx-d91e657e98161963aee317bf02d64ad2b64f835c.zip |
Added automatic configuration of HPOJ for HP's multi-function devices.
-rw-r--r-- | perl-install/printer.pm | 106 | ||||
-rw-r--r-- | perl-install/printerdrake.pm | 37 |
2 files changed, 137 insertions, 6 deletions
diff --git a/perl-install/printer.pm b/perl-install/printer.pm index 98e7b4d85..d75e03e76 100644 --- a/perl-install/printer.pm +++ b/perl-install/printer.pm @@ -1413,11 +1413,113 @@ sub get_copiable_queues { sub copy_foomatic_queue { my ($printer, $oldqueue, $oldspooler, $newqueue) = @_; run_program::rooted($prefix, "foomatic-configure", "-q", - "-s", $printer->{SPOOLER}, - "-n", $newqueue, + "-s", $printer->{SPOOLER}, + "-n", $newqueue, "-C", $oldspooler, $oldqueue); } +sub configure_hpoj { + my ($device, @autodetected) = @_; + # Get the model ID as auto-detected + my $model; + foreach (@autodetected) { + $device eq $_->{port} or next; + $model = $_->{val}{MODEL}; + last; + } + #$device = "/dev/usb/lp1"; $model = "DeskJet 990C"; + # Read the HPOJ config file and check whether this device is already + # configured + my $deviceconfigured = 0; + my $ptaldevice; + my $hpoj_config = "/etc/ptal-start.conf"; + local *HPOJCONFIG; + if (open HPOJCONFIG, ("< $prefix$hpoj_config")) { + while ($line = <HPOJCONFIG>) { + chomp $line; + # Comment or blank line + next if (($line =~ /^\s*\#/) || ($line =~ /^\s*$/)); + # Only lines beginning with "ptal-mlcd" are interesting. + next if ($line !~ /^\s*ptal-mlcd\s+(\S+)\s+/); + $ptaldevice = "mlc:$1"; + if ($ptaldevice =~ /^mlc:par:(\d+)$/) { + # Parallel device + next if ($device =~ /usb/); + if ($line =~ m!-device\s+$device!) { + # Our new device is parallel and already configured + # by the current line + $deviceconfigured = 1; + last; + } + } elsif ($ptaldevice =~ /^mlc:usb:(.+)$/) { + # USB device + next if ($device !~ /usb/); + if ($line =~ /-devidmatch\s+(\"[^\"]*\")/) { + $configuredmodel = $1; + $configuredmodel =~ s/\"//g; + $configuredmodel =~ s/^mdl://; + $configuredmodel =~ s/^model://; + $configuredmodel =~ s/;$//; + if ($configuredmodel eq $model) { + # Our new device is USB and already configured + # by the current line + $deviceconfigured = 1; + last; + } + } elsif ($line =~ m!-device\s+(/dev/usb/lp\d+)!) { + if ($1 eq $device) { + # Our new device is USB and already configured + # by the current line + $deviceconfigured = 1; + last; + } + } + } + } + close HPOJCONFIG; + } + + # It's all done for us, the device is already configured + return $ptaldevice if $deviceconfigured; + + # Configure the device + my $entry; + if ($device =~ /usb/) { + # USB device + my $ptaldevicemodel = $model; + $ptaldevicemodel =~ s/\s+/_/g; + $entry = "\nptal-mlcd usb:$ptaldevicemodel -device /dev/usb/lp* -devidmatch \"$model;\" \$PTAL_MLCD_CMDLINE_APPEND\nptal-printd mlc:usb:$ptaldevicemodel \$PTAL_PRINTD_CMDLINE_APPEND\n"; + $ptaldevice = "mlc:usb:$ptaldevicemodel"; + } else { + # parallel device + # auto-detect the parallel port addresses + $device =~ m!^/dev/lp(\d+)$!; + my $portnumber = $1; + my $parport_addresses = + `cat /proc/sys/dev/parport/parport$portnumber/base-addr`; + my $address_arg; + if ($parport_addresses =~ /^\s*(\d+)\s+(\d+)\s*$/) { + $address_arg = sprintf(" -base 0x%x -basehigh 0x%x", $1, $2); + } elsif ($parport_addresses =~ /^\s*(\d+)\s*$/) { + $address_arg = sprintf(" -base 0x%x", $1); + } else { + $address_arg = ""; + } + $entry = "\nptal-mlcd par:$portnumber -device $device$address_arg \$PTAL_MLCD_CMDLINE_APPEND\nptal-printd mlc:par:$portnumber \$PTAL_PRINTD_CMDLINE_APPEND\n"; + $ptaldevice = "mlc:par:$portnumber"; + } + + # Add new entry to HPOJ's config file + open(HPOJCONFIG,">> $prefix$hpoj_config") || + die "Could not open $hpoj_config for writing!\n"; + print HPOJCONFIG $entry; + close HPOJCONFIG; + # Restart HPOJ + restart_service("hpoj"); + # Return HPOJ device name to form the URI + return $ptaldevice; +} + #-###################################################################################### #- Wonderful perl :( diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm index 126ade703..d1aa9d851 100644 --- a/perl-install/printerdrake.pm +++ b/perl-install/printerdrake.pm @@ -448,16 +448,45 @@ _(" (Parallel Ports: /dev/lp0, /dev/lp1, ..., equivalent to LPT1:, LPT2:, ..., 1 } } + #- Check whether the printer is an HP multi-function device and + #- configure HPOJ if it is one + + my $ptaldevice = ""; + if (($menuchoice =~ /HP OfficeJet/i) || + ($menuchoice =~ /HP PSC/i) || + ($menuchoice =~ /HP PhotoSmart/i) || + ($menuchoice =~ /HP LaserJet 1100/i) || + ($menuchoice =~ /HP LaserJet 1200/i) || + ($menuchoice =~ /HP LaserJet 1220/i) || + ($menuchoice =~ /HP LaserJet 3200/i)) { + # Install HPOJ package + if ((!$::testing) && + (!printer::files_exist((qw(/usr/sbin/ptal-mlcd + /etc/ptal-start.conf))))) { + my $w = $in->wait_message('', _("Installing HPOJ package...")); + $in->do_pkgs->install('hpoj'); + } + # Configure and start HPOJ + $ptaldevice = printer::configure_hpoj($device, @parport); + + # make the DeviceURI from $device. + $printer->{currentqueue}{'connect'} = "ptal:/" . $ptaldevice; + } else { + # make the DeviceURI from $device. + $printer->{currentqueue}{'connect'} = "file:" . $device; + } + #- if CUPS is the spooler, make sure that CUPS knows the device if ($printer->{SPOOLER} eq "cups") { my $w = $in->wait_message ('', _("Making printer port available for CUPS ...")); - printer::assure_device_is_available_for_cups($device); + if ($ptaldevice eq "") { + printer::assure_device_is_available_for_cups($device); + } else { + printer::assure_device_is_available_for_cups($ptaldevice); + } } - #- make the DeviceURI from $device. - $printer->{currentqueue}{'connect'} = "file:" . $device; - #- Read the printer driver database if necessary if ((keys %printer::thedb) == 0) { my $w = $in->wait_message('', _("Reading printer database ...")); |