#!/usr/bin/perl -w ################################################################ # # Welcome to the CUPS PAP backend. A colleague downloaded a # Shell script off the net that was supposed to do all of # this, and it didn't work very well... # At all, actually. So I decided to whip up my own in Perl. # This is that script. I have done some optimization based on # the CUPS "Writing Backends" document as provided w/ version # 1.1.17. # # It works with CUPS 1.1.17 or newer, # possibly older, I don't know - as well as any modern # (1.4b2+) version of Netatalk upto and probably surpassing # the 1.6.0 release. # # This software is to be considered public domain. Do with it as # you will. # # Written 5/Dec/2002 by Matthew Keller # ################################################################ # # INSTALLATION (by the aforementioned "colleague") # # Requirements: Perl and netatalk. If you don't know what # those are, I think you're in over you're head... # # Save this script as /usr/lib/cups/backend/papbackend # (....or wherever you have the other backends if you # aren't running a stock install of CUPS). Make sure it is # executable! # Then, make sure the entry for the AppleTalk printer in # /etc/cups/printers.conf is declared with a URI thus: # # DeviceURI papbackend://"Printer Name"@"Some Zone" # # THE QUOTES ARE IMPORTANT AND NECESSARY if you have spaces # in your Printer Name or your Zone Name. If you have no # zones on your network, then "Printer Name"@* should work. # # *NOTE: The URI can also be declared in the CUPS web interface # and will get properly entered in printers.conf if you do it # that way. But it gets mangled when viewing printer # properties via the web interface. This is OK, though I # don't know why CUPS does this! As long as it's OK in # printers.conf, that's all that matters. # # -- 6/Dec/2002 by Romeyn prescott # ############################################################### # # If there aren't at least 5 arguments, there is a problem. # Tell the user and die. if(scalar(@ARGV) < 5) { die "pap backend is quite unhappy. Mainly because there are only " . scalar(@ARGV) . " elements on the argument list and there should be at least 5."; } # Trash or stash variables as desired shift @ARGV; # We don't care about the job ID my $user=shift @ARGV; # We don't care about the user either, # but we'll pretend we do. shift @ARGV; # We couldn't care less about the title. my $copies=shift @ARGV; # Number of copies we definitely care about if($copies < 1) { $copies = 1; } # Sanity check. shift @ARGV; # Options? Bah! # Glean the device from the environment and format it # The device is is assumed to be a properly formated NBP_NAME # (see man page for nbp_name) for the printer, preceded # by CUPs' papbackend:// garbage. Make sure any spaced words # are quoted properly, or else pap will die. NO TRAILING SLASHES, # ASSHAT!!!! # Right: papbackend://"My Printer"@"My Zone" # Wrong: papbackend://"My Printer"@"My Zone"/ # Wrong: papbackend://My Printer@My Zone # Wrong: papbackend://"My Printer@My Zone" my $device=$ENV{DEVICE_URI}; $device =~ s/^papbackend:\/\///; # Deal with the file my $file=""; unless(scalar(@ARGV)) { # Is @ARGV all popped out? # File must be on stdin, put it in $file. $file="/var/tmp/$$.prn"; $copies=1; # CUPS want's backends to NOT trust command-line # copies for STDIN-spooled jobs # Open it, write to it, close it, else die open(TMF,">$file") or die "Could not write to $file! $!\n"; print TMF ; close TMF; } else { # File was spooled to a file, and is supplied. $file=shift @ARGV; # The last argument is the filename. } # Print it... Many times if necessary. while($copies > 0) { # Send it to the pap program `/usr/local/bin/pap -p $device $file`; $copies--; } # Burn the evidence unlink $file;