#!/bin/sh
#
# faxlpr - Printer filter to receive a fax  postscript format and to spool it 
#          to mgetty+sendfax.
#
# This filter is part of the fax server for mgetty+sendfax.
# see http://www.itex.co.za/mgetty for information on how to configure 
# the fax server
#  
#-------------------------------------------------------------------------

TAIL=/usr/bin/tail
CAT=/bin/cat
SED=/bin/sed
FAXSPOOL=/usr/bin/faxspool
RM="/bin/rm -f"

#-------------------------------------------------
#Get the header file from the lock file
#-------------------------------------------------
HeaderFile=`$TAIL -1 lock`
Header=`$CAT $HeaderFile`

#-------------------------------------------------
#Read the diffrent variables from the header file
#The fax number is stored in the job id (J)
#-------------------------------------------------
FaxNo=`echo "$Header" | $SED -e /^[^J]/d -e s/.//`

#-------------------------------------------------
#The printjob is on stdin - copy this to a temp
# file and call faxspool to send the fax
#-------------------------------------------------
$CAT - >> /tmp/fax$$.ps

$FAXSPOOL $FaxNo /tmp/fax$$.ps


$RM /tmp/fax$$.ps
