#!/bin/sh
# The only purpose of this script is to show which environment variables
# we can deal with, how we are called and how we can pass debug messages
# through to the calling CUPS backend.
# We simply create a log file and write some stuff into it.

LOGFILE="`dirname $0`/${1}.txt"

# redirect stdout into our logfile
exec 1>"${LOGFILE}"

# If the $DEBUG variable in the postscriptfile backend is set to true
# it's a good idea, that we write all stuff to $DEBUG_LOG, too. 
# Otherwise we simply discard error messages...

if [ ${DEBUG} = TRUE ]; then
	# send everything on stderr into $DEBUG_LOG
        exec 2>>${DEBUG_LOG}
else
	# ignore error messages completely
        exec 2> /dev/null
fi

echo -e "$0: Collecting data... \c" >&2

# We've been supplied with both title and owner of the printjob on the
# command line

TITLE="$1"
OWNER="$2"

echo "We've been called as \"$0\" \"${TITLE}\" \"${OWNER}\""

echo "Let's have a look at our environment."
echo "We can use many CUPS options exported as environment variables" 
set

chmod 666 "${LOGFILE}"
echo "Finished" >&2

exit 0

