#!/bin/bash # ############################################################################# # # This CUPS backend provides a mechanism to browse local HELIOS queues and # to print into these. Every queue that is configured as "tcp/ip printer" # will be published (the 'chooser' name will be displayed). # # To use it, save this script renamed as "helios" in CUPS' backend folder # e.g. /usr/libexec/cups/backend (on MacOS X) # ############################################################################# # # author: Thomas Kaiser # license: GPL - http://www.gnu.org/copyleft/gpl.html # url: http://users.phg-online.de/tk/helios/scripts/cups-backend.sh # date: Sat Apr 5 16:57:09 CEST 2003 (v.0.0.5) # ############################################################################# # # CHANGES: # # 0.0.5: - force CUPS to reread its ppds.dat database after we copied # PPDs to the model dir # - some code cleanups # # 0.0.4: - added support for copying the HELIOS PPDs to CUPS' model dir # # 0.0.3: - some code cleanups # - append the CUPS OWNER string as the For: string in the PS header # # 0.0.2: - supply a printer model based on the "*ModelName" entry in the # queue's PPD file # - changed the "device class" from "direct" to "file" # ############################################################################# # # Non-Warranty: # This script comes with absolutely no warranty. # # Use at your own risk! # ############################################################################# # # Custom settings: # # if you define this path and it is pointing to a directory then the backend # will copy the queue's PPDs inside and force CUPS to update its PPD database PPD_DIR=/usr/share/cups/model/helios # administrative settings PROTOCOL=`basename ${0}` TMP_FILE="${TMPDIR:=/tmp}/${PROTOCOL}-$$.ps" while [ -e "${TMP_FILE}" ]; do TMP_FILE="${TMP_FILE}x"; done ############################################################################# # # some functions main() { # Check prerequisits CheckHELIOS # Let's start to process the CUPS requests if [ ${#} = 0 ]; then # CUPS is calling us to determine which services we can provide # check whether we should copy the queue's PPDs over to CUPS if [ -d "${PPD_DIR}" ]; then CopyPPD=TRUE else CopyPPD=FALSE fi # let's parse the Helios config for available 'tcp/ip printers' ${HELIOSDIR}/bin/prefdump | tr -d "\012" | sed 's|\[\]|\\|g' | \ tr "\\" "\n" | grep "\[TCPPublish\]" | while read PRINTER; do IsTCPPrinter=`echo ${PRINTER} | cut -d"=" -f4` if [ ${IsTCPPrinter} = "TRUE" ]; then PrinterName=`echo ${PRINTER} | cut -d"[" -f3 | tr -d "]"` # Try to get the macintosh chooser name PAPName=`${HELIOSDIR}/bin/prefdump | tr -d "\012" | \ sed 's|\[\]|@|g' | tr "@" "\n" | \ grep "\[Printers\]\[${PrinterName}\]\[papname\]" | \ cut -d"]" -f5` if [ "X${PAPName}" = "X" ]; then PAPName=${PrinterName} fi # Try to get the model name of the printer PPD=${HELIOSDIR}/var/spool/qmeta/${PrinterName}/PPD TYPE="\"Unknown\"" if [ -r ${PPD} ]; then PPDTYPE=`grep "^*ModelName:" ${PPD} | cut -d"\"" -f2` test "X${PPDTYPE}" = "X" || TYPE="\"${PPDTYPE}\"" # test whether we should copy the PPD to CUPS if [ ${CopyPPD} = "TRUE" -a ! -f "${TMP_DIR}/update_ppds" ]; then cp "${PPD}" "${PPD_DIR}/${PrinterName}" fi fi echo "file ${PROTOCOL}://${PrinterName} ${TYPE} \"HELIOS Queue '${PAPName}'\"" fi done # let CUPS eventually update its PPD database ForcePPDUpdate else # Let's print the job... PRINTER=`echo ${DEVICE_URI} | awk -F"://" '{print $2}'` TITLE="${3}" OWNER="${2}" echo "INFO: Sending job to HELIOS" >&2 (echo -e "%!PS\n%%For: (${OWNER})"; cat $6) | ${LPR} -P${PRINTER} -T"${TITLE}" echo "PAGE: 1 1" >&2 fi } CheckHELIOS() { if [ -r /etc/HELIOSInstallPath ]; then read HELIOSDIR &2 exit 1 fi } ForcePPDUpdate() { if [ -f "${TMP_DIR}/update_ppds" ]; then rm "${TMP_DIR}/update_ppds" return 0 else touch "${TMP_DIR}/update_ppds" fi case `uname -s` in AIX|HP-UX|OSF1|SunOS|IRIX*) CUPSPID=`ps -e | grep cupsd | awk -F' ' '{print $1}'` ;; Darwin|Linux) CUPSPID=`ps ax | grep cupsd | awk -F' ' '{print $1}'` ;; *) echo "ERROR: unable to check system architecture" >&2 return 1 ;; esac if [ -z "${CUPSPID}" ]; then echo "ERROR: unable to get CUPS PID" >&2 return 1 fi kill -HUP ${CUPSPID} } ############################################################################# # # let's go main "$@"