#!/bin/bash # fax backend to drive efax similar to Apple's own. Ours does also some # kind of basic locking, and stores the sent faxes somewhere... # # When we're called without arguments, we simply exit (fax.orig will # report the available devices) and if we're called to transmit a fax # we will redirect the output into a logfile additionally and store # the document to be transmitted in subfolders of the Fax subsystem's # 'SavePath' -- usually /Users/Shared/Faxes --, too. Main() { # Read efax preferences . /etc/efax.rc # Look what's going on case $# in 0) echo "serial fax \"Unknown\" \"Fax Printer (fax)\"" echo "serial fax://dev/${DEV} \"Unknown\" \"modem\"" exit 0 ;; 5) FaxFile="${TMPDIR:=/tmp}/`date +%s`-$$" while [ -e "${FaxFile}" ]; do FaxFile="${FaxFile}X" done cat >"${FaxFile}" ;; 6) FaxFile="$6" ;; esac PATH=${PATH}:/usr/bin:/usr/sbin: export PATH # Collect some informations about the job (for Logging and storing the # fax with an appropriate filename) eval ParseCUPSOptions $5 Device2Use=`echo ${DEVICE_URI} | awk -F'://' '{print $2}'` Subject="$3" Number2Dial="`echo ${FAX_phone} | perl -ple 's/%([0-9A-Fa-f]{2})/chr(hex($1))/eg' 2>/dev/null`" echo "${FAX_Resolution}" | grep -q "196" case $? in 0) Resolution="High Resolution" ;; 1) Resolution="Low Resolution" ;; esac if [ -n "${FAX_faxSubject}" ]; then Subject="`echo "${FAX_faxSubject}" | perl -ple 's/%([0-9A-Fa-f]{2})/chr(hex($1))/eg' 2>/dev/null`" fi FaxName="`printf %05s "$1"` - `echo "${FAX_faxTo} (${Subject})" | tr "\/" "\:"`" # Store the fax in an appropriate place SavePath="`defaults read /Library/Preferences/com.apple.print.FaxPrefs SavePath`" if [ ! -d "${SavePath}" ]; then echo "WARNING: Couldn't save the Fax. Please specify a target folder in PrintCenter" >&2 else for Folder in Failed Sent ; do if [ ! -d "${SavePath}/${Folder}" ]; then mkdir -m777 "${SavePath}/${Folder}" fi done FaxTargetFile="${SavePath}/Sent/${FaxName}.tif" cp "${FaxFile}" "${FaxTargetFile}" chown 99:99 "${FaxTargetFile}" chmod 666 "${FaxTargetFile}" fi # Start to log into /var/log/fax/de.kaiser-edv.sent.log and # /var/log/fax/de.kaiser-edv.additional.log if [ ! -d /var/log/fax/ ]; then mkdir -m 755 /var/log/fax/ fi # Calling efax Device2Use=`echo ${DEVICE_URI} | awk -F'://' '{print $2}'` OurNumber=`defaults read /Library/Preferences/com.apple.print.FaxPrefs FaxNumber` echo "efax sending to ${Number2Dial}" >&2 efax -d${Device2Use} ${LOCK} -vewincf -iZ -i "E0&D2S7=120&C0M1X4" -oh -l "${OurNumber}" -t "${DIALPREFIX}${Number2Dial}" "${FaxFile}" Status=$? echo "Exit Code: ${Status}" >&2 if [ ${Status} -ne 0 ]; then if [ -f "${FaxTargetFile}" ]; then /bin/mv "${FaxTargetFile}" "${SavePath}/Failed" fi fi /bin/rm "${FaxFile}" } ParseCUPSOptions() { # We parse the CUPS options, delete occurences of "com.apple.print" in # their names, preprend the variable names with "CUPS_", define # them as variables and export them # If you want to use these variables in an folderaction script then # use set to have a look what vars are exported and what values they # have i="com\.apple\.print\." while [ $# -ge 1 ]; do VarName=`echo $1 | cut -d"=" -f1 | sed "s|^$i||g;s|\.[nb]\.$||g;s|\.||g"` VarValue=`echo $1 | cut -d"=" -f2 | sed "s|\ |\\\\\ |g"` eval FAX_${VarName}=${VarValue} eval export CUPS_${VarName} shift done } Main "$@"