1*4746Srica# 2*4746Srica# CDDL HEADER START 3*4746Srica# 4*4746Srica# The contents of this file are subject to the terms of the 5*4746Srica# Common Development and Distribution License (the "License"). 6*4746Srica# You may not use this file except in compliance with the License. 7*4746Srica# 8*4746Srica# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*4746Srica# or http://www.opensolaris.org/os/licensing. 10*4746Srica# See the License for the specific language governing permissions 11*4746Srica# and limitations under the License. 12*4746Srica# 13*4746Srica# When distributing Covered Code, include this CDDL HEADER in each 14*4746Srica# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*4746Srica# If applicable, add the following below this CDDL HEADER, with the 16*4746Srica# fields enclosed by brackets "[]" replaced with your own identifying 17*4746Srica# information: Portions Copyright [yyyy] [name of copyright owner] 18*4746Srica# 19*4746Srica# CDDL HEADER END 20*4746Srica# 21*4746Srica# 22*4746Srica#ident "%Z%%M% %I% %E% SMI" 23*4746Srica# 24*4746Srica# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25*4746Srica# Use is subject to license terms. 26*4746Srica# 27*4746Srica# 28*4746Srica########### 29*4746Srica## 30*4746Srica## Network Standard printer interface program for foomatic. 31*4746Srica## 32*4746Srica########### 33*4746Srica 34*4746Srica##### 35*4746Srica# We can't do much except exit if spooler/scheduler 36*4746Srica# cancels us. 37*4746Srica##### 38*4746Sricatrap 'eval exit_clean 15' 15 39*4746Srica 40*4746Srica#### 41*4746Srica# 42*4746Srica# Send standard error messages to /dev/null rather than to 43*4746Srica# the spooler. Avoids "Terminated" messages that shell puts out 44*4746Srica# when gets SIGTERM. Save standard error so it can be used 45*4746Srica# when we need it 46*4746Srica#### 47*4746Sricaexec 5>&2 2>/dev/null 3>&1 48*4746Srica 49*4746Srica#### 50*4746Srica# set some global variables 51*4746Srica#### 52*4746Srica 53*4746Srica: ${LPTMPDIR:=/tmp} 54*4746Srica: ${SPOOLDIR:=/usr/spool/lp} 55*4746Srica: ${LOCALPATH:=${SPOOLDIR}/bin} 56*4746SricaPATH="/bin:/usr/bin:${LOCALPATH}" 57*4746Sricaexit_code=0 58*4746Srica 59*4746Srica 60*4746Srica# ${LPTELL} is the name of a program that will send its 61*4746Srica# standard input to the Spooler. It is used to forward 62*4746Srica# the description of a printer fault to the Spooler, 63*4746Srica# which uses it in an alert to the administrator. 64*4746Srica##### 65*4746Sricaif [ ! -x "${LPTELL:=${LOCALPATH}/lp.tell}" ] 66*4746Sricathen 67*4746Srica fake_lptell () { 68*4746Srica header="no" 69*4746Srica while read line 70*4746Srica do 71*4746Srica if [ "no" = "${header}" ] 72*4746Srica then 73*4746Srica errmsg ERROR ${E_IP_UNKNOWN} \ 74*4746Srica "unknown printer/interface failure" \ 75*4746Srica "consult your system administrator; 76*4746Srica reasons for failure (if any) follow:" 77*4746Srica header=yes 78*4746Srica fi 79*4746Srica echo "${line}" >&2 80*4746Srica done 81*4746Srica return 1 82*4746Srica } 83*4746Srica LPTELL=fake_lptell 84*4746Sricafi 85*4746Srica 86*4746Srica##### 87*4746Srica# ${LPTSOLSEPARATOR} is the name of a program to put banner and trailer 88*4746Srica# pages around the job. 89*4746Srica##### 90*4746Sricaif [ -x ${LOCALPATH}/lp.tsol_separator ] 91*4746Sricathen 92*4746Srica LPTSOLSEPARATOR=${LOCALPATH}/lp.tsol_separator 93*4746Sricaelse 94*4746Srica echo "${LOCALPATH}/lp.tsol_separator not found." >&2 95*4746Srica exit 1 96*4746Sricafi 97*4746Srica 98*4746Srica##### 99*4746Srica# Error message formatter: 100*4746Srica# 101*4746Srica# Invoke as 102*4746Srica# 103*4746Srica# errmsg severity message-number problem help 104*4746Srica# 105*4746Srica# where severity is "ERROR" or "WARNING", message-number is 106*4746Srica# a unique identifier, problem is a short description of the 107*4746Srica# problem, and help is a short suggestion for fixing the problem. 108*4746Srica##### 109*4746Srica 110*4746SricaLP_ERR_LABEL="UX:lp" 111*4746SricaE_IP_ARGS=1 112*4746SricaE_IP_OPTS=2 113*4746Srica#E_IP_FILTER=3 114*4746SricaE_IP_UNKNOWN=5 115*4746SricaE_IP_BADFILE=6 116*4746SricaE_IP_ERRORS=12 # (in slow.filter) 117*4746Srica 118*4746Sricaerrmsg () { 119*4746Srica 120*4746Srica case $1 in 121*4746Srica ERROR ) 122*4746Srica sev=" ERROR"; 123*4746Srica ;; 124*4746Srica WARNING ) 125*4746Srica sev="WARNING"; 126*4746Srica ;; 127*4746Srica esac 128*4746Srica 129*4746Srica echo "${LP_ERR_LABEL}:$2 ${sev}: $3 130*4746Srica TO FIX: $4" >&5 131*4746Srica} 132*4746Srica 133*4746Srica########### 134*4746Srica## 135*4746Srica## Check arguments 136*4746Srica########### 137*4746Srica 138*4746Sricaparse () { 139*4746Srica echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`" 140*4746Srica} 141*4746Srica 142*4746Srica##### 143*4746Srica## 144*4746Srica## Error Cleanup and Exit 145*4746Srica## 146*4746Srica##### 147*4746Srica 148*4746Sricaexit_clean() 149*4746Srica{ 150*4746Srica 151*4746Srica if [ -f "${LPTMPDIR}/pr_eexit_code.$$" ] 152*4746Srica then 153*4746Srica /bin/rm ${LPTMPDIR}/pr_eexit_code.$$ 154*4746Srica fi 155*4746Srica 156*4746Srica if [ -f "${LPTMPDIR}/small_banner.$$" ] 157*4746Srica then 158*4746Srica /bin/rm ${LPTMPDIR}/small_banner.$$ 159*4746Srica fi 160*4746Srica 161*4746Srica if [ -f "${LPTMPDIR}/banner.exit_code.$$" ] 162*4746Srica then 163*4746Srica /bin/rm ${LPTMPDIR}/banner.exit_code.$$ 164*4746Srica fi 165*4746Srica 166*4746Srica if [ -f "${LPTMPDIR}/banner.errmsg.$$" ] 167*4746Srica then 168*4746Srica /bin/rm ${LPTMPDIR}/banner.errmsg.$$ 169*4746Srica fi 170*4746Srica 171*4746Srica if [ -f "${tmpfile}" ] 172*4746Srica then 173*4746Srica /bin/rm "${tmpfile}" 174*4746Srica fi 175*4746Srica 176*4746Srica exit $1 177*4746Srica} 178*4746Srica 179*4746Srica##### 180*4746Srica# 181*4746Srica# This program is invoked as 182*4746Srica# 183*4746Srica# ${SPOOLDIR}/.../printer request-id user title copies options files... 184*4746Srica# 185*4746Srica# The first three arguments are simply reprinted on the banner page, 186*4746Srica# the fourth (copies) is used to control the number of copies to print, 187*4746Srica# the fifth (options) is a blank separated list (in a single argument) 188*4746Srica# of user or Spooler supplied options (without the -o prefix), 189*4746Srica# and the last arguments are the files to print. 190*4746Srica##### 191*4746Srica 192*4746Sricaif [ $# -lt 5 ] 193*4746Sricathen 194*4746Srica 195*4746Srica errmsg ERROR ${E_IP_ARGS} \ 196*4746Srica "wrong number of arguments to interface program" \ 197*4746Srica "consult your system administrator" 198*4746Srica exit 1 199*4746Sricafi 200*4746Srica 201*4746Sricaprinter=`basename $0` 202*4746Sricarequest_id=$1 203*4746Sricauser_name=$2 204*4746Sricatitle=$3 205*4746Sricacopies=$4 206*4746Sricaoption_list=$5 207*4746Srica 208*4746Sricashift 5 209*4746Sricafiles="$*" 210*4746Srica 211*4746Srica 212*4746Srica# 213*4746Srica# debug sent to file if defined in /etc/syslog.conf 214*4746Srica# syslog.conf entry: 215*4746Srica# lpr.debug /path/filename 216*4746Srica# 217*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" " " 218*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" "INPUT" 219*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 220*4746Srica " printer : ${printer}" 221*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 222*4746Srica " request_id : ${request_id}" 223*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 224*4746Srica " user_name : ${user_name}" 225*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 226*4746Srica " title : ${title}" 227*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 228*4746Srica " copies : ${copies}" 229*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 230*4746Srica " option_list : ${option_list}" 231*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 232*4746Srica " files : ${files}" 233*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 234*4746Srica " spooler_key ${SPOOLER_KEY}" 235*4746Srica 236*4746Srica#### 237*4746Srica# default: do print a banner 238*4746Srica#### 239*4746Sricanobanner=no 240*4746Sricanolabels="no" 241*4746Sricanofilebreak="no" 242*4746Sricainlist= 243*4746Sricadata_file_flag= 244*4746Srica 245*4746Sricafor i in ${option_list} 246*4746Sricado 247*4746Srica case "${inlist}${i}" in 248*4746Srica 249*4746Srica nobanner ) 250*4746Srica nobanner="yes" 251*4746Srica ;; 252*4746Srica 253*4746Srica nofilebreak ) 254*4746Srica nofilebreak="yes" 255*4746Srica ;; 256*4746Srica 257*4746Srica nolabels ) 258*4746Srica nolabels="yes" 259*4746Srica ;; 260*4746Srica 261*4746Srica ##### 262*4746Srica # 263*4746Srica # If you want to add simple options (e.g. -o simple) 264*4746Srica # identify them here. 265*4746Srica ##### 266*4746Srica# simple ) 267*4746Srica# simple="yes" 268*4746Srica# ;; 269*4746Srica 270*4746Srica cpi=pica ) 271*4746Srica cpi=10 272*4746Srica ;; 273*4746Srica cpi=elite ) 274*4746Srica cpi=12 275*4746Srica ;; 276*4746Srica cpi=* ) 277*4746Srica cpi=`parse ${i}` 278*4746Srica ;; 279*4746Srica 280*4746Srica lpi=* ) 281*4746Srica lpi=`parse ${i}` 282*4746Srica ;; 283*4746Srica 284*4746Srica length=* ) 285*4746Srica length=`parse ${i}` 286*4746Srica ;; 287*4746Srica 288*4746Srica width=* ) 289*4746Srica width=`parse ${i}` 290*4746Srica ;; 291*4746Srica dest=* ) 292*4746Srica dest="-d `parse ${i}`" 293*4746Srica ;; 294*4746Srica 295*4746Srica protocol=* ) 296*4746Srica protocol="-P `parse ${i}`" 297*4746Srica ;; 298*4746Srica bsdctrl=* ) 299*4746Srica controlfile="-c `parse ${i}`" 300*4746Srica ;; 301*4746Srica timeout=* ) 302*4746Srica timeout="-t `parse ${i}`" 303*4746Srica ;; 304*4746Srica 305*4746Srica data-file-type=* ) 306*4746Srica data_file_flag="-f `parse ${i}`" 307*4746Srica ;; 308*4746Srica 309*4746Srica # 310*4746Srica # The IPP/PAPI attributes are handled by the foomatic-rip filter so 311*4746Srica # all we need to do here is ignore them so that they don't invoke the 312*4746Srica # "unrecognized option" message. 313*4746Srica # 314*4746Srica 315*4746Srica finishing=* | page-ranges=* | sides=* ) 316*4746Srica ;; 317*4746Srica number-up=* | orientation-requested=* | media=* ) 318*4746Srica ;; 319*4746Srica printer-resolution=* | print-quality=* ) 320*4746Srica ;; 321*4746Srica 322*4746Srica ##### 323*4746Srica # 324*4746Srica # If you want to add simple-value options (e.g. -o value=a) 325*4746Srica # identify them here. 326*4746Srica ##### 327*4746Srica# value=* ) 328*4746Srica# value=`parse ${i}` 329*4746Srica# ;; 330*4746Srica 331*4746Srica ##### 332*4746Srica # 333*4746Srica # If you want to add options that, 334*4746Srica # take a list (e.g. -o lopt='a b c'), identif 335*4746Srica # them here and below (look for LOPT). 336*4746Srica ##### 337*4746Srica 338*4746Srica# flist=* | lpd=* | options=* ) 339*4746Srica flist=* | lpd=* ) 340*4746Srica#LOPT stty=* | flist=* | lpd=* | lopt=* ) 341*4746Srica 342*4746Srica inlist=`expr "${inlist}${i}" : "^\([^=]*=\)"` 343*4746Srica case "${i}" in 344*4746Srica ${inlist}\'*\' ) 345*4746Srica item=`expr "${i}" : "^[^=]*='*\(.*\)'\$"` 346*4746Srica ;; 347*4746Srica ${inlist}\' ) 348*4746Srica continue 349*4746Srica ;; 350*4746Srica ${inlist}\'* ) 351*4746Srica item=`expr "${i}" : "^[^=]*='*\(.*\)\$"` 352*4746Srica ;; 353*4746Srica ${inlist}* ) 354*4746Srica item=`expr "${i}" : "^[^=]*=\(.*\)\$"` 355*4746Srica ;; 356*4746Srica *\' ) 357*4746Srica item=`expr "${i}" : "^\(.*\)'\$"` 358*4746Srica ;; 359*4746Srica * ) 360*4746Srica item="${i}" 361*4746Srica ;; 362*4746Srica esac 363*4746Srica 364*4746Srica ##### 365*4746Srica # 366*4746Srica # We don't dare use "eval" because a clever user could 367*4746Srica # put something in an option value that we'd end up 368*4746Srica # exec'ing. 369*4746Srica ##### 370*4746Srica case "${inlist}" in 371*4746Srica flist= ) 372*4746Srica flist="${flist} ${item}" 373*4746Srica ;; 374*4746Srica lpd= ) 375*4746Srica lpd="${lpd} ${item}" 376*4746Srica ;; 377*4746Srica#LOPT lopt= ) 378*4746Srica#LOPT lopt="${lopt} ${item}" 379*4746Srica#LOPT ;; 380*4746Srica# options= ) 381*4746Srica# options="${options} ${item}" 382*4746Srica# ;; 383*4746Srica esac 384*4746Srica 385*4746Srica case "${i}" in 386*4746Srica ${inlist}\'*\' ) 387*4746Srica inlist= 388*4746Srica ;; 389*4746Srica ${inlist}\'* ) 390*4746Srica ;; 391*4746Srica *\' | ${inlist}* ) 392*4746Srica inlist= 393*4746Srica ;; 394*4746Srica esac 395*4746Srica ;; 396*4746Srica 397*4746Srica * ) 398*4746Srica errmsg WARNING ${E_IP_OPTS} \ 399*4746Srica "unrecognized \"-o ${i}\" option" \ 400*4746Srica "check the option, resubmit if necessary 401*4746Srica printing continues" 402*4746Srica ;; 403*4746Srica esac 404*4746Sricadone 405*4746Srica 406*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 407*4746Srica "term : ${TERM}" 408*4746Srica 409*4746Sricaif [ -z "${FILTER}" ] 410*4746Sricathen 411*4746Srica ##### 412*4746Srica # 413*4746Srica # If no filter is being used, we use netpr to push the 414*4746Srica # file to the printer. 415*4746Srica # (QUOTES ARE IMPORTANT!) 416*4746Srica ##### 417*4746Srica 418*4746Srica case "$TERM" in 419*4746Srica PS ) 420*4746Srica # make the "postscript" printers use cat 421*4746Srica # (TSOL banners are added during filtering, so we have 422*4746Srica # to use some filter.) 423*4746Srica FILTER=/bin/cat 424*4746Srica ;; 425*4746Srica PSR ) 426*4746Srica # make the "reverse postscript" printers reverse the 427*4746Srica # output and the use postio to talk to the printer 428*4746Srica #FILTER="/usr/lib/lp/postscript/postreverse " 429*4746Srica #FILTER= 430*4746Srica FILTER="/usr/lib/lp/postscript/postreverse " 431*4746Srica ;; 432*4746Srica * ) 433*4746Srica # We don't know the type, so just assume that the 434*4746Srica # input and output are the same. Use netpr. 435*4746Srica #FILTER=/bin/cat 436*4746Srica FILTER= 437*4746Srica ;; 438*4746Srica esac 439*4746Sricafi 440*4746Srica 441*4746Srica#### 442*4746Srica# sets default value for ordering of data and control files with 443*4746Srica# bsd protocol. Default: data files first. Administrator 444*4746Srica# may set to control file first with lpadmin -o bsdctrl=first 445*4746Srica#### 446*4746Srica 447*4746Sricabanner_flag="" 448*4746Sricacase "${nobanner}" in 449*4746Srica yes ) 450*4746Srica banner_flag="-b" 451*4746Srica ;; 452*4746Sricaesac 453*4746Srica 454*4746SricaNETPR="/usr/lib/lp/bin/netpr ${banner_flag} ${data_file_flag} \ 455*4746Srica -I ${request_id} -U ${user_name} \ 456*4746Srica -p ${printer} ${dest} -T \"${title}\" \ 457*4746Srica ${timeout} ${protocol} ${controlfile} " 458*4746SricaLPTELL_OPTS="-l" # netpr sends LaserWriter style messages back 459*4746SricaPPDFILTER=/usr/lib/lp/bin/foomatic-rip 460*4746SricaPPDFILTERA="${PPDFILTER} ${request_id} ${user_name} \"${title}\" ${copies} \"${option_list}\"" 461*4746Srica 462*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 463*4746Srica "NETPR= ${NETPR}" 464*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 465*4746Srica "filter : ${FILTER}" 466*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 467*4746Srica "ppdfilter : ${PPDFILTERA}" 468*4746Srica 469*4746Sricanode=`uname -n` 470*4746Sricapid=$$ 471*4746Sricatmpfile=${LPTMPDIR}/${node}.${pid} 472*4746Sricatmpfilefoo=${LPTMPDIR}/${node}.${pid}.1 473*4746Srica 474*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 475*4746Srica "tmpfile : ${tmpfile}" 476*4746Srica 477*4746Srica##### 478*4746Srica# 479*4746Srica# Set up filter for banner page 480*4746Srica# 481*4746Srica##### 482*4746Sricabanner_filter= 483*4746Sricacase "${TERM}" in 484*4746SricaPS | PSR ) 485*4746Srica banner_filter=" | /usr/lib/lp/postscript/postprint " 486*4746Srica LPTELL_OPTS="-l" 487*4746Srica ;; 488*4746Sricaesac 489*4746Srica 490*4746Srica##### 491*4746Srica# 492*4746Srica# Build temporary file that is the banner page 493*4746Srica# 494*4746Srica##### 495*4746SricaPAD="#####${NL}" 496*4746SricaCR="\r" 497*4746SricaNL="${CR}\n" 498*4746SricaFF= 499*4746Srica 500*4746Sricasmall_banner() { 501*4746Srica echo "${CR}\c" 502*4746Srica echo "${PAD}\c" 503*4746Srica echo "##### User: ${user_name}${NL}\c" 504*4746Srica if [ -n "${title}" ] 505*4746Srica then 506*4746Srica echo "##### Title: ${title}${NL}\c" 507*4746Srica fi 508*4746Srica echo "##### Date: `LANG=C date '+%a %H:%M %h %d, %Y'`${NL}\c" 509*4746Srica echo "##### Job: ${request_id}${NL}\c" 510*4746Srica echo "${PAD}\c" 511*4746Srica if [ -n "${FF}" ] 512*4746Srica then 513*4746Srica echo "${CR}${FF}\c" 514*4746Srica fi 515*4746Srica} 516*4746Srica 517*4746Srica##### 518*4746Srica# 519*4746Srica# Doing small banner as we don't know what printer is out there 520*4746Srica# 521*4746Srica##### 522*4746Sricabanner=small_banner 523*4746Srica 524*4746Srica## Skip this for PS/PSR printers, since lp.tsol_separator handles the banners 525*4746Sricaif [ "no" = "${nobanner}" -a "${TERM}" != "PSR" -a "${TERM}" != "PS" ] 526*4746Sricathen 527*4746Srica eval "${banner} ${banner_filter}" 2>&1 1>${LPTMPDIR}/small_banner.$$ 528*4746Sricafi 529*4746Srica 530*4746Srica########### 531*4746Srica## 532*4746Srica## Surround the job by PostScript code to produce banner 533*4746Srica## and trailerpages and page headers and footers. 534*4746Srica## 535*4746Srica########### 536*4746Srica 537*4746SricaBANNER_EXIT_CODE=${LPTMPDIR}/banner.exit_code.$$ 538*4746Sricaecho 0 > ${BANNER_EXIT_CODE} 539*4746SricaTSOLSEPARATOR_LOG=${LPTMPDIR}/banner.errmsg.$$ 540*4746Srica 541*4746Sricatsol_bannerize () { 542*4746Srica TSOLSEPARATOR_OPTS="-e ${TSOLSEPARATOR_LOG}" 543*4746Srica 544*4746Srica if [ "yes" = "${nolabels}" ] 545*4746Srica then 546*4746Srica TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -l" 547*4746Srica fi 548*4746Srica 549*4746Srica if [ "yes" = "${nobanner}" ] 550*4746Srica then 551*4746Srica TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -t /dev/null -b /dev/null" 552*4746Srica fi 553*4746Srica 554*4746Srica if [ "${TERM}" = "PSR" ] 555*4746Srica then 556*4746Srica TSOLSEPARATOR_OPTS="${TSOLSEPARATOR_OPTS} -r" 557*4746Srica fi 558*4746Srica 559*4746Srica # Get rid of the #, TAB and NL characters in the title 560*4746Srica tsol_title=`echo $title` 561*4746Srica tsol_title=`echo $tsol_title | sed 's/#//g'` 562*4746Srica 563*4746Srica logger -p lpr.debug -t "tsol_netstandard: ${request_id}" \ 564*4746Srica "banner command: ${LPTSOLSEPARATOR} ${TSOLSEPARATOR_OPTS} \ 565*4746Srica ${printer} ${request_id} ${user_name} \"${tsol_title}\" ${file}" 566*4746Srica ${LPTSOLSEPARATOR} ${TSOLSEPARATOR_OPTS} ${printer} \ 567*4746Srica ${request_id} ${user_name} "${tsol_title}" ${file} 568*4746Srica 569*4746Srica echo $? > ${BANNER_EXIT_CODE} 570*4746Srica true 571*4746Srica} 572*4746Srica 573*4746Sricabannerize=tsol_bannerize 574*4746Srica 575*4746Sricaif [ "yes" = "${nobanner}" -a "yes" = "${nolabels}" ] 576*4746Sricathen 577*4746Srica bannerize=cat 578*4746Sricafi 579*4746Srica 580*4746Sricaif [ "${TERM}" != "PSR" -a "${TERM}" != "PS" ] 581*4746Sricathen 582*4746Srica bannerize=cat 583*4746Sricafi 584*4746Srica 585*4746Srica##### 586*4746Srica# 587*4746Srica# Print banner page before job unless PSR or PS 588*4746Srica# 589*4746Srica##### 590*4746Srica 591*4746Srica 592*4746Srica## Skip this for PS/PSR printers, since lp.tsol_separator handles the banners 593*4746Sricaif [ "no" = "${nobanner}" -a "${TERM}" != "PSR" -a "${TERM}" != "PS" ] 594*4746Sricathen 595*4746Srica ( 596*4746Srica eval ${NETPR} ${LPTMPDIR}/small_banner.$$ 2>&1 597*4746Srica echo $? > ${LPTMPDIR}/pr_eexit_code.$$ 598*4746Srica ) | ${LPTELL} ${LPTELL_OPTS} ${printer} 599*4746Srica 600*4746Srica exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$` 601*4746Srica logger -p lpr.debug -t \ 602*4746Srica "tsol_netstandard_foomatic: ${request_id}" \ 603*4746Srica "banner page exit code : ${exit_code}" 604*4746Srica 605*4746Sricafi 606*4746Srica 607*4746Sricai=1 608*4746Sricawhile [ $i -le $copies ] 609*4746Sricado 610*4746Srica for file in ${files} 611*4746Srica do 612*4746Srica if [ -r "${file}" ] 613*4746Srica then 614*4746Srica 615*4746Srica if [ ! -z "${FILTER}" ] 616*4746Srica then 617*4746Srica ( 618*4746Srica ##### 619*4746Srica # There is a filter, use it 620*4746Srica # 621*4746Srica # Put 0<${file} before the "eval" to keep 622*4746Srica # clever users from giving a file name that 623*4746Srica # evaluates as something to execute. 624*4746Srica # Redirect stderr to stdout so LPTELL will 625*4746Srica # get error messages from pipe. 626*4746Srica ##### 627*4746Srica 628*4746Srica 0<${file} $bannerize | eval ${FILTER} 2>&1 1>${tmpfile} 629*4746Srica echo $? > ${LPTMPDIR}/pr_eexit_code.$$ 630*4746Srica ) | ${LPTELL} ${LPTELL_OPTS} ${printer} 631*4746Srica 632*4746Srica # if lp.tsol_separator had an error, 633*4746Srica # send its logged error message to LPTELL. 634*4746Srica banner_exit_code=`cat ${BANNER_EXIT_CODE}` 635*4746Srica if [ -n "${banner_exit_code}" -a \ 636*4746Srica 0 -ne "${banner_exit_code}" -a \ 637*4746Srica -n "${LPTELL}" -a \ 638*4746Srica -r "${TSOLSEPARATOR_LOG}" ] 639*4746Srica then 640*4746Srica cat ${TSOLSEPARATOR_LOG} | ${LPTELL} ${printer} 641*4746Srica echo 77 > ${LPTMPDIR}/pr_eexit_code 642*4746Srica fi 643*4746Srica 644*4746Srica exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$` 645*4746Srica logger -p lpr.debug -t \ 646*4746Srica "tsol_netstandard_foomatic: ${request_id}" \ 647*4746Srica "filter exit_code : ${exit_code}" 648*4746Srica 649*4746Srica if [ -n "${exit_code}" ] 650*4746Srica then 651*4746Srica if [ "${exit_code}" -eq 0 ] 652*4746Srica then 653*4746Srica printfile=${tmpfile} 654*4746Srica else 655*4746Srica #### 656*4746Srica # The filter did not succeed, so don't try to print 657*4746Srica #### 658*4746Srica printfile= 659*4746Srica fi 660*4746Srica fi 661*4746Srica 662*4746Srica else 663*4746Srica printfile=${file} 664*4746Srica fi 665*4746Srica 666*4746Srica logger -p lpr.debug -t \ 667*4746Srica "tsol_netstandard_foomatic: ${request_id}" \ 668*4746Srica "printfile : ${printfile}" 669*4746Srica 670*4746Srica ##### 671*4746Srica # Print the file 672*4746Srica ##### 673*4746Srica 674*4746Srica if [ -r "${printfile}" ] 675*4746Srica then 676*4746Srica ( 677*4746Sricalogger -p lpr.debug -t \ 678*4746Srica "@1 tsol_netstandard_foomatic: printfile = ${printfile}" "" 679*4746Sricalogger -p lpr.debug -t \ 680*4746Srica "tsol_netstandard_foomatic: ${NETPR} ${printfile}" "" 681*4746Srica #eval ${NETPR} ${printfile} 2>&1 682*4746Srica cat ${printfile} | ${PPDFILTER} \ 683*4746Srica ${request_id} ${user_name} "${title}" ${copies} "${option_list}" \ 684*4746Srica > ${tmpfilefoo} 2> /dev/null 685*4746Srica eval ${NETPR} ${tmpfilefoo} 2>&1 686*4746Srica echo $? > ${LPTMPDIR}/pr_eexit_code.$$ 687*4746Srica /bin/rm -f ${tmpfilefoo} 688*4746Srica ) | ${LPTELL} ${LPTELL_OPTS} ${printer} 689*4746Srica 690*4746Srica exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$` 691*4746Srica logger -p lpr.debug -t \ 692*4746Srica "@2 netstandard_foomatic: ${request_id}" \ 693*4746Srica "netpr exit_code : ${exit_code}" 694*4746Srica 695*4746Srica# if [ -f "${tmpfile}" ] 696*4746Srica# then 697*4746Srica# /bin/rm "${tmpfile}" 698*4746Srica# fi 699*4746Srica 700*4746Srica if [ -n "${exit_code}" ] 701*4746Srica then 702*4746Srica if [ "${exit_code}" -eq 0 ] 703*4746Srica then 704*4746Srica printone=yes 705*4746Srica else 706*4746Srica if [ "${exit_code}" -lt 128 ] 707*4746Srica then 708*4746Srica noprint=yes 709*4746Srica else 710*4746Srica retry=yes 711*4746Srica fi 712*4746Srica fi 713*4746Srica fi 714*4746Srica 715*4746Srica 716*4746Srica else 717*4746Srica 718*4746Srica errmsg WARNING ${E_IP_BADFILE} \ 719*4746Srica "cannot read temporary file \"${printfile}\""\ 720*4746Srica "see if file still exists, 721*4746Srica or consult your system administrator; 722*4746Srica printing continues" 723*4746Srica 724*4746Srica fi 725*4746Srica else 726*4746Srica 727*4746Srica ##### 728*4746Srica # 729*4746Srica # Don't complain about not being able to read 730*4746Srica # a file on second and subsequent copies, unless 731*4746Srica # we've not complained yet. This removes repeated 732*4746Srica # messages about the same file yet reduces the 733*4746Srica # chance that the user can remove a file and not 734*4746Srica # know that we had trouble finding it. 735*4746Srica ##### 736*4746Srica 737*4746Srica if [ "${i}" -le 1 -o -z "${badfileyet}" ] 738*4746Srica then 739*4746Srica errmsg WARNING ${E_IP_BADFILE} \ 740*4746Srica "cannot read file \"${file}\"" \ 741*4746Srica "see if the file still exists and is readable, 742*4746Srica or consult your system administrator; 743*4746Srica printing continues" 744*4746Srica badfileyet=yes 745*4746Srica fi 746*4746Srica 747*4746Srica fi 748*4746Srica 749*4746Srica# for file in ${files} 750*4746Srica done 751*4746Srica i=`expr $i + 1` 752*4746Sricadone 753*4746Srica 754*4746Srica##### 755*4746Srica# 756*4746Srica# If printing in reverse order, print the banner page now 757*4746Srica# Skip this for TSOL, since lp.tsol_separator handles the banners 758*4746Srica# 759*4746Srica##### 760*4746Srica 761*4746Srica#if [ "no" = "${nobanner}" -a "${TERM}" = "PSR" ] 762*4746Srica#then 763*4746Srica#( 764*4746Srica# eval ${NETPR} ${LPTMPDIR}/small_banner.$$ 2>&1 765*4746Srica# echo $? > ${LPTMPDIR}/pr_eexit_code.$$ 766*4746Srica#) | ${LPTELL} ${LPTELL_OPTS} ${printer} 767*4746Srica#fi 768*4746Srica 769*4746Sricaexit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$` 770*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 771*4746Srica "banner page exit code : ${exit_code}" 772*4746Srica 773*4746Sricaif [ -n "${printone}" -a -z "${retry}" -a -z "${noprint}" ] 774*4746Sricathen 775*4746Srica exit_code=`expr 0` 776*4746Sricaelse 777*4746Srica if [ -n "${retry}" -a -z "${printone}" -a -z "${noprint}" ] 778*4746Srica then 779*4746Srica exit_code=`expr 129` 780*4746Srica else 781*4746Srica exit_code=`expr 1` 782*4746Srica fi 783*4746Sricafi 784*4746Srica 785*4746Sricalogger -p lpr.debug -t "tsol_netstandard_foomatic: ${request_id}" \ 786*4746Srica "FINAL exit_code : ${exit_code}" 787*4746Srica 788*4746Sricaexit_clean ${exit_code} 789