#!/bin/bash
#
# /usr/lib/lpdfilter/post/bin2ppaXXXX
#
# filter used by /usr/lib/lpdfilter/bin/if
#
# Copyright 2001 SuSE GmbH, Nuernberg Germany
#
# Author: Werner Fink <feedback@suse.de>

#
# Activate debugging if requested.
#
if test "$DEBUG" = "medium" -o "$DEBUG" = "high" ; then
    # bash should be verbose
    set -x
    # Redirect stderr to a file
    exec 2> $(mktemp /tmp/lpdfilter.${0##*/}-$$.XXXXXX) || exit 2
fi

#
# Get our environment
#
. /usr/lib/lpdfilter/global/signals
. /usr/lib/lpdfilter/global/functions
type -p readpc   &> /dev/null || export PATH=/usr/lib/lpdfilter/bin:${PATH}
type -p xpmtoppm &> /dev/null || export PATH=${PATH}:/usr/X11R6/bin

#
# Check for our filter program
#
type -p pnm2ppa &> /dev/null || fault_filetype pnm2ppa

#
# Optional printer
#
model="${0#*bin2ppa}"
  cfg=""

if   test -r /etc/pnm2ppa-${queue}.conf ; then
     cfg="-f /etc/pnm2ppa-${queue}.conf"
elif test -r /etc/pnm2ppa-${model}.conf ; then
     cfg="-f /etc/pnm2ppa-${model}.conf"
elif test -r /etc/pnm2ppa.conf ; then
     cfg="-f /etc/pnm2ppa.conf"
fi

#
# Reads ppmraw gs output
#
if test "${color:=no}" = "no" ; then
    exec 0< <(exec -a ppmtopgm ppmtopgm)
    exec -a pnm2ppa pnm2ppa ${cfg:+$cfg} --bw
else
    exec -a pnm2ppa pnm2ppa ${cfg:+$cfg}
fi
