#! /bin/sh
#
# Brother Print filter
# Copyright (C) 2005-2020 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
#

if [ "$1" = '-e' ]; then
if [ -f /etc/debian_version ] ; then
sudo rm -rf /var/lib/dpkg/info/td2130ncupswrapper*
fi
  rm -f /usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
  rm -f /usr/lib64/cups/filter/
  rm -f /opt/brother/td2130n/bin/cupswrapper/brcupsconfpt1
if [  -e /etc/init.d/cups ]; then
   /etc/init.d/cups restart
elif [  -e /etc/init.d/cupsys ]; then
   /etc/init.d/cupsys restart
fi
  exit 0
fi
if [ "$1" = "-r" ]; then
if [  -e /etc/init.d/cups ]; then
   /etc/init.d/cups restart
elif [  -e /etc/init.d/cupsys ]; then
   /etc/init.d/cupsys restart
fi
  exit 0
fi
if [ "$1" = "help" ] || [ "$1" = "-h" ]; then
  echo   'option -h : help'
  echo   '       -i : install'
  echo   '       -e : uninstall'
  echo   '       -r : remove printer'
  exit 0
fi

if [ -e "/opt/brother/td2130n/bin/lpd/filtertd2130n" ]; then
  :
else
  echo "ERROR : Brother LPD filter is not installed."
fi
if [ -f /etc/debian_version ] ; then 
if [  -d /usr/share/cups/model ]; then
rm -f /usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
ppd_file_name=/usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
ppd_file_name1=/usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
fi
if [  -d /usr/share/ppd ]; then
rm -f /usr/share/ppd/brother_td2130n_printer_en.ppd
ppd_file_name1=/usr/share/ppd/brother_td2130n_printer_en.ppd
fi
else 
rm -f /usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
ppd_file_name=/usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
ppd_file_name1=/usr/share/cups/model/Brother/brother_td2130n_printer_en.ppd
fi
if [ -e "/usr/share/cups/model/Brother" ]; then
  :
else
	mkdir -p /usr/share/cups/model/Brother
fi
cat <<ENDOFPPDFILE | tee $ppd_file_name >> $ppd_file_name1
*PPD-Adobe: "4.3"

*%================================================
*%	Copyright(C) 2005-2020 Brother Industries, Ltd.
*%	"Brother TD-2130N CUPS"
*%================================================

*%==== General Information Keywords ========================
*FormatVersion: "4.3"
*FileVersion: "1.00"
*LanguageVersion: English
*LanguageEncoding: UTF-8
*PCFileName: "TD-2130N.PPD"
*Manufacturer: "Brother"
*Product: "(TD-2130N)"
*1284DeviceID: "MFG: Brother;MDL: TD-2130N"
*cupsVersion: 1.4
*cupsManualCopies: True
*cupsFilter: "application/vnd.cups-postscript 0 brother_td2130n"
*cupsModelNumber: 1
*ModelName: "Brother TD-2130N"
*ShortNickName: "Brother TD-2130N"
*NickName: "Brother TD-2130N CUPS"
*%APDialogExtension: "/Library/Printers/Brother/PDEs/BRPtouchQuality.plugin"
*%APPrinterIconPath: "/Library/Printers/Brother/Icons/BRPTQL.icns"
*PSVersion: "(3010.106) 3"

*%==== Basic Device Capabilities =============
*LanguageLevel: "3"
*ColorDevice: False
*DefaultColorSpace: Gray
*FileSystem: False
*Throughput: "12"
*LandscapeOrientation: Plus90
*VariablePaperSize: False
*TTRasterizer: Type42
*FreeVM: "1700000"

*%DefaultOutputOrder: Reverse

*%==== Media Selection ======================
*OpenUI *PageSize/纸张大小: PickOne
*OrderDependency: 11 AnySetup *PageSize
*DefaultPageSize: 50x30
*PageSize 30x30/30mm x 30mm(1.1" x 1.1"):	"          "
*PageSize 40x40/40mm x 40mm(1.5" x 1.5"):	"          "
*PageSize 40x50/40mm x 50mm(1.5" x 1.9"):	"          "
*PageSize 40x60/40mm x 60mm(1.5" x 2.3"):	"          "
*PageSize 50x30/50mm x 30mm(1.9" x 1.1"):	"          "
*PageSize 51x26/51mm x 26mm(2.0" x 1.0"):	"          "
*PageSize 60x60/60mm x 60mm(2.3" x 2.3"):	"          "
*PageSize 57X1/57mm(2.25"):			"          "
*PageSize 58X1/58mm(2.28"):			"          "
*CloseUI: *PageSize

*OpenUI *PageRegion: PickOne
*OrderDependency: 12 AnySetup *PageRegion
*DefaultPageRegion: 50x30
*PageRegion 30x30/30mm x 30mm(1.1" x 1.1"):	"          "
*PageRegion 40x40/40mm x 40mm(1.5" x 1.5"):	"          "
*PageRegion 40x50/40mm x 50mm(1.5" x 1.9"):	"          "
*PageRegion 40x60/40mm x 60mm(1.5" x 2.3"):	"          "
*PageRegion 50x30/50mm x 30mm(1.9" x 1.1"):	"          "
*PageRegion 51x26/51mm x 26mm(2.0" x 1.0"):	"          "
*PageRegion 60x60/60mm x 60mm(2.3" x 2.3"):	"          "
*PageRegion 57X1/57mm(2.25"):			"          "
*PageRegion 58X1/58mm(2.28"):			"          "
*CloseUI: *PageRegion


*DefaultImageableArea: 50x30
*ImageableArea 30x30/30mm x 30mm(1.1" x 1.1"):	"4.32 8.40 80.64 76.56"
*ImageableArea 40x40/40mm x 40mm(1.5" x 1.5"):	"4.32 8.40 108.96 104.88"
*ImageableArea 40x50/40mm x 50mm(1.5" x 1.9"):	"4.32 8.40 108.96 133.44"
*ImageableArea 40x60/40mm x 60mm(1.5" x 2.3"):	"4.32 8.40 108.96 161.76"
*ImageableArea 50x30/50mm x 30mm(1.9" x 1.1"):	"4.32 8.40 137.52 76.56"
*ImageableArea 51x26/51mm x 26mm(2.0" x 1.0"):	"4.32 8.40 139.68 64.08"
*ImageableArea 60x60/60mm x 60mm(2.3" x 2.3"):	"5.76 8.40 164.40 161.76"
*ImageableArea 57X1/57mm(2.25"):			"4.32 8.40 157.68 275.04"
*ImageableArea 58X1/58mm(2.28"):			"4.32 8.40 160.08 275.04"

*%==== Information About Media Sizes ========
*DefaultPaperDimension: 50x30
*PaperDimension 30x30/30mm x 30mm(1.1" x 1.1"):	"84.96 84.96"
*PaperDimension 40x40/40mm x 40mm(1.5" x 1.5"):	"113.28 113.28"
*PaperDimension 40x50/40mm x 50mm(1.5" x 1.9"):	"113.28 141.84"
*PaperDimension 40x60/40mm x 60mm(1.5" x 2.3"):	"113.28 170.16"
*PaperDimension 50x30/50mm x 30mm(1.9" x 1.1"):	"141.84 84.96"
*PaperDimension 51x26/51mm x 26mm(2.0" x 1.0"):	"144.00 72.48"
*PaperDimension 60x60/60mm x 60mm(2.3" x 2.3"):	"170.16 170.16"
*PaperDimension 57X1/57mm(2.25"):			"162.00 283.44"
*PaperDimension 58X1/58mm(2.28"):			"164.40 283.44"


*OpenUI *BrMargin/进带: PickOne
*OrderDependency: 23 AnySetup  *BrMargin
*DefaultBrMargin: 3
*BrMargin 3/3 mm: "          "
*BrMargin 4/4 mm: "          "
*BrMargin 5/5 mm: "          "
*BrMargin 6/6 mm: "          "
*BrMargin 7/7 mm: "          "
*BrMargin 8/8 mm: "          "
*BrMargin 9/9 mm: "          "
*BrMargin 10/10 mm: "          "
*BrMargin 11/11 mm: "          "
*BrMargin 12/12 mm: "          "
*BrMargin 13/13 mm: "          "
*BrMargin 14/14 mm: "          "
*BrMargin 15/15 mm: "          "
*BrMargin 16/16 mm: "          "
*BrMargin 17/17 mm: "          "
*BrMargin 18/18 mm: "          "
*BrMargin 19/19 mm: "          "
*BrMargin 20/20 mm: "          "
*BrMargin 21/21 mm: "          "
*BrMargin 22/22 mm: "          "
*BrMargin 23/23 mm: "          "
*BrMargin 24/24 mm: "          "
*BrMargin 25/25 mm: "          "
*BrMargin 26/26 mm: "          "
*BrMargin 27/27 mm: "          "
*BrMargin 28/28 mm: "          "
*BrMargin 29/29 mm: "          "
*BrMargin 30/30 mm: "          "
*CloseUI: *BrMargin

*OpenUI *BrPriority/质量: PickOne
*OrderDependency: 22 AnySetup  *BrPriority
*DefaultBrPriority: BrSpeed
*BrPriority BrSpeed/打印速度优先: "          "
*BrPriority BrQuality/打印质量优先: "          "
*CloseUI: *BrPriority

*% added start printing/Compress for QL720NW
*OpenUI *BrCompress/开始打印: PickOne
*OrderDependency: 23 AnySetup  *BrCompress
*DefaultBrCompress: OFF
*BrCompress OFF/开始接收数据后立即打印: "          "
*BrCompress ON/接收一页数据后打印: "          "
*CloseUI: *BrCompress

*% added for QL720NW
*%OpenUI *BrCutLabel/自动剪切: PickOne
*%OrderDependency: 23 AnySetup  *BrCutLabel
*%DefaultBrCutLabel: 1
*%BrCutLabel 0/关: "          "
*%BrCutLabel 1/1 标签: "          "
*%BrCutLabel 2/2 标签: "          "
*%BrCutLabel 3/3 标签: "          "
*%BrCutLabel 4/4 标签: "          "
*%BrCutLabel 5/5 标签: "          "
*%BrCutLabel 6/6 标签: "          "
*%BrCutLabel 7/7 标签: "          "
*%BrCutLabel 8/8 标签: "          "
*%BrCutLabel 9/9 标签: "          "
*%BrCutLabel 10/10 标签: "          "
*%BrCutLabel 11/11 标签: "          "
*%BrCutLabel 12/12 标签: "          "
*%BrCutLabel 13/13 标签: "          "
*%BrCutLabel 14/14 标签: "          "
*%BrCutLabel 15/15 标签: "          "
*%BrCutLabel 16/16 标签: "          "
*%BrCutLabel 17/17 标签: "          "
*%BrCutLabel 18/18 标签: "          "
*%BrCutLabel 19/19 标签: "          "
*%BrCutLabel 20/20 标签: "          "
*%BrCutLabel 21/21 标签: "          "
*%BrCutLabel 22/22 标签: "          "
*%BrCutLabel 23/23 标签: "          "
*%BrCutLabel 24/24 标签: "          "
*%BrCutLabel 25/25 标签: "          "
*%BrCutLabel 26/26 标签: "          "
*%BrCutLabel 27/27 标签: "          "
*%BrCutLabel 28/28 标签: "          "
*%BrCutLabel 29/29 标签: "          "
*%BrCutLabel 30/30 标签: "          "
*%CloseUI: *BrCutLabel


*%  added Cut At End for QL720NW
*%OpenUI *BrCutAtEnd/末端切割: PickOne
*%OrderDependency: 21 AnySetup  *BrCutAtEnd
*%DefaultBrCutAtEnd: ON
*%BrCutAtEnd OFF/关: "          "
*%BrCutAtEnd ON/开: "          "
*%CloseUI: *BrCutAtEnd

*%=====  Added trim tape for QL720NW... =====
*OpenUI *BrTrimtape/数据之后修剪色带: PickOne
*OrderDependency: 21 AnySetup  *BrTrimtape
*DefaultBrTrimtape: OFF
*BrTrimtape OFF/关: "          "
*BrTrimtape ON/开: "          "
*CloseUI: *BrTrimtape
*%===== ... Added trim tape for QL720NW =====


*OpenUI *BrMirror/镜像打印: PickOne
*OrderDependency: 21 AnySetup  *BrMirror
*DefaultBrMirror: OFF
*BrMirror OFF/关: "          "
*BrMirror ON/开: "          "
*CloseUI: *BrMirror

*OpenUI *BrRotate/翻转 180 度: PickOne
*OrderDependency: 21 AnySetup  *BrRotate
*DefaultBrRotate: OFF
*BrRotate OFF/关: "          "
*BrRotate ON/开: "          "
*CloseUI: *BrRotate

*OpenUI *BrPeeler/使用剥离器功能: PickOne
*OrderDependency: 21 AnySetup  *BrPeeler
*DefaultBrPeeler: OFF
*BrPeeler OFF/关: "          "
*BrPeeler ON/开: "          "
*CloseUI: *BrPeeler


*%==== Custom Page Sizes ====================
*%NonUIOrderDependency: 40 AnySetup *CustomPageSize
*%VariablePaperSize: True
*%LeadingEdge Short: "          "
*%DefaultLeadingEdge: Short
*%MaxMediaWidth: "612"
*%MaxMediaHeight: "1008"
*%HWMargins: 12 12 12 12
*%CustomPageSize True: "
*%	<</BRCustomPageSize true>> setpagedevice
*%	pop pop pop
*%	<< /PageSize [ 5 -2 roll ] /ImagingBBox null >>
*%	setpagedevice
*%"
*%End
*%ParamCustomPageSize Width: 1 points 284 612
*%ParamCustomPageSize Height: 2 points 595 1008
*%ParamCustomPageSize WidthOffset: 3 points 0 0
*%ParamCustomPageSize HeightOffset: 4 points 0 0
*%ParamCustomPageSize Orientation: 5 int 0 3

*%=== Paper Feed================================
*%OpenUI *InputSlot: PickOne
*%OrderDependency: 13 AnySetup *InputSlot
*%DefaultInputSlot: AutoSelect
*%InputSlot AutoSelect/Auto Select: 	"          "
*%InputSlot Tray1/Tray1: 		"          "
*%InputSlot Manual/Manual: 		"          "
*%CloseUI: *InputSlot

*%==== Resolution Features =================================
*%OpenUI *Resolution/质量: PickOne
*%OrderDependency: 14 AnySetup *Resolution
*%DefaultResolution: Normal
*%Resolution	Normal/标准(300 * 300dpi): 	"          "
*%CloseUI: *Resolution

*%=== Media Type ================================
*%OpenUI *MediaType/Media Type: PickOne
*%OrderDependency: 17 AnySetup *MediaType
*%DefaultMediaType: Plain
*%MediaType Plain/Plain Paper: "          "
*%MediaType Thin/Thin Paper: "          "
*%MediaType Thick/Thick Paper: "          "
*%MediaType Thicker/Thicker Paper: "          "
*%MediaType Transparencies/Transparencies: "          "
*%MediaType Recycled/Recycled Paper: "          "
*%CloseUI: *MediaType

*%#S1

*OpenUI *BrHalftonePattern/半色调: PickOne
*OrderDependency: 24 AnySetup  *BrHalftonePattern
*DefaultBrHalftonePattern: BrErrorDiffusion
*BrHalftonePattern BrBinary/二进制: "          "
*BrHalftonePattern BrDither/像素混合: "          "
*BrHalftonePattern BrErrorDiffusion/误差扩散: "          "
*CloseUI: *BrHalftonePattern

*OpenUI *BrBrightness/亮度: PickOne
*OrderDependency: 25 AnySetup  *BrBrightness
*DefaultBrBrightness: 0
*BrBrightness 50/50: "          "
*BrBrightness 49/49: "          "
*BrBrightness 48/48: "          "
*BrBrightness 47/47: "          "
*BrBrightness 46/46: "          "
*BrBrightness 45/45: "          "
*BrBrightness 44/44: "          "
*BrBrightness 43/43: "          "
*BrBrightness 42/42: "          "
*BrBrightness 41/41: "          "
*BrBrightness 40/40: "          "
*BrBrightness 39/39: "          "
*BrBrightness 38/38: "          "
*BrBrightness 37/37: "          "
*BrBrightness 36/36: "          "
*BrBrightness 35/35: "          "
*BrBrightness 34/34: "          "
*BrBrightness 33/33: "          "
*BrBrightness 32/32: "          "
*BrBrightness 31/31: "          "
*BrBrightness 30/30: "          "
*BrBrightness 29/29: "          "
*BrBrightness 28/28: "          "
*BrBrightness 27/27: "          "
*BrBrightness 26/26: "          "
*BrBrightness 25/25: "          "
*BrBrightness 24/24: "          "
*BrBrightness 23/23: "          "
*BrBrightness 22/22: "          "
*BrBrightness 21/21: "          "
*BrBrightness 20/20: "          "
*BrBrightness 19/19: "          "
*BrBrightness 18/18: "          "
*BrBrightness 17/17: "          "
*BrBrightness 16/16: "          "
*BrBrightness 15/15: "          "
*BrBrightness 14/14: "          "
*BrBrightness 13/13: "          "
*BrBrightness 12/12: "          "
*BrBrightness 11/11: "          "
*BrBrightness 10/10: "          "
*BrBrightness 9/9: "          "
*BrBrightness 8/8: "          "
*BrBrightness 7/7: "          "
*BrBrightness 6/6: "          "
*BrBrightness 5/5: "          "
*BrBrightness 4/4: "          "
*BrBrightness 3/3: "          "
*BrBrightness 2/2: "          "
*BrBrightness 1/1: "          "
*BrBrightness 0/0: "          "
*BrBrightness -1/-1: "          "
*BrBrightness -2/-2: "          "
*BrBrightness -3/-3: "          "
*BrBrightness -4/-4: "          "
*BrBrightness -5/-5: "          "
*BrBrightness -6/-6: "          "
*BrBrightness -7/-7: "          "
*BrBrightness -8/-8: "          "
*BrBrightness -9/-9: "          "
*BrBrightness -10/-10: "          "
*BrBrightness -11/-11: "          "
*BrBrightness -12/-12: "          "
*BrBrightness -13/-13: "          "
*BrBrightness -14/-14: "          "
*BrBrightness -15/-15: "          "
*BrBrightness -16/-16: "          "
*BrBrightness -17/-17: "          "
*BrBrightness -18/-18: "          "
*BrBrightness -19/-19: "          "
*BrBrightness -20/-20: "          "
*BrBrightness -21/-21: "          "
*BrBrightness -22/-22: "          "
*BrBrightness -23/-23: "          "
*BrBrightness -24/-24: "          "
*BrBrightness -25/-25: "          "
*BrBrightness -26/-26: "          "
*BrBrightness -27/-27: "          "
*BrBrightness -28/-28: "          "
*BrBrightness -29/-29: "          "
*BrBrightness -30/-30: "          "
*BrBrightness -31/-31: "          "
*BrBrightness -32/-32: "          "
*BrBrightness -33/-33: "          "
*BrBrightness -34/-34: "          "
*BrBrightness -35/-35: "          "
*BrBrightness -36/-36: "          "
*BrBrightness -37/-37: "          "
*BrBrightness -38/-38: "          "
*BrBrightness -39/-39: "          "
*BrBrightness -40/-40: "          "
*BrBrightness -41/-41: "          "
*BrBrightness -42/-42: "          "
*BrBrightness -43/-43: "          "
*BrBrightness -44/-44: "          "
*BrBrightness -45/-45: "          "
*BrBrightness -46/-46: "          "
*BrBrightness -47/-47: "          "
*BrBrightness -48/-48: "          "
*BrBrightness -49/-49: "          "
*BrBrightness -50/-50: "          "
*CloseUI: *BrBrightness

*OpenUI *BrContrast/对比度: PickOne
*OrderDependency: 26 AnySetup  *BrContrast
*DefaultBrContrast: 0
*BrContrast 50/50: "          "
*BrContrast 49/49: "          "
*BrContrast 48/48: "          "
*BrContrast 47/47: "          "
*BrContrast 46/46: "          "
*BrContrast 45/45: "          "
*BrContrast 44/44: "          "
*BrContrast 43/43: "          "
*BrContrast 42/42: "          "
*BrContrast 41/41: "          "
*BrContrast 40/40: "          "
*BrContrast 39/39: "          "
*BrContrast 38/38: "          "
*BrContrast 37/37: "          "
*BrContrast 36/36: "          "
*BrContrast 35/35: "          "
*BrContrast 34/34: "          "
*BrContrast 33/33: "          "
*BrContrast 32/32: "          "
*BrContrast 31/31: "          "
*BrContrast 30/30: "          "
*BrContrast 29/29: "          "
*BrContrast 28/28: "          "
*BrContrast 27/27: "          "
*BrContrast 26/26: "          "
*BrContrast 25/25: "          "
*BrContrast 24/24: "          "
*BrContrast 23/23: "          "
*BrContrast 22/22: "          "
*BrContrast 21/21: "          "
*BrContrast 20/20: "          "
*BrContrast 19/19: "          "
*BrContrast 18/18: "          "
*BrContrast 17/17: "          "
*BrContrast 16/16: "          "
*BrContrast 15/15: "          "
*BrContrast 14/14: "          "
*BrContrast 13/13: "          "
*BrContrast 12/12: "          "
*BrContrast 11/11: "          "
*BrContrast 10/10: "          "
*BrContrast 9/9: "          "
*BrContrast 8/8: "          "
*BrContrast 7/7: "          "
*BrContrast 6/6: "          "
*BrContrast 5/5: "          "
*BrContrast 4/4: "          "
*BrContrast 3/3: "          "
*BrContrast 2/2: "          "
*BrContrast 1/1: "          "
*BrContrast 0/0: "          "
*BrContrast -1/-1: "          "
*BrContrast -2/-2: "          "
*BrContrast -3/-3: "          "
*BrContrast -4/-4: "          "
*BrContrast -5/-5: "          "
*BrContrast -6/-6: "          "
*BrContrast -7/-7: "          "
*BrContrast -8/-8: "          "
*BrContrast -9/-9: "          "
*BrContrast -10/-10: "          "
*BrContrast -11/-11: "          "
*BrContrast -12/-12: "          "
*BrContrast -13/-13: "          "
*BrContrast -14/-14: "          "
*BrContrast -15/-15: "          "
*BrContrast -16/-16: "          "
*BrContrast -17/-17: "          "
*BrContrast -18/-18: "          "
*BrContrast -19/-19: "          "
*BrContrast -20/-20: "          "
*BrContrast -21/-21: "          "
*BrContrast -22/-22: "          "
*BrContrast -23/-23: "          "
*BrContrast -24/-24: "          "
*BrContrast -25/-25: "          "
*BrContrast -26/-26: "          "
*BrContrast -27/-27: "          "
*BrContrast -28/-28: "          "
*BrContrast -29/-29: "          "
*BrContrast -30/-30: "          "
*BrContrast -31/-31: "          "
*BrContrast -32/-32: "          "
*BrContrast -33/-33: "          "
*BrContrast -34/-34: "          "
*BrContrast -35/-35: "          "
*BrContrast -36/-36: "          "
*BrContrast -37/-37: "          "
*BrContrast -38/-38: "          "
*BrContrast -39/-39: "          "
*BrContrast -40/-40: "          "
*BrContrast -41/-41: "          "
*BrContrast -42/-42: "          "
*BrContrast -43/-43: "          "
*BrContrast -44/-44: "          "
*BrContrast -45/-45: "          "
*BrContrast -46/-46: "          "
*BrContrast -47/-47: "          "
*BrContrast -48/-48: "          "
*BrContrast -49/-49: "          "
*BrContrast -50/-50: "          "
*CloseUI: *BrContrast

*DefaultFont: Courier
*Font AvantGarde-Book: Standard "(001.006S)" Standard ROM
*Font AvantGarde-BookOblique: Standard "(001.006S)" Standard ROM
*Font AvantGarde-Demi: Standard "(001.007S)" Standard ROM
*Font AvantGarde-DemiOblique: Standard "(001.007S)" Standard ROM
*Font Bookman-Demi: Standard "(001.004S)" Standard ROM
*Font Bookman-DemiItalic: Standard "(001.004S)" Standard ROM
*Font Bookman-Light: Standard "(001.004S)" Standard ROM
*Font Bookman-LightItalic: Standard "(001.004S)" Standard ROM
*Font Courier: Standard "(002.004S)" Standard ROM
*Font Courier-Bold: Standard "(002.004S)" Standard ROM
*Font Courier-BoldOblique: Standard "(002.004S)" Standard ROM
*Font Courier-Oblique: Standard "(002.004S)" Standard ROM
*Font Helvetica: Standard "(001.006S)" Standard ROM
*Font Helvetica-Bold: Standard "(001.007S)" Standard ROM
*Font Helvetica-BoldOblique: Standard "(001.007S)" Standard ROM
*Font Helvetica-Narrow: Standard "(001.006S)" Standard ROM
*Font Helvetica-Narrow-Bold: Standard "(001.007S)" Standard ROM
*Font Helvetica-Narrow-BoldOblique: Standard "(001.007S)" Standard ROM
*Font Helvetica-Narrow-Oblique: Standard "(001.006S)" Standard ROM
*Font Helvetica-Oblique: Standard "(001.006S)" Standard ROM
*Font NewCenturySchlbk-Bold: Standard "(001.009S)" Standard ROM
*Font NewCenturySchlbk-BoldItalic: Standard "(001.007S)" Standard ROM
*Font NewCenturySchlbk-Italic: Standard "(001.006S)" Standard ROM
*Font NewCenturySchlbk-Roman: Standard "(001.007S)" Standard ROM
*Font Palatino-Bold: Standard "(001.005S)" Standard ROM
*Font Palatino-BoldItalic: Standard "(001.005S)" Standard ROM
*Font Palatino-Italic: Standard "(001.005S)" Standard ROM
*Font Palatino-Roman: Standard "(001.005S)" Standard ROM
*Font Times-Bold: Standard "(001.007S)" Standard ROM
*Font Times-BoldItalic: Standard "(001.009S)" Standard ROM
*Font Times-Italic: Standard "(001.007S)" Standard ROM
*Font Times-Roman: Standard "(001.007S)" Standard ROM
*Font ZapfChancery-MediumItalic: Standard "(001.007S)" Standard ROM
*Font ZapfDingbats: Special "(001.004S)" Special ROM
*Font Symbol: Special "(001.007S)" Special ROM
*Font Alaska: Standard "(001.005)" Standard ROM
*Font AlaskaExtrabold: Standard "(001.005)" Standard ROM
*Font AntiqueOakland: Standard "(001.005)" Standard ROM
*Font AntiqueOakland-Bold: Standard "(001.005)" Standard ROM
*Font AntiqueOakland-Oblique: Standard "(001.005)" Standard ROM
*Font ClevelandCondensed: Standard "(001.005)" Standard ROM
*Font Connecticut: Standard "(001.005)" Standard ROM
*Font Guatemala-Antique: Standard "(001.005)" Standard ROM
*Font Guatemala-Bold: Standard "(001.005)" Standard ROM
*Font Guatemala-Italic: Standard "(001.005)" Standard ROM
*Font Guatemala-BoldItalic: Standard "(001.005)" Standard ROM

*Font LetterGothic: Standard "(001.005)" Standard ROM
*Font LetterGothic-Bold: Standard "(001.005)" Standard ROM
*Font LetterGothic-Oblique: Standard "(001.005)" Standard ROM
*Font Maryland: Standard "(001.005)" Standard ROM
*Font Oklahoma: Standard "(001.005)" Standard ROM
*Font Oklahoma-Bold: Standard "(001.005)" Standard ROM
*Font Oklahoma-Oblique: Standard "(001.005)" Standard ROM
*Font Oklahoma-BoldOblique: Standard "(001.005)" Standard ROM
*Font Utah: Standard "(001.005)" Standard ROM
*Font Utah-Bold: Standard "(001.005)" Standard ROM
*Font Utah-Oblique: Standard "(001.005)" Standard ROM
*Font Utah-BoldOblique: Standard "(001.005)" Standard ROM
*Font UtahCondensed: Standard "(001.005)" Standard ROM
*Font UtahCondensed-Bold: Standard "(001.005)" Standard ROM
*Font UtahCondensed-Oblique: Standard "(001.004)" Standard ROM
*Font UtahCondensed-BoldOblique: Standard "(001.005)" Standard ROM
*Font BermudaScript: Standard "(001.005)" Standard ROM
*Font Germany: Standard "(001.005)" Standard ROM
*Font SanDiego: Standard "(001.005)" Standard ROM
*Font US-Roman: Standard "(001.005)" Standard ROM


ENDOFPPDFILE

printer_model=""td2130n""
ldpwrapper=/opt/brother/${printer_model}/bin/cupswrapper/brother_${printer_model}
brotherlpdwrapper=/usr/lib/cups/filter/brother_td2130n
brotherlpdwrapper64=/usr/lib64/cups/filter/brother_td2130n
#brotherlpdwrapper=/usr/lib/cups/backend/brusb_td2130n
#brotherlpdwrapper64=/usr/lib64/cups/backend/brusb_td2130n

rm -f  $ldpwrapper
#echo 'rm -f /usr/lib/cups/filter/brlpdwrappertd2130n'


cat <<!ENDOFWFILTER! >$ldpwrapper
#! /bin/sh
#
# Brother Print filter  >>  /usr/lib/cups/backend/brusb_td2130n
# Copyright (C) 2005-2020 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
#

LOGFILE="/dev/null"
LOGLEVEL="1"
LOGCLEVEL="7"
DEBUG=0
NUPENABLE=1
LOG_LATESTONLY=1

touch /tmp/td2130n_latest_print_info
chmod 600 -R /tmp/td2130n_latest_print_info

errorcode=0

if [ \$DEBUG != 0 ]; then
    LOGFILE=/tmp/br_cupsfilter_debug_log
fi

PPDC=\`printenv | grep "PPD="\`
PPDC=\`echo \$PPDC | sed -e 's/PPD=//'\`

if [ "\$PPDC" = "" ]; then
    PPDC="/usr/share/cups/model/Brother/brother_td2130n_printer_en.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

cp  /opt/brother/td2130n/bin/inf/brtd2130nrc  /tmp/brtd2130nrc_\$$
chmod 777 -R /tmp/brtd2130nrc_\$$
export BRPRINTERRCFILE=/tmp/brtd2130nrc_\$$

INPUT_TEMP_PS=\`mktemp /tmp/br_input_ps.XXXXXX\`

nup="cat"
if [ "\`echo \$5 | grep 'Nup='\`" != '' ] && [ \$NUPENABLE != 0 ]; then

	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
	       cp \$6  \$INPUT_TEMP_PS
       else
	       cat    > \$INPUT_TEMP_PS
       fi
   fi
else
   if [ \$# -ge 7 ]; then
      cp \$6  \$INPUT_TEMP_PS
   else
      cat    > \$INPUT_TEMP_PS
   fi
fi
if [ -e "/opt/brother/td2130n/bin/lpd/filtertd2130n" ]; then
       :
else
    echo "ERROR: /opt/brother/td2130n/bin/lpd/filtertd2130n does not exist"   >>\$LOGFILE
    echo "ERROR: /opt/brother/td2130n/bin/lpd/filtertd2130n does not exist"   >> /tmp/td2130n_latest_print_info
    errorcode=30
    exit
fi

CUPSOPTION=\`echo "\$5 Copies=1" | sed -e 's/PageSize/media/' -e 's/BrMargin/Feed/' -e 's/BrCompress/Compress/' -e 's/BrCutAtEnd/CutAtEnd/' -e  's/BrTrimtape/Trimtape/' -e 's/BrRotate/RotatePrint/' -e 's/BrPeeler/Peeler/' -e 's/BrCutLabel/CutLabel/' -e 's/BrMirror/MirrorPrint/' -e 's/BrPriority/Priority/' -e 's/BrQuality/QUALITY/' -e 's/BrSpeed/SPEED/' -e 's/BrHalftonePattern/Halftone/' -e 's/BrErrorDiffusion/ERROR/' -e 's/BrBinary/BINARY/' -e 's/BrDither/DITHER/' -e 's/BrBrightness/Brightness/' -e 's/BrContrast/Contrast/' -e 's/multiple-document-handling/Collate/' -e 's/separate-documents-collated-copies/ON/' -e 's/separate-documents-uncollated-copies/OFF/'\`




BRURI=\`printenv | grep DEVICE_URI=\`
BRURI=\`echo \$BRURI | grep "brserial"\`
PORT="USB"
if [ "\$BRURI" != "" ]; then
	PORT="SERIAL"
fi

if [ -e "/opt/brother/td2130n/bin/cupswrapper/brcupsconfpt1" ]; then
  if [ \$DEBUG = 0 ]; then
     /opt/brother/td2130n/bin/cupswrapper/brcupsconfpt1  td2130n  \$PPDC 0 "\$CUPSOPTION" \$BRPRINTERRCFILE>> /dev/null
  else
     /opt/brother/td2130n/bin/cupswrapper/brcupsconfpt1  td2130n  \$PPDC \$LOGCLEVEL "\$CUPSOPTION" \$BRPRINTERRCFILE>>\$LOGFILE
  fi
fi

if [ \$DEBUG -lt 10 ]; then
    cat    \$INPUT_TEMP_PS | /opt/brother/td2130n/bin/lpd/filtertd2130n "\$\$" "CUPS" "\$PORT"
    echo brtd2130nrc_\$$   > /tmp/td2130n_latest_print_info
    cat  /tmp/brtd2130nrc_\$$  >> /tmp/td2130n_latest_print_info
    rm -f /tmp/brtd2130nrc_\$$
    if [ \$LOGLEVEL -gt 2 ];  then
	   if [ \$LOGFILE != "/dev/null" ]; then
	     echo ""                                                >>\$LOGFILE
	     echo "    ------PostScript Data-------"                >>\$LOGFILE
	     cat    \$INPUT_TEMP_PS                                  >>\$LOGFILE
	   fi
    fi
fi
rm -f  \$INPUT_TEMP_PS

exit $errorcode

!ENDOFWFILTER!

chmod 755 $ldpwrapper

if [ -d /usr/lib/cups/filter ]; then
	rm -f  $brotherlpdwrapper
	ln -s $ldpwrapper	$brotherlpdwrapper
fi

if [ -d /usr/lib64/cups/filter ]; then
	rm -f  $brotherlpdwrapper64
	ln -s $ldpwrapper	$brotherlpdwrapper64
fi

if [ -e /etc/init.d/lpd ]; then
   /etc/init.d/lpd stop
fi
if [  -e /etc/init.d/lprng ]; then
   /etc/init.d/lprng stop
fi


if [  -e /etc/init.d/cups ]; then
   /etc/init.d/cups restart
elif [  -e /etc/init.d/cupsys ]; then
   /etc/init.d/cupsys restart
fi


exit 0

