#!/usr/local/bin/bash # # /usr/lib/cups/backend/sispm # # (c) September 2007 Kurt Pfeifle # # Network printing consultant Linux/Unix/Windows/Samba/CUPS # # (c) Jan 2008 Dominic Morris # Uses sispm to control printers # # # License: GNU GPLv2 or GPLv3 (your choice) # Warranty: None at all; you may need to fix included defects on your own. # set -x backend=${0} jobid=${1} cupsuser=${2} jobtitle=${3} jobcopies=${4} joboptions=${5} jobfile=${6} # the following messages should appear in /var/log/cups/error_log, # depending on what "LogLevel" setting your cupsd.conf carries: echo "INFO: backend=${backend}" 1>&2 echo "INFO: jobid=${jobid}" 1>&2 echo "INFO: cupsuser=${cupsuser}" 1>&2 echo "INFO: jobtitle=${jobtitle}" 1>&2 echo "INFO: jobcopies=${jobcopies}" 1>&2 echo "INFO: joboptions=${joboptions}" 1>&2 echo "INFO: jobfile=${jobfile}" 1>&2 echo "INFO: printtime=${printtime}" 1>&2 echo "EMERG: This is a \"emergency\" level log message" 1>&2 echo "ALERT: This is a \"alert\" level log message" 1>&2 echo "CRIT: This is a \"critical\" level log message" 1>&2 echo "ERROR: This is a \"error\" level log message" 1>&2 echo "WARN: This is a \"warn\" level log message" 1>&2 echo "NOTICE: This is a \"notice\" level log message" 1>&2 echo "INFO: This is a \"info\" level log message" 1>&2 echo "INFO: This is a 2nd \"info\" level log message" 1>&2 echo "INFO: This is a 3rd \"info\" level log message" 1>&2 echo "DEBUG: This is a \"debug\" level log message" 1>&2 # we will read the output filename from the printers $DEVICE_URI environment # variable that should look s.th. like "sispm:/port number:[normal uri]" # Split up Device URI into sensible bits base=`echo ${DEVICE_URI} | sed "s/sispm:\///g"` port=`echo $base | sed "s/\([0-9]*\)\/\(.*\)/\1/"` realuri=`echo $base | sed "s/\([0-9]*\)\/\(.*\)/\2/"` realbackend=`echo $realuri | awk -F ':' '{print $1}'` # Now do the real work: case ${#} in 0) # this case is for "backend discovery mode" echo "sispm sispm \"SisPM backend\" \"Backend to control printer power using a sispm\"" exit 0 ;; 5) # backend needs to read from stdin if number of arguments is 5 if [ ! -f /var/run/cups/sispm/${port} ]; then /usr/local/bin/sispmctl -o $port fi touch /var/run/cups/sispm/${port} export DEVICE_URI=$realuri exec -a "${DEVICE_URI}" /usr/local/libexec/cups/backend/${realbackend} "$@" ;; 6) # backend needs to read from file if number of arguments is 6 if [ ! -f /var/run/cups/sispm/${port} ]; then /usr/local/bin/sispmctl -o $port fi touch /var/run/cups/sispm/${port} export DEVICE_URI=$realuri exec -a "${DEVICE_URI}" /usr/local/libexec/cups/backend/${realbackend} "$@" ;; 1|2|3|4|*) # these cases are unsupported echo " " echo " Usage: sispm job-id user title copies options [file]" echo " " echo " (Install as CUPS backend in /usr/lib/cups/backend/sispm)" echo " (Use as 'device URI' like \"sispm:/port/normaluri\" for printer installation.)" exit 1 esac echo 1>&2 # we reach this line only if we actually "printed something" echo "NOTICE: processed Job ${jobid} to file ${DEVICE_URI#2file:}" 1>&2 echo "NOTICE: End of \"${0}\" run...." 1>&2 echo "NOTICE: ---------------------------------------------------" 1>&2 echo 1>&2 exit 0