Skip to content

Instantly share code, notes, and snippets.

@mizhka
Created December 22, 2019 09:40
Show Gist options
  • Save mizhka/d95bbf552ffa22a87e0fc58d0ec488cb to your computer and use it in GitHub Desktop.
Save mizhka/d95bbf552ffa22a87e0fc58d0ec488cb to your computer and use it in GitHub Desktop.
DCP1610w filter patched for FreeBSD (location - /usr/local/libexec/cups/filter/)
#! /bin/sh
#
# CUPS filter for DCP1610W
# Copyright Brother Industries,Ltd 2006-2014
#
# Ver1.05
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
LOGFILE="/dev/null"
LOGCLEVEL="7"
DEBUG=4
LOG_LATESTONLY=1
PRINTER=DCP1610W
BASEDIR=/usr/local/etc/printers/$PRINTER/
LATESTINFO=/tmp/DCP1610W_latest_print_info
rm -f $LATESTINFO
touch $LATESTINFO
options="$5"
if [ "$(echo $options | grep 'force-debug=1')" != '' ];then
DEBUG=1
elif [ "$(echo $options | grep 'force-debug=2')" != '' ];then
DEBUG=2
elif [ "$(echo $options | grep 'force-debug=3')" != '' ];then
DEBUG=3
elif [ "$(echo $options | grep 'force-debug=4')" != '' ];then
DEBUG=4
fi
errorcode=0
set +o noclobber
if [ $DEBUG != 0 ]; then
LOGFILE=/tmp/br_cupsfilter_debug_log
fi
if [ "$PPD" = "" ]; then
PPD="/usr/share/cups/model/$PRINTER.ppd"
fi
if [ $LOGFILE != "/dev/null" ]; then
if [ $LOG_LATESTONLY = "1" ]; then
rm -f $LOGFILE
date >$LOGFILE
else
if [ -e $LOGFILE ]; then
date >>$LOGFILE
else
date >$LOGFILE
fi
fi
echo "arg0 = $0" >>$LOGFILE
echo "arg1 = $1" >>$LOGFILE
echo "arg2 = $2" >>$LOGFILE
echo "arg3 = $3" >>$LOGFILE
echo "arg4 = $4" >>$LOGFILE
echo "arg5 = $5" >>$LOGFILE
echo "arg6 = $6" >>$LOGFILE
echo "PPD = $PPD" >>$LOGFILE
fi
TMP_RC=/tmp/brDCP1610Wrc_$$
cp $BASEDIR/inf/brDCP1610Wrc $TMP_RC
export BRPRINTERRCFILE=$TMP_RC
if [ $DEBUG != 0 ]; then
echo BRPRINTERRCFILE=$BRPRINTERRCFILE >>$LOGFILE
fi
if [ -e "/$BASEDIR/lpd/filter_"${PRINTER}"" ]; then
:
else
echo "ERROR: /$BASEDIR/lpd/filter_"$PRINTER" does not exist" >>$LOGFILE
echo "ERROR: /$BASEDIR/lpd/filter_"$PRINTER" does not exist" >> $LATESTINFO
errorcode=2
rm $TMP_RC
exit
fi
if [ -e "$BASEDIR/cupswrapper/brcupsconfig4" ]; then
if [ $DEBUG = 0 ]; then
$BASEDIR/cupswrapper/brcupsconfig4 $PRINTER $PPD 0 "$options" >> /dev/null
else
$BASEDIR/cupswrapper/brcupsconfig4 $PRINTER $PPD $LOGCLEVEL "$options" >>$LOGFILE
fi
fi
if [ $DEBUG = 0 ]; then
if [ $# -ge 7 ]; then
cat $6 | /$BASEDIR/lpd/filter_"$PRINTER"
else
cat | /$BASEDIR/lpd/filter_"$PRINTER"
fi
echo brDCP1610Wrc_$$ >> $LATESTINFO
cat $TMP_RC >> $LATESTINFO
rm $TMP_RC
exit $errorcode
else
## ---------------- for debug
echo --------------------------- >>$LOGFILE
cat $BRPRINTERRCFILE >>$LOGFILE
echo --------------------------- >>$LOGFILE
INPUT_TEMP_PS=`mktemp /tmp/br_input_ps.XXXXXX`
if [ $# -ge 7 ]; then
cat $6 > $INPUT_TEMP_PS
else
cat > $INPUT_TEMP_PS
fi
case $DEBUG in
1)
export LPD_DEBUG=1
cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER"
;;
2)
export LPD_DEBUG=2
echo "" >>$LOGFILE
echo " ------PostScript Data-------" >>$LOGFILE
cat $INPUT_TEMP_PS >>$LOGFILE
cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER"
;;
3)
export LPD_DEBUG=3
echo "" >>$LOGFILE
echo " ------PostScript Data-------" >>$LOGFILE
cat $INPUT_TEMP_PS >>$LOGFILE
;;
4)
export LPD_DEBUG=4
echo "" >>$LOGFILE
echo " ------PostScript Data-------" >>$LOGFILE
cat $INPUT_TEMP_PS >>$LOGFILE
echo " ------Print Data-------" >>$LOGFILE
cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER" | hexdump -C >>$LOGFILE
cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER"
;;
esac
rm
echo brDCP1610Wrc_$$ >> $LATESTINFO
cat $TMP_RC >> $LATESTINFO
rm $TMP_RC
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment