#! /bin/bash # # /var/spool/fax/bin/faxrcvd # Noel Burton-Krahn <noel@burton-krahn.com> # Sept 4, 1999 # # Modifications by Jonas Smedegaard <dr@jones.dk> # 2001-2002 # # $Id: faxrcvd,v 1.2 2002-03-07 16:22:51 jonas Exp $ # # faxrcvd file devID commID error-msg # # modified faxrcvd from hylafax which calls faxrcvd-mail # if [ $# != 4 ]; then echo "Usage: $0 file devID commID error-msg" exit 1 fi FILE="$1" DEVICE="$2" COMMID="$3" MSG="$4" test -f etc/setup.cache || { SPOOL=`pwd` cat<<EOF FATAL ERROR: $SPOOL/etc/setup.cache is missing! The file $SPOOL/etc/setup.cache is not present. This probably means the machine has not been setup using the faxsetup(1M) command. Read the documentation on setting up HylaFAX before you startup a server system. EOF exit 1 } . etc/setup.cache SENDFROM=FaxMaster TOADDR=FaxMaster INFO=$SBIN/faxinfo PATH="$SPOOL/sbin:$SPOOL/bin:$PATH" # # There is no good portable way to find out the fully qualified # domain name (FQDN) of the host or the TCP port for the hylafax # service so we fudge here. Folks may want to tailor this to # their needs; e.g. add a domain or use localhost so the loopback # interface is used. # HOSTNAME=`hostname` # XXX no good way to find FQDN PORT=4559 # XXX no good way to lookup service if [ -f $SPOOL/$FILE ]; then # # Check the sender's TSI and setup to dispatch # facsimile received from well-known senders. # SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print $2 }' | sed 's/^ //' 2>/dev/null`" TRUNCFILE=`echo $FILE | sed -e 's/\.tif$//'` /usr/bin/tiff2ps -a -O $SPOOL/$TRUNCFILE.ps $SPOOL/$FILE /usr/bin/ps2pdf $SPOOL/$TRUNCFILE.ps $SPOOL/$TRUNCFILE.pdf SENDTO= FILETYPE=tif if [ -f etc/FaxDispatch ]; then . etc/FaxDispatch # NB: FaxDispatch sets SENDTO based on $SENDER fi DELIVERED= if [ -n "$TOADDR" ]; then # if faxrcvd-mail "$TRUNCFILE" "$FILETYPE" "$DEVICE" "$COMMID" "$MSG" "$TOADDR" "$SENDFROM" "$SENDTO" | /usr/sbin/sendmail -f$SENDFROM -oi $TOADDR; then if faxrcvd-mail "$TRUNCFILE" "$FILETYPE" "$DEVICE" "$COMMID" "$MSG" "$TOADDR" "$SENDFROM" "$SENDTO"; then DELIVERED=1 else ERRORMSG=$! fi fi if [ -n "$SENDTO" ]; then # if faxrcvd-mail "$TRUNCFILE" "$FILETYPE" "$DEVICE" "$COMMID" "$MSG" "$TOADDR" "$SENDFROM" | /usr/sbin/sendmail -f$SENDFROM -oi $SENDTO; then if faxrcvd-mail "$TRUNCFILE" "$FILETYPE" "$DEVICE" "$COMMID" "$MSG" "$SENDTO" "$SENDFROM"; then DELIVERED=1 else ERRORMSG=$! fi fi if [ "$DELIVERED" = "1" -a "$NOCLEAN" = "" ]; then rm -f $SPOOL/$TRUNCFILE* else (echo "To: $TOADDR" echo "From: The HylaFAX Receive Agent <$SENDFROM>" echo "Subject: facsimile not received" echo "" echo "An attempt to receive facsimile on $DEVICE failed because:" echo "" echo " $ERRORMSG" echo "" ) | 2>&1 $SENDMAIL -f$SENDFROM -oi $TOADDR fi else # # Generate notification mail for a failed attempt. # (echo "To: $TOADDR" echo "From: The HylaFAX Receive Agent <$SENDFROM>" echo "Subject: facsimile not received" echo "" echo "An attempt to receive facsimile on $DEVICE failed because:" echo "" echo " $MSG" echo "" echo " ---- Transcript of session follows ----" echo "" if [ -f log/c$COMMID ]; then $SED -e '/-- data/d' \ -e '/start.*timer/d' -e '/stop.*timer/d' \ log/c$COMMID elif [ -n "$COMMID" ]; then echo " No transcript available (CommID c$COMMID)." else echo " No transcript available." fi ) | 2>&1 $SENDMAIL -f$SENDFROM -oi $TOADDR fi