stefan-langenmaier / brother-overlay

Portage overlay for Brother printer and scanner software
GNU General Public License v3.0
34 stars 41 forks source link

ebuild for brother dcp-j4120dw #46

Closed hjudt closed 3 years ago

hjudt commented 6 years ago

I am looking for an ebuild for my dcp-j4120dw printer but couldn't find any. Any idea which ebuild from the overlay I should take as template to write one?

Printer driver download is here: http://support.brother.com/g/b/downloadlist.aspx?c=eu_ot&lang=en&prod=dcpj4120dw_eu_as&os=127

The scanner works great with the bscan4 driver.

stefan-langenmaier commented 6 years ago

Sorry it took me so long to reply, I'm not really sure if there is a similar ebuild.

Maybe have a look at the simpler ebuilds first: https://github.com/stefan-langenmaier/brother-overlay/blob/6b8a9c1d136b9adb402f390d0de7e18480792459/net-print/brother-mfc9340cdw-bin/brother-mfc9340cdw-bin-1.1.2.ebuild

But there are also more complex ones: https://github.com/stefan-langenmaier/brother-overlay/blob/b14dc2de8ad85aa12744eaf5af012a31e98acbb4/net-print/brother-mfcj880dw-bin/brother-mfcj880dw-bin-1.0.0-r0.ebuild

hjudt commented 6 years ago

Thank you for your answer. With the ebuilds for the other models you provided I could finally get my printer going. During my earlier attempts, I missed that there is a cupswrapper source code for my printer and tried to install the cupswrapper rpm from the support site. This did not work, failing with some error in cups about opening a file. Now I have successfully modified the mfcj880dw ebuild. I will attach it here. `# Copyright 1999-2017 Gentoo Foundation

Distributed under the terms of the GNU General Public License v2

$Id$

EAPI=6

inherit eutils rpm multilib linux-info

MODEL="dcpj4120dw" BR_PR=${PR/r/}

DESCRIPTION="Brother printer driver for DCP-J4120DW" HOMEPAGE="http://support.brother.com" SRC_URI="http://www.brother.com/pub/bsc/linux/dlf/${MODEL}lpr-${PV}-${BR_PR}.i386.rpm http://download.brother.com/welcome/dlf101559/brother_${MODEL}_GPL_source_${PV}-${BR_PR}.tar.gz"

LICENSE="GPL-2+ brother-eula no-source-code" SLOT="0" KEYWORDS="amd64 x86" IUSE="+metric -debug" RESTRICT="mirror strip"

DEPEND="net-print/cups" RDEPEND="${DEPEND} app-text/a2ps"

DEST="/opt/brother/Printers/${MODEL}" S="${WORKDIR}${DEST}"

src_prepare() { eapply_user

if use metric; then
    sed -i '/^PaperType/s/Letter/A4/' inf/br${MODEL}rc || die
fi

mv "${WORKDIR}/brother_${MODEL}_GPL_source_${PV}-${BR_PR}/" "${S}/cupswrapper-src/" || die

# Extract the needed bundled lpdwrapper script from within brothers generate script.
# Our needed script is located between tags.
cd "cupswrapper-src" || die
local TAG="\!ENDOFWFILTER\!"
sed -ne "/${TAG}/,/${TAG}/!d" -e "/${TAG}/d; p" < cupswrapper/cupswrapper${MODEL} > brother_lpdwrapper_${MODEL} || die

# exchange the vars in the script with the values of our ones and
# remove masking backslashes and some other stuff
local PRINTER_NAME="${MODEL^^}"
sed -i -e "s|\${printer_model}|${MODEL}|g;s|\${device_model}|Printers|g;s|\${printer_name}|${PRINTER_NAME}|g;s|exit \$errorcode|exit|" \
    -e 's|\\\([\$\`]\)|\1|g' brother_lpdwrapper_${MODEL} || die

if use debug; then
    sed -i '/^DEBUG=/s/.$/1/' brother_lpdwrapper_${MODEL} || die
fi

}

src_compile() { cd cupswrapper-src/brcupsconfig || die emake brcupsconfig }

src_install() { has_multilib_profile && ABI=x86

cd cupswrapper-src || die
exeinto /usr/libexec/cups/filter
doexe brother_lpdwrapper_${MODEL}

cd brcupsconfig || die
exeinto ${DEST}/cupswrapper
doexe brcupsconfig

cd ../ppd || die
insinto ${DEST}/cupswrapper
doins brother_${MODEL}_printer_en.ppd
insinto /usr/share/cups/model/Brother
doins brother_${MODEL}_printer_en.ppd
insinto /usr/share/ppd/Brother
doins brother_${MODEL}_printer_en.ppd

# proprietary binary included, no source available
cd ../../lpd || die
exeinto ${DEST}/lpd
doexe br${MODEL}filter filter${MODEL} psconvertij2

cd ../inf || die
insinto ${DEST}/inf
doins br${MODEL}rc br${MODEL}func ImagingArea PaperDimension paperinfij2
doins -r lut

# proprietary binary, no source available
cd "${WORKDIR}/usr/bin" || die
into /usr
dobin brprintconf_${MODEL}

}

pkgpostinst () { ewarn "Because /usr/bin/brprintconf${MODEL} uses /var/tmp to create a simple temp file on printing, make sure the directory has enough rights (eg. 1777)" ewarn "or you won't be able to change print options on printing and therefore you always have to edit /opt/brother/Printers/inf/br${MODEL}rc, manually!" } `

hjudt commented 6 years ago

It seems github messes up the code in the comment. Here is a pastebin.com link: https://pastebin.com/cUEJ7y3N

Note that a2ps might not really be needed, I will still have to test this. IIRC, it is somewhere referenced in a bash script, though.

stefan-langenmaier commented 6 years ago

Thanks for your work! Do you think you can add it in form of a pull request? If not I'll add it next week.

hjudt commented 6 years ago

I will test it again for the requirement of the a2ps dependency and then create a pull request in 2018.

ghost commented 6 years ago

If you use my ebuild, so please leave the comment about the original base/author.

hjudt commented 6 years ago

Pull request sent.

hjudt commented 6 years ago

There is still one problem with this ebuild: Despite setting proper permissions on /var/tmp (the message in the ebuild is a bit vague on what is considered to be proper permissions), changing settings doesn't have any effect. Editing the rc directly helps. I will have to retest this to find out which permissions are needed.

ghost commented 6 years ago

I run into this with the underlying j880dw. If /var/tmp has no write permission for the printing process, then changes on the print settings of the document to print, will have no effect. So you can test which permissions and groups will work for you, but 1777 is working at least for all. But working doesn't mean the same as security.

The odd thing is, that the printing binary from brother is creating a single temp file on exactly that place, containing the printer setting changes, I figured out. So if it cannot write in that dir, no changes will be made to the settings. Sorry, if my comments aren't clear enough. Feel free to edit at your own.

Regards Chris Morgenstern

ghost commented 6 years ago

Maybe your printer uses another way or directory on printing. Enabling debug use flag, which keeps the logs in /tmp ( at least on j880dw) or modifying the printers source scripts might help.

hjudt commented 3 years ago

I have now further investigated on this and fixed it. The problem here is not with permissions, but that the default (provided) cups config binary is called brcupsconfpt1, while our self-compiled binary is called brcupsconfig. Unfortunately, this is not changed in the generated lpd wrapper script, so I have now added an additional sed command to do this (one could actually also rename the binary, but it has a nicer name). I will push a PR for this.

hjudt commented 3 years ago

https://github.com/stefan-langenmaier/brother-overlay/pull/101

stefan-langenmaier commented 3 years ago

Nice detective work. :) I will close this.