From 8d1d5ce4aadb043a2aefd74bb59821aa1f8b9105 Mon Sep 17 00:00:00 2001
From: Monkey 7 <monkeyseven@fblog.ch>
Date: Wed, 10 Jul 2019 07:08:21 +0200
Subject: [PATCH] New package: brother-hl5340d-cupswrapper-2.0.4

---
 srcpkgs/brother-hl5340d-cupswrapper/INSTALL   |   5 +
 srcpkgs/brother-hl5340d-cupswrapper/REMOVE    |   5 +
 .../patches/cupswrapperHL5340D.patch          | 125 ++++++++++++++++++
 srcpkgs/brother-hl5340d-cupswrapper/template  |  37 ++++++
 4 files changed, 172 insertions(+)
 create mode 100644 srcpkgs/brother-hl5340d-cupswrapper/INSTALL
 create mode 100644 srcpkgs/brother-hl5340d-cupswrapper/REMOVE
 create mode 100644 srcpkgs/brother-hl5340d-cupswrapper/patches/cupswrapperHL5340D.patch
 create mode 100644 srcpkgs/brother-hl5340d-cupswrapper/template

diff --git a/srcpkgs/brother-hl5340d-cupswrapper/INSTALL b/srcpkgs/brother-hl5340d-cupswrapper/INSTALL
new file mode 100644
index 00000000000..2825fd47a9f
--- /dev/null
+++ b/srcpkgs/brother-hl5340d-cupswrapper/INSTALL
@@ -0,0 +1,5 @@
+case "${ACTION}" in
+    post)
+        usr/lib/brother/cupswrapper/cupswrapperHL5340D-2.0.4 -i
+        ;;
+esac
diff --git a/srcpkgs/brother-hl5340d-cupswrapper/REMOVE b/srcpkgs/brother-hl5340d-cupswrapper/REMOVE
new file mode 100644
index 00000000000..0e84f1023ea
--- /dev/null
+++ b/srcpkgs/brother-hl5340d-cupswrapper/REMOVE
@@ -0,0 +1,5 @@
+case ${ACTION} in
+    pre) 
+        usr/lib/brother/cupswrapper/cupswrapperHL5340D-2.0.4 -e
+        ;;
+esac
diff --git a/srcpkgs/brother-hl5340d-cupswrapper/patches/cupswrapperHL5340D.patch b/srcpkgs/brother-hl5340d-cupswrapper/patches/cupswrapperHL5340D.patch
new file mode 100644
index 00000000000..73611570465
--- /dev/null
+++ b/srcpkgs/brother-hl5340d-cupswrapper/patches/cupswrapperHL5340D.patch
@@ -0,0 +1,125 @@
+diff -ur orig/usr/local/Brother/cupswrapper/cupswrapperHL5340D-2.0.4 new/usr/local/Brother/cupswrapper/cupswrapperHL5340D-2.0.4
+--- orig/usr/local/Brother/cupswrapper/cupswrapperHL5340D-2.0.4	2009-09-10 04:48:37.000000000 +0200
++++ new/usr/local/Brother/cupswrapper/cupswrapperHL5340D-2.0.4	2019-07-09 10:08:23.763781987 +0200
+@@ -22,8 +22,7 @@
+   lpadmin -x HL5340D
+   rm -f /usr/share/cups/model/HL5340D.ppd
+   rm -f /usr/lib/cups/filter/brlpdwrapperHL5340D
+-  rm -f /usr/lib64/cups/filter/brlpdwrapperHL5340D
+-  rm -f /usr/local/Brother/cupswrapper/brcupsconfig3
++  rm -f /usr/lib/brother/cupswrapper/brcupsconfig3
+   if [ -f /usr/share/ppd/HL5340D.ppd ];then
+   rm -f /usr/share/ppd/HL5340D.ppd
+   fi
+@@ -38,11 +37,14 @@
+ if [ "$1" = "-r" ]; then
+   lpadmin -x HL5340D
+   if [ -e /etc/init.d/cups ]; then
+-    /etc/init.d/cups restart
++    sv restart cupsd restart
+   fi
+   if [ -e /etc/init.d/cupsys ]; then
+     /etc/init.d/cupsys restart
+   fi
++  if [ -e /usr/bin/sv -a -e /var/service/cupsd/run ]; then
++    /usr/bin/sv restart cupsd
++  fi
+   exit 0 
+ fi
+ if [ "$1" = "help" ] || [ "$1" = "-h" ]; then
+@@ -54,15 +56,18 @@
+ fi
+ mkdir -p /usr/lib/cups/filter
+ 
+-if [ -e "/usr/local/Brother/lpd/filterHL5340D" ]; then
++if [ -e "/usr/lib/brother/lpd/filterHL5340D" ]; then
+   :
+ else
+   echo "ERROR : Brother LPD filter is not installed."
+ fi
+ rm -f /usr/share/cups/model/HL5340D.ppd
+ ppd_file_name=/usr/share/cups/model/HL5340D.ppd
++#if [ ! -e /usr/share/cups/model ]; then
++#   ppd_file_name=/usr/share/ppd/HL5340D.ppd
++#fi
+ if [ ! -e /usr/share/cups/model ]; then
+-   ppd_file_name=/usr/share/ppd/HL5340D.ppd
++  mkdir -p /usr/share/cups/model
+ fi
+ 
+ cat <<ENDOFPPDFILE >$ppd_file_name
+@@ -372,20 +377,14 @@
+ ENDOFPPDFILE
+ 
+ chmod 755  $ppd_file_name
+-if [ -e '/usr/share/ppd' ];then
+-  if [ -e '/usr/share/cups/model' ];then
+-    cp  $ppd_file_name  /usr/share/ppd
+-  fi
+-fi
++#if [ -e '/usr/share/ppd' ];then
++#  if [ -e '/usr/share/cups/model' ];then
++#    cp  $ppd_file_name  /usr/share/ppd
++#  fi
++#fi
+ 
+ brotherlpdwrapper=/usr/lib/cups/filter/brlpdwrapperHL5340D
+-brotherlpdwrapper64=/usr/lib64/cups/filter/brlpdwrapperHL5340D
+ rm -f  $brotherlpdwrapper
+-if [ ! -e /usr/lib/cups/filter ];then
+-  if [ -e /usr/lib64/cups/filter ];then
+-    brotherlpdwrapper=/usr/lib64/cups/filter/brlpdwrapperHL5340D
+-  fi
+-fi
+ 
+ 
+ cat <<!ENDOFWFILTER! >$brotherlpdwrapper
+@@ -517,25 +516,25 @@
+ fi
+ 
+ 
+-if [ -e "/usr/local/Brother/lpd/filter\$PRINTER" ]; then
++if [ -e "/usr/lib/brother/lpd/filter\$PRINTER" ]; then
+        :
+ else
+-    echo "ERROR: /usr/local/Brother/lpd/filter\$PRINTER does not exist"   >>\$LOGFILE
++    echo "ERROR: /usr/lib/brother/lpd/filter\$PRINTER does not exist"   >>\$LOGFILE
+     errorcode=30
+     exit $errorcode
+ fi
+ 
+-if [ -e "/usr/local/Brother/cupswrapper/brcupsconfig3" ]; then
++if [ -e "/usr/lib/brother/cupswrapper/brcupsconfig3" ]; then
+   if [ \$DEBUG = 0 ]; then
+-     /usr/local/Brother/cupswrapper/brcupsconfig3  \$PRINTER  \$PPD 0 "\$options" >> /dev/null
++     /usr/lib/brother/cupswrapper/brcupsconfig3  \$PRINTER  \$PPD 0 "\$options" >> /dev/null
+   else
+-     /usr/local/Brother/cupswrapper/brcupsconfig3  \$PRINTER  \$PPD \$LOGCLEVEL "\$options" >>\$LOGFILE
++     /usr/lib/brother/cupswrapper/brcupsconfig3  \$PRINTER  \$PPD \$LOGCLEVEL "\$options" >>\$LOGFILE
+   fi
+ fi
+ 
+ 
+ if [ \$DEBUG -le 2 ]; then
+-    cat    \$INPUT_TEMP_PS | /usr/local/Brother/lpd/filter\$PRINTER
++    cat    \$INPUT_TEMP_PS | /usr/lib/brother/lpd/filter\$PRINTER
+ fi
+ 
+ if [ \$DEBUG -ge 2 ];  then
+@@ -553,14 +552,9 @@
+ 
+ 
+ chmod 755 $brotherlpdwrapper
+-if [ -e /usr/lib/cups/filter ]; then
+- if [ -e /usr/lib64/cups/filter ]; then
+-   cp $brotherlpdwrapper  $brotherlpdwrapper64
+- fi
+-fi
+ 
+-chmod a+w /usr/local/Brother/inf/brHL5340Drc
+-chmod a+w /usr/local/Brother/inf
++chmod a+w /usr/lib/brother/inf/brHL5340Drc
++chmod a+w /usr/lib/brother/inf
+ if [ -e /etc/init.d/lpd ]; then
+    /etc/init.d/lpd stop
+ fi
diff --git a/srcpkgs/brother-hl5340d-cupswrapper/template b/srcpkgs/brother-hl5340d-cupswrapper/template
new file mode 100644
index 00000000000..65c97945ff3
--- /dev/null
+++ b/srcpkgs/brother-hl5340d-cupswrapper/template
@@ -0,0 +1,37 @@
+# Template file for 'brother-hl5340d-cupswrapper'
+pkgname=brother-hl5340d-cupswrapper
+_br_version=2.0.4
+_br_revision=1
+version=${_br_version}
+revision=1
+archs="i686 x86_64"
+create_wrksrc=yes
+depends="brother-hl5340d-lpr cups cups-filters"
+short_desc="CUPS wrapper driver for the brother HL5340D printer"
+maintainer="Monkey 7<monkeyseven@fblog.ch>"
+license="brother-eula GPL-2"
+homepage="http://support.brother.com"
+distfiles="http://www.brother.com/pub/bsc/linux/dlf/cupswrapperHL5340D-${version}-${_br_revision}.i386.deb
+	http://www.brother.com/pub/bsc/linux/dlf/BR5340_2_GPL.ppd.gz"
+checksum="a39c39e086904ec79d2ac0a9fe24bf2dd474ccd959adc11ad9d9b0b5d2649320
+ 	e8b8bb0688c2a181c9ebbb597ca7f467513262420bbf9a3c9bc1e2cf6e0bf9ee"
+nopie=yes
+patch_args="-Np1"
+
+do_extract() {
+	ar x ${XBPS_SRCDISTDIR}/${pkgname}-${version}/cupswrapperHL5340D-${version}-${_br_revision}.i386.deb
+	tar xzpvf data.tar.gz -C ${wrksrc}
+	# Brother HL-5340D BR-Script3
+	gunzip -c ${XBPS_SRCDISTDIR}/${pkgname}-${version}/BR5340_2_GPL.ppd.gz >${wrksrc}/BR5340_2_GPL.ppd
+}
+
+do_install() {
+	cp -a ${wrksrc}/usr ${DESTDIR}/
+	vmkdir usr/lib
+	mv ${DESTDIR}/usr/local/Brother ${DESTDIR}/usr/lib/brother
+	rm -rf ${DESTDIR}/usr/local
+	# Brother HL-5340D BR-Script3
+	vmkdir usr/share/cups/model
+	cp ${wrksrc}/BR5340_2_GPL.ppd ${DESTDIR}/usr/share/cups/model/BR5340_2_GPL.ppd
+}
+
