View File pipe of Package cups-backends (Project home:uninstall:Printing)
# CUPS wrapper backend "pipe" for printing to any program.
# It forwards the print job data like a pipe into another command.
# Author: Johannes Meixner <firstname.lastname@example.org>, 2009, 2014
# For basic information see "man 7 backend" and "man 7 filter".
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU GENERAL PUBLIC LICENSE Version 2
# as published by the Free Software Foundation.
# Activate the "set -x" line to get debugging info in /var/log/cups/error_log:
# Output "Device Discovery" information on stdout:
if test "$#" = "0"
echo 'direct pipe "Unknown" "Forward print job data like a pipe to another command"'
# Output usage information in case of wrong number of parameters:
if test "$#" != "5" -a "$#" != "6"
echo 'Usage: pipe job-id user title copies options [file]' 1>&2
echo 'Queue setup example:' 1>&2
echo 'lpadmin -p queue_name -v "pipe:/path/to/command?option1=value1&-option2&value2" -E' 1>&2
echo 'The command is called with the specified options as:' 1>&2
echo '/path/to/command option1=value1 -option2 value2' 1>&2
echo 'The original command line parameters (... job-id user ...)' 1>&2
echo 'are provided as environment variables PIPE_BACKEND_ARGV[0-6]' 1>&2
# Keep the original command line parameters (... job-id user ...)
# in environment variables to make them available for the command:
# Have the input at fd0 (stdin) in any case:
if test -n "$6"
# To be on the safe side clip anything after the first space character
# because spaces are excluded characters in a URI (see RFC 2396):
# Extract the command to which the job schould be sent from the URI.
# Clip the URI scheme (anything up to the first ':' character) and
# clip anything after the first '?' character
# because anything after the first '?' character are options:
# Extract the options (e.g. from 'pipe:/path/to/command?option1=value1&-option2&value2'
# clip anything up to the first '?' character and
# replace the options separator '&' character by a space:
if test "$OPTIONS" = "$URI"
OPTIONS=$( echo "$OPTIONS" | tr '&' ' ' )
# Options could have been specified in a wrong way
# as addendum to the DeviceURI separated by spaces
# (spaces are excluded characters in a URI, see RFC 2396)
# which works by luck at least for some CUPS versions
# see https://bugzilla.novell.com/show_bug.cgi?id=499735
# like 'pipe:/path/to/command option1=value1 -option2 value2'
# nevertheless use additionally those kind of options too:
if test "$MORE_OPTIONS" = "$DEVICE_URI"
OPTIONS=$( echo "$OPTIONS" "$MORE_OPTIONS" | tr -s ' ' )
# Test if the command is executable:
if ! test -x "$COMMAND"
echo "Cannot execute $COMMAND" 1>&2
# Replace this wrapper with the actual command
# so that it exits with the exit code of the command
# and that the command gets any signals directly.
exec "$COMMAND" $OPTIONS