5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # ident "%Z%%M% %I% %E% SMI"
28 # printer interface script for printers with a URI instead of
31 # The existence of a "PPD" environment variable in the calling environment
32 # indicates that Foomatic is to be used for filtering all job data as it is
33 # streamed to the output device (printer).
35 # The contents of a "DEVICE_URI" environment variable in the calling
36 # environment indicates the method and endpoint used in communicating with
37 # the output device (printer). If no DEVICE_URI is present or the value
38 # contains a missing or unknown scheme, the URI scheme is assumed to be
39 # "file" and output streaming will be handled accordingly.
41 export PATH
=/bin
:/usr
/bin
:/usr
/lib
/lp
/bin
:/usr
/sfw
/bin
46 # Re-arrange fds for later use
47 exec 5>&2 2>/dev
/null
3>&1
57 fail
() { # exit-code "message"
58 logger
-p lpr.error
-t ${TAG} "${2}"
64 # EXIT 0 - normal exit
65 # HUP 1 - the output stream disconnected
66 # INT 2 - the output stream interupted us
67 # QUIT 3 - the output stream interupted us
68 # TERM 15 - we have been cancelled or shutdown
75 fail
${EXIT_RETRY} "connection to the printer dropped; off-line?"
79 fail
${EXIT_RETRY} "interrupt from the printer; baud-rate issues?"
82 catch_cancellation
() {
83 fail
${EXIT_RETRY} "job cancelled"
86 trap 'catch_disconnect()' HUP
87 trap 'catch_interrupt()' INT QUIT
88 trap 'catch_cancellation()' TERM
90 parse_uri
() { # scheme://[[user[:password]@]host[:port]]/path
91 URI_SCHEME
=$
(expr "$1" : "\(.*\)://.*")
95 echo "$(expr \"$1\" : \"^[^=]*=\(.*\)\")"
99 # Generate an ASCII burst page and pass it to the printer
100 # This may be much faster than the PostScript(TM) burst page
105 Request: ${request_id}
115 # Generate a PostScript(TM) burst page (this assumes an 8.5x11 page size)
117 postscript_burst_page
() {
120 /PrintLine { exch findfont exch scalefont setfont moveto show } def
121 newpath 4 setlinewidth 1 setlinejoin
122 15 760 moveto 595 760 lineto 595 585 lineto 15 585 lineto closepath
123 gsave .75 setgray fill grestore
125 (${user}) 30 730 /Times-Bold 24 PrintLine
126 (${request_id}) 415 730 /Times-Bold 24 PrintLine
127 (${printer}) 30 600 /Times-Bold 16 PrintLine
128 ($(date)) 350 600 /Times-Roman 16 PrintLine
129 (${title}) 100 660 /Times-Bold 36 PrintLine
130 (Copies: ${copies}) 30 25 /Times-Roman 16 PrintLine
135 logger
-p lpr.debug
-t ${TAG} "$0 $*"
138 # Detemine if we were called correctly
140 if [[ $# -lt 5 ]] ; then
141 fail
${EXIT_FATAL} "wrong number of arguments to interface script"
145 printer
=$
(basename $0)
155 burst_page
="postscript_burst_page"
170 burst_page
="$(parse ${i})_burst_page"
174 logger
-p lpr.error
-t ${TAG} \
175 "unrecognized \"-o ${i}\" option, ignored" 1>&2
182 # Procss the DEVICE_URI if we have one
184 if [[ -n "${DEVICE_URI}" ]] ; then
185 parse_uri
${DEVICE_URI} # split up the URI
187 URI_SCHEME
=${URI_SCHEME:-file} # if there is no scheme, assume "file"
189 case "${URI_SCHEME}" in
190 file|usb|ecpp|serial|parallel
)
195 IO_HANDLER
="smbspool"
196 IO_HANDLER_ARGS
="${request_id} ${user} \"${title}\" 1
200 URI_HOST
=$
(expr "${DEVICE_URI}" : ".*://\([^:/]*\)")
201 URI_PORT
=$
(expr "${DEVICE_URI}" : ".*://.*:\([^/]*\)")
202 if [[ -z "${URI_HOST}" ]] ; then
203 fail
${EXIT_FATAL} "invalid device-uri: ${DEVICE_URI}, reset with lpadmin -v"
205 URI_PORT
=${URI_PORT:-"9100"}
207 IO_HANDLER_ARGS
="-c -E ${URI_HOST} ${URI_PORT}"
211 IO_HANDLER_ARGS
="-s -d ${DEVICE_URI}"
214 IO_HANDLER
=${URI_SCHEME}
219 IO_HANDLER
=${IO_HANDLER:-"lp.cat"} # if IO_HANDLER is still unset, use lp.cat
221 # determine if the IO handler is available for us to use when communicating with
222 # the output device (printer.)
223 whence
${IO_HANDLER} >/dev
/null
224 if [[ $?
-ne 0 ]] ; then
226 "Interface script unable to locate IO handler: ${IO_HANDLER}"
229 # There is a PPD file specified, so use foomatic
230 if [[ -n "${PPD}" ]] ; then
231 FILTER_CHAIN
="| foomatic-rip"
235 # Start processing the job here
237 set | logger
-p lpr.debug
-t "${TAG}"
240 if [[ -n "${burst_page}" ]] ; then
241 eval "${burst_page} ${FILTER_CHAIN}"
243 while [[ $copies -gt 0 ]] ; do
244 for file in ${files} ; do
245 if [[ -r "${file}" ]] ; then
246 eval "cat ${file} ${FILTER_CHAIN}"
249 copies
=$
(( copies
- 1 ))
251 ) |
${IO_HANDLER} ${IO_HANDLER_ARGS}