# $Id$ # # Tea4CUPS : Tee for CUPS # # (c) 2005 Jerome Alet # (c) 2005 Peter Stuge # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # # First we set all top-level directives in the [global] section [global] # Should we log debugging information to CUPS' error_log file ? # defaults to No if unset. debug : yes # In which directory will we create our files ? It must already exist ! # This directive MUST be present since there's no sane default value. # Can be set either in the [global] section or any print queue section. # The value defined in a print queue section takes precedence over the # value defined in the [global] section. # directory : /var/spool/tea4cups/ directory : /var/spool/cups/ # Should Tea4CUPS keep the files it creates once all hooks have ended ? # Defaults to No if unset, meaning that files are automatically deleted # once all hooks have ended. # Can be set either in the [global] section or any print queue section. # The value defined in a print queue section takes precedence over the # value defined in the [global] section. # BEWARE : this may use huge amounts of disk space ! # keepfiles : yes # Should we serialize the launch of all hooks : launch one after # the other to save some system resources. # Defaults to No if unset, meaning that all hooks are launched in # parallel. # # NB : in any case, hooks' names are sorted alphabetically and # are launched in this sort order (obviously when launched in parallel # this is unnoticeable). # # Can be set either in the [global] section or any print queue section. # The value defined in a print queue section takes precedence over the # value defined in the [global] section. # serialize : yes # When executing the contents of a prehook or posthook directive, # tea4cups makes the following environment variables available to your # own commands : # # TEAPRINTERNAME : The print queue name. # TEADIRECTORY : Tea4CUPS output directory. # TEADATAFILE : Full name of Tea4CUPS work file (in $TEADIRECTORY). # TEAJOBSIZE : Job's size in bytes. # TEAMD5SUM : MD5 sum of the job's datas. # TEACLIENTHOST : Client's hostname or IP address. # TEAJOBID : Job's Id. # TEAUSERNAME : Name of the user who launched the print job. # TEATITLE : Job's title. # TEACOPIES : Number of copies requested. # TEAOPTIONS : Options of the print job. # TEAINPUTFILE : Job's data file or empty when job read from stdin. # TEABILLING : Job's billing code (lp -o job-billing=SomeCode file.ps) # TEACONTROLFILE : Job's IPP message file (usually /var/spool/cups/c?????) # # Your own commands will mostly be interested in TEADATAFILE which is # the name of the file from which your commands may extract the final # job's datas. Don't rely on TEAINPUTFILE, use TEADATAFILE instead # since the first one may be empty depending on your printer driver. # Some prehooks and posthooks # # Prehooks are guaranteed to be launched # BEFORE the job's datas are sent to the printer, and # posthooks are guaranteed to be launched AFTER the job's # datas have been sent to the printer. # # prehook names are completely free BUT THEY MUST BEGIN WITH 'prehook_' # posthook names are completely free BUT THEY MUST BEGIN WITH 'posthook_' # # An additionnal environment variable is made available to posthooks, # named TEASTATUS which contains the exitcode of the real CUPS backend. # If defined, the normal value is 0, meaning that the real CUPS backend exited # successfully. Any other value indicates that a problem occured # in the CUPS backend which handles the transmission of the job # to the printer. # # prehook_0 : echo "Your print job has been accepted" | smbclient -M $TEAUSERNAME # posthook_0 : echo "Your print job has been printed with status $TEASTATUS" | smbclient -M $TEAUSERNAME # # NB : as a special feature, any prehook which exits with a -1 status (255) # causes the job to NOT be sent to the real backend, effectively cancelling it. # None of the posthooks gets executed in this case, but all # remaining prehooks are still executed. # #prehook_pdf : cat $TEADATAFILE | su -c "lp -dPDFGenerator" $TEAUSERNAME #posthook_0 : cat $TEADATAFILE >/tmp/$TEAJOBID.prn # Sample section for print queue HP2100 # Uncomment and adapt to your needs. # #[HP2100] # # By using a same hook name as in the [global] section, the new # value takes precedence #posthook_0 : cat $TEADATAFILE >~$TEAUSERNAME/savejobs/$TEAJOBID.prn # An empty value deletes a value defined in the [global] section # so this particular hook doesn't get executed on this printer. #prehook_pdf : # A reflector which produces 4 copies each time : #posthook_4copies : lp -dotherprinter -n4 $CUPSDATAFILE # A simple accounting mechanism #prehook_accounting : echo $TEAPRINTERNAME $TEAJOBID $TEAUSERNAME $TEABILLING `pkpgcounter $TEADATAFILE` >/var/log/printaccounting.log # Some additionnal hooks to forbid duplicate jobs : # The prehook will use the history file to filter out duplicate jobs # checkdupes is an hypothetical command which exits -1 if the current print # job is a duplicate (same MD5 sum already found in history). # # NB : Beware of some software which embed the job printing time into the # PostScript job : two identical jobs may have different MD5 checksums # if they differ only by the value of the '%%CreationDate:' PostScript # comment ! #prehook_to_filter_duplicates : /usr/local/bin/checkdupes $TEAMD5SUM /tmp/jobmd5sums #posthook_to_filter_duplicates : echo "$TEAJOBID : $TEAMD5SUM" >>/tmp/jobmd5sums # A particular prehook can send datas to the posthook # of the same name automatically through pipes : # The file /tmp/result1 will contain the output of prehook_dialog1 # prehook_dialog1 : echo "This is pipe #1" # posthook_dialog1 : cat >/tmp/result1 # The file /tmp/result2 will contain the output of prehook_dialog2 # prehook_dialog2 : echo "This is pipe #2" # posthook_dialog2 : cat >/tmp/result2