178N/A#!/bin/sh
178N/A#
178N/A# CDDL HEADER START
178N/A#
178N/A# The contents of this file are subject to the terms of the
178N/A# Common Development and Distribution License (the "License").
178N/A# You may not use this file except in compliance with the License.
178N/A#
178N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
178N/A# or http://www.opensolaris.org/os/licensing.
178N/A# See the License for the specific language governing permissions
178N/A# and limitations under the License.
178N/A#
178N/A# When distributing Covered Code, include this CDDL HEADER in each
178N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
178N/A# If applicable, add the following below this CDDL HEADER, with the
178N/A# fields enclosed by brackets "[]" replaced with your own identifying
178N/A# information: Portions Copyright [yyyy] [name of copyright owner]
178N/A#
178N/A# CDDL HEADER END
178N/A#
178N/A#
178N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
178N/A#
178N/A# To configure this interface script under Solaris LP use the following
178N/A# command:
178N/A#
178N/A# lpadmin -p printer -v /dev/... -I"postscript,pdf" -Tunknown \
178N/A# -i /usr/sfw/share/ghostscript/interfaces/GSinterface \
178N/A# -o GS_DEVICE=(gs-device-type) \
178N/A# [-o OutputFile=(file/device)] [-o PAPERSIZE=(size)] \
178N/A# [-o RESOLUTION=XxY] [-o banner-type=(ascii|postscript)] \
178N/A# [-o GS_OPTIONS="-sIjsServer=... -sIjsParams=..."]
178N/A#
178N/A# see gs(1) for more information about values that can be used for
178N/A# GS_DEVICE, PAPERSIZE, and RESOLUTION, and GS_OPTIONS.
178N/A#
178N/A# There is a known problem printing through a /dev/lp? parallel port
178N/A# on a Solaris x86 machine. If you have selected the correct GS_DEVICE
178N/A# and get garbled output when printing under this configuration, running
178N/A# "lpadmin -p printer -H nopush"
178N/A# should fix the problem.
178N/A
178N/APATH=/usr/sfw/bin:/usr/lib/lp/bin:/bin export PATH
178N/A
178N/A
178N/Aif [ $# -lt 5 ] ; then
178N/A logger -p lpr.err -t "GSinterface" \
178N/A "wrong number of arguments to interface program" 1>&2
178N/A logger -p lpr.err -t "GSinterface" "$0 $*"
178N/A echo "wrong number of arguments to interface program" 1>&2
178N/A exit 1
178N/Afi
178N/A
178N/A
178N/Aprinter=`basename $0`
178N/Arequest_id=$1
178N/Auser_name=$2
178N/Atitle=$3
178N/Acopies=$4
178N/Aoption_list=$5
178N/A
178N/Ashift 5
178N/Afiles="$*"
178N/A
178N/Atag="GSinterface: ${request_id}"
178N/Aerror_file="/tmp/${printer}-log.$$"
178N/A
178N/Alogger -p lpr.debug -t ${tag} "INPUT"
178N/Alogger -p lpr.debug -t ${tag} " printer : ${printer}"
178N/Alogger -p lpr.debug -t ${tag} " request_id : ${request_id}"
178N/Alogger -p lpr.debug -t ${tag} " user_name : ${user_name}"
178N/Alogger -p lpr.debug -t ${tag} " title : ${title}"
178N/Alogger -p lpr.debug -t ${tag} " copies : ${copies}"
178N/Alogger -p lpr.debug -t ${tag} " option_list : ${option_list}"
178N/Alogger -p lpr.debug -t ${tag} " files : ${files}"
178N/A
178N/A
178N/Aparse () {
178N/A echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
178N/A}
178N/A
178N/Abanner="postscript_banner"
178N/Anobanner="no"
178N/Anofilebreak="no"
178N/AOutputFile=
178N/AGS_DEVICE=nullpage
178N/AGS_OPTIONS=
178N/Ainlist=
178N/A
178N/Afor i in ${option_list}
178N/Ado
178N/A case "${inlist}${i}" in
178N/A
178N/A nobanner )
178N/A nobanner="yes"
178N/A ;;
178N/A
178N/A nofilebreak )
178N/A nofilebreak="yes"
178N/A ;;
178N/A
178N/A banner-type=* )
178N/A banner="`parse ${i}`_banner"
178N/A ;;
178N/A
178N/A GS_DEVICE=* )
178N/A GS_DEVICE=`parse ${i}`
178N/A ;;
178N/A
178N/A OutputFile=* )
178N/A GS_OPTIONS="-sOutputFile=`parse ${i}` ${GS_OPTIONS}"
178N/A OutputFile="yes"
178N/A ;;
178N/A
178N/A RESOLUTION=* )
178N/A GS_OPTIONS="-r`parse ${i}` ${GS_OPTIONS}"
178N/A ;;
178N/A
178N/A PAPERSIZE=* )
178N/A GS_OPTIONS="-sPAPERSIZE=`parse ${i}` ${GS_OPTIONS}"
178N/A ;;
178N/A
178N/A GS_OPTIONS=* )
178N/A GS_OPTIONS="`parse ${i}` ${GS_OPTIONS}"
178N/A ;;
178N/A
178N/A * )
178N/A logger -p lpr.error -t ${tag} \
178N/A "unrecognized \"-o ${i}\" option, ignored" 1>&2
178N/A ;;
178N/A esac
178N/Adone
178N/A
178N/Aif [ "${OutputFile}" = "" ] ; then
178N/A GS_OPTIONS="-sOutputFile=- ${GS_OPTIONS}"
178N/Afi
178N/A
178N/A# Don't pause between pages, exit upon completion, don't print startup and
178N/A# page messages, don't allow deletefile, rename, or write access to files
178N/AGS_OPTIONS="-dNOPAUSE -dBATCH -dQUIET -dSAFER ${GS_OPTIONS}"
178N/A
178N/Aexport GS_DEVICE GS_OPTIONS PATH
178N/A
178N/Alogger -p lpr.debug -t ${tag} "ENVIRONMENT"
178N/Aenv | logger -p lpr.debug -t "${tag}: "
178N/A
178N/A#
178N/A# Generate an ASCII banner page and pass it to the printer
178N/A# This is much faster than the PostScript(TM) banner
178N/A#
178N/Aascii_banner() {
178N/A cat <<EOF
178N/A ${title}
178N/A Request: ${request_id}
178N/A User: ${user_name}
178N/A Printer: ${printer}
178N/A Time: `date`
178N/A Copies: ${copies}
178N/AEOF
178N/A tput ff
178N/A}
178N/A
178N/A#
178N/A# Generate a PostScript(TM) banner page and run it through GhostScript.
178N/A# This assumes an 8.5x11 page size.
178N/A#
178N/Apostscript_banner() {
178N/A cat <<EOF | gs - 2>> ${error_file}
178N/A%!ps
178N/A/PrintLine { exch findfont exch scalefont setfont moveto show } def
178N/Anewpath 4 setlinewidth 1 setlinejoin
178N/A15 760 moveto 595 760 lineto 595 585 lineto 15 585 lineto closepath
178N/Agsave .75 setgray fill grestore
178N/A0 setgray stroke
178N/A(${user_name}) 30 730 /Times-Bold 24 PrintLine
178N/A(${request_id}) 415 730 /Times-Bold 24 PrintLine
178N/A(${printer}) 30 600 /Times-Bold 16 PrintLine
178N/A(`date`) 350 600 /Times-Roman 16 PrintLine
178N/A(${title}) 100 660 /Times-Bold 36 PrintLine
178N/A(Copies: ${copies}) 30 25 /Times-Roman 16 PrintLine
178N/Ashowpage
178N/AEOF
178N/A}
178N/A
178N/A#
178N/A# should create a banner
178N/A# a simple text or PCL banner would be prefered, because a PS one
178N/A# would require GhostScript to RIP and pass the whole image to the
178N/A# printer.
178N/A#
178N/Acase "${nobanner}" in
178N/A "no")
178N/A (eval "${banner}" 1>&3 2>&1) | lp.cat 0
178N/A ;;
178N/Aesac
178N/A
178N/A#
178N/A# process the files
178N/A#
178N/Ai=1
178N/Awhile [ $i -le $copies ] ; do
178N/A for file in $files ; do
178N/A gs $file 2>> ${error_file} | lp.cat 0
178N/A done
178N/A i=`expr $i + 1`
178N/Adone
178N/A
178N/Aif [ -s ${error_file} ] ; then
178N/A logger -p lpr.debug -t ${tag} "GS ERRORS"
178N/A cat ${error_file} | logger -p lpr.debug -t "${tag}: "
178N/A rm -f ${error_file}
178N/Afi
178N/A
178N/Aexit 0