2014-04-24 23:31:21 +02:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
|
|
|
# Brother Print filter
|
|
|
|
# Copyright (C) 2005-2011 Brother. Industries, Ltd.
|
|
|
|
|
|
|
|
# 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
|
|
|
|
#
|
2014-04-24 23:36:52 +02:00
|
|
|
# modified for voidlinux by Carlo Dormeletti carlo.dormeletti <at> email.it
|
2014-08-25 17:43:06 +02:00
|
|
|
# 2014/04/26 -- first version
|
|
|
|
# 2014/08/25 -- adapted to runit
|
2014-04-24 23:31:21 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
printer_model=""dcp197c""
|
2014-04-26 15:41:55 +02:00
|
|
|
cups_printer_name=`echo $printer_model | tr '[a-z]' '[A-Z]'`
|
|
|
|
device_name=`echo $cups_printer_name | eval sed -e 's/MFC/MFC-/' -e 's/DCP/DCP-/' -e 's/FAX/FAX-/'`
|
|
|
|
# pcfilename=`echo $cups_printer_name | tr -d '[A-Z]'`
|
2014-04-24 23:31:21 +02:00
|
|
|
device_model="Printers"
|
|
|
|
tmp_filter=/var/tmp/brlpdwrapper${printer_model}
|
|
|
|
ppd_file_name=/usr/share/ppd/cupsfilters/brother_${printer_model}_printer_en.ppd
|
2014-04-26 15:41:55 +02:00
|
|
|
brotherlpdwrapper=/usr/lib/cups/filter/brlpdwrapper${printer_model}
|
2014-04-24 23:31:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "-c" ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
echo "---------- Printer ----------"
|
|
|
|
echo "printer_model => " $printer_model
|
|
|
|
echo "cups_printer_name => " $cups_printer_name
|
|
|
|
echo "device_name => " $device_name
|
|
|
|
echo "device_model => " $device_model
|
|
|
|
echo "-------- Filters File --------"
|
|
|
|
echo "tmp_filter => " $tmp_filter
|
|
|
|
echo "ppd_file_name => " $ppd_file_name
|
2014-04-24 23:31:21 +02:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = '-e' ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
lpadmin -x ${cups_printer_name}
|
2014-04-24 23:31:21 +02:00
|
|
|
rm -f $ppd_file_name
|
2014-04-26 15:41:55 +02:00
|
|
|
rm -f $brotherlpdwrapper
|
2014-04-24 23:31:21 +02:00
|
|
|
|
2014-08-25 17:43:06 +02:00
|
|
|
sv restart cups
|
2014-04-26 15:41:55 +02:00
|
|
|
exit 0
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "-r" ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
lpadmin -x ${cups_printer_name}
|
|
|
|
|
2014-08-25 17:43:06 +02:00
|
|
|
sv restart cups
|
2014-04-26 15:41:55 +02:00
|
|
|
exit 0
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "help" ] || [ "$1" = "-h" ]; then
|
|
|
|
echo 'option -h : help'
|
|
|
|
echo ' -i : install'
|
|
|
|
echo ' -e : uninstall'
|
|
|
|
echo ' -r : remove printer'
|
|
|
|
echo ' -c : check variables'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "/opt/brother/${device_model}/${printer_model}/lpd/filter${printer_model}" ]; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
echo "ERROR : Brother LPD filter is not installed."
|
2014-04-26 15:41:55 +02:00
|
|
|
echo "ERROR : please install it."
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
cp "/opt/brother/${device_model}/${printer_model}/cupswrapper/brother_${printer_model}_printer_en.ppd" $ppd_file_name
|
|
|
|
chmod 644 $ppd_file_name
|
|
|
|
|
|
|
|
#
|
|
|
|
# create temporary CUPS Filter
|
|
|
|
#
|
|
|
|
|
|
|
|
cat <<!ENDOFWFILTER! >$tmp_filter
|
|
|
|
#! /bin/sh
|
|
|
|
#
|
|
|
|
# Brother Print filter >>
|
|
|
|
# Copyright (C) 2005-2011 Brother. Industries, Ltd.
|
|
|
|
# Ver1.10
|
|
|
|
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# modified for voidlinux by Carlo Dormeletti carlo.dormeletti <at> email.it
|
2014-04-26 15:41:55 +02:00
|
|
|
# modify date 201/04/26
|
2014-04-24 23:31:21 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
LOGFILE="/dev/null"
|
|
|
|
LOGLEVEL="1"
|
|
|
|
LOGCLEVEL="7"
|
2014-04-24 23:36:52 +02:00
|
|
|
DEBUG=0
|
2014-04-24 23:31:21 +02:00
|
|
|
NUPENABLE=1
|
|
|
|
LOG_LATESTONLY=1
|
|
|
|
errorcode=0
|
|
|
|
|
|
|
|
if [ \$DEBUG != 0 ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
LOGFILE=/tmp/br_cupsfilter_debug_log
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
PPDC=\`printenv | grep "PPD="\`
|
|
|
|
PPDC=\`echo \$PPDC | sed -e 's/PPD=//'\`
|
|
|
|
|
|
|
|
if [ "\$PPDC" = "" ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
PPDC=$ppd_file_name
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ \$LOGFILE != "/dev/null" ]; then
|
|
|
|
if [ \$LOG_LATESTONLY == "1" ]; then
|
|
|
|
rm -f \$LOGFILE
|
2014-04-26 15:41:55 +02:00
|
|
|
date >\$LOGFILE
|
2014-04-24 23:31:21 +02:00
|
|
|
else
|
|
|
|
if [ -e \$LOGFILE ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
date >>\$LOGFILE
|
2014-04-24 23:31:21 +02:00
|
|
|
else
|
2014-04-26 15:41:55 +02:00
|
|
|
date >\$LOGFILE
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
fi
|
2014-04-26 15:41:55 +02:00
|
|
|
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
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
INPUT_TEMP_PS=\`mktemp /tmp/br_input_ps.XXXXXX\`
|
|
|
|
|
|
|
|
nup="cat"
|
|
|
|
if [ "`echo \$5 | grep 'Nup='`" != '' ] && [ \$NUPENABLE != 0 ]; then
|
|
|
|
|
2014-04-26 15:41:55 +02:00
|
|
|
if [ "`echo \$5 | grep 'Nup=64'`" != '' ]; then
|
|
|
|
nup="psnup -64"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=32'`" != '' ]; then
|
|
|
|
nup="psnup -32"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=25'`" != '' ]; then
|
|
|
|
nup="psnup -25"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=16'`" != '' ]; then
|
|
|
|
nup="psnup -16"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=8'`" != '' ]; then
|
|
|
|
nup="psnup -8"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=6'`" != '' ]; then
|
|
|
|
nup="psnup -6"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=4'`" != '' ]; then
|
|
|
|
nup="psnup -4"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=2'`" != '' ]; then
|
|
|
|
nup="psnup -2"
|
|
|
|
elif [ "`echo \$5 | grep 'Nup=1'`" != '' ]; then
|
|
|
|
nup="cat"
|
|
|
|
fi
|
|
|
|
echo "NUP=\$nup" >>\$LOGFILE
|
|
|
|
if [ -e /usr/bin/psnup ]; then
|
|
|
|
if [ \$# -ge 7 ]; then
|
|
|
|
cat \$6 | \$nup > \$INPUT_TEMP_PS
|
|
|
|
else
|
|
|
|
cat | \$nup > \$INPUT_TEMP_PS
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ \$# -ge 7 ]; then
|
2014-04-24 23:31:21 +02:00
|
|
|
cp \$6 \$INPUT_TEMP_PS
|
2014-04-26 15:41:55 +02:00
|
|
|
else
|
2014-04-24 23:31:21 +02:00
|
|
|
cat > \$INPUT_TEMP_PS
|
2014-04-26 15:41:55 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ \$# -ge 7 ]; then
|
|
|
|
cp \$6 \$INPUT_TEMP_PS
|
|
|
|
else
|
|
|
|
cat > \$INPUT_TEMP_PS
|
|
|
|
fi
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
2014-04-26 15:41:55 +02:00
|
|
|
|
2014-04-24 23:31:21 +02:00
|
|
|
if [ -e "/opt/brother/${device_model}/${printer_model}/lpd/filter${printer_model}" ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
:
|
2014-04-24 23:31:21 +02:00
|
|
|
else
|
2014-04-26 15:41:55 +02:00
|
|
|
echo "ERROR: /opt/brother/${device_model}/${printer_model}/lpd/filter${printer_model} does not exist" >>\$LOGFILE
|
|
|
|
errorcode=30
|
|
|
|
exit
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
CUPSOPTION=\`echo "\$5 Copies=\$4" | sed -e 's/BrMirror=OFF/MirrorPrint=OFF/' -e 's/BrMirror=ON/MirrorPrint=ON/' -e 's/BrChain/Chain/' -e 's/BrBrightness/Brightness/' -e 's/BrContrast/Contrast/' -e 's/BrHalfCut/HalfCut/' -e 's/BrAutoTapeCut/AutoCut/' -e 's/BrHalftonePattern/Halftone/' -e 's/Binary/Binary/' -e 's/Dither/Dither/' -e 's/ErrorDiffusion/ErrorDiffusion/' -e 's/PageSize/media/' -e 's/BrSheets/Sheets/' -e 's/multiple-document-handling/Collate/' -e 's/separate-documents-collated-copies/ON/' -e 's/separate-documents-uncollated-copies/OFF/'\`
|
|
|
|
|
|
|
|
if [ -e "/opt/brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1" ]; then
|
|
|
|
if [ \$DEBUG = 0 ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
/opt/brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1 ${cups_printer_name} \$PPDC 0 "\$CUPSOPTION" "${printer_model}">> /dev/null
|
2014-04-24 23:31:21 +02:00
|
|
|
else
|
2014-04-26 15:41:55 +02:00
|
|
|
/opt/brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1 ${cups_printer_name} \$PPDC \$LOGCLEVEL "\$CUPSOPTION" "${printer_model}">>\$LOGFILE
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ \$DEBUG -lt 10 ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
cat \$INPUT_TEMP_PS | /opt/brother/${device_model}/${printer_model}/lpd/filter${printer_model} "\$\$" "CUPS" "USB"
|
|
|
|
|
|
|
|
if [ \$LOGLEVEL -gt 2 ]; then
|
|
|
|
if [ \$LOGFILE != "/dev/null" ]; then
|
|
|
|
echo "" >>\$LOGFILE
|
|
|
|
echo " ------PostScript Data-------" >>\$LOGFILE
|
|
|
|
cat \$INPUT_TEMP_PS >>\$LOGFILE
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
2014-04-26 15:41:55 +02:00
|
|
|
fi
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
2014-04-26 15:41:55 +02:00
|
|
|
|
2014-04-24 23:31:21 +02:00
|
|
|
rm -f \$INPUT_TEMP_PS
|
|
|
|
|
|
|
|
exit $errorcode
|
|
|
|
|
|
|
|
!ENDOFWFILTER!
|
|
|
|
|
|
|
|
chmod 755 $tmp_filter
|
|
|
|
|
|
|
|
#
|
2014-04-26 15:41:55 +02:00
|
|
|
# check brotherlpdwrapper in /usr/lib/cups/filter
|
2014-04-24 23:31:21 +02:00
|
|
|
#
|
2014-04-26 15:41:55 +02:00
|
|
|
|
2014-04-24 23:31:21 +02:00
|
|
|
if [ -d /usr/lib/cups/filter ]; then
|
2014-04-26 15:41:55 +02:00
|
|
|
rm -f $brotherlpdwrapper
|
|
|
|
cp $tmp_filter $brotherlpdwrapper
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
2014-04-26 15:41:55 +02:00
|
|
|
# remove temporary script file
|
2014-04-24 23:31:21 +02:00
|
|
|
#
|
2014-04-26 15:41:55 +02:00
|
|
|
|
2014-04-24 23:31:21 +02:00
|
|
|
rm -f $tmp_filter
|
|
|
|
|
|
|
|
chmod a+w /opt/brother/${device_model}/${printer_model}/inf/br${printer_model}rc
|
|
|
|
chmod a+w /opt/brother/${device_model}/${printer_model}/inf
|
|
|
|
|
|
|
|
sleep 2s
|
|
|
|
|
2014-08-25 17:43:06 +02:00
|
|
|
sv restart cups
|
2014-04-24 23:31:21 +02:00
|
|
|
|
|
|
|
port2=`lpinfo -v | grep -i 'usb://Brother/${device_name}' | head -1`
|
|
|
|
|
|
|
|
if [ "$port2" = '' ];then
|
2014-04-26 15:41:55 +02:00
|
|
|
port2=`lpinfo -v | grep 'usb://Brother' | head -1`
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$port2" = '' ];then
|
2014-04-26 15:41:55 +02:00
|
|
|
port2=`lpinfo -v | grep 'usb://' | head -1`
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
port=`echo $port2| sed s/direct//g`
|
|
|
|
|
|
|
|
if [ "$port" = '' ];then
|
2014-04-26 15:41:55 +02:00
|
|
|
port=usb:/dev/usb/lp0
|
2014-04-24 23:31:21 +02:00
|
|
|
fi
|
|
|
|
|
2014-04-26 15:41:55 +02:00
|
|
|
lpadmin -p ${cups_printer_name} -E -v $port -P $ppd_file_name
|
2014-04-24 23:31:21 +02:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
|