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