lol
1{ lib
2, stdenv
3, fetchurl
4, dpkg
5, makeWrapper
6, coreutils
7, gnugrep
8, gnused
9, mfc9140cdnlpr
10, pkgsi686Linux
11, psutils
12}:
13
14stdenv.mkDerivation rec {
15 pname = "mfc9140cdncupswrapper";
16 version = "1.1.4-0";
17
18 src = fetchurl {
19 url = "https://download.brother.com/welcome/dlf100407/${pname}-${version}.i386.deb";
20 sha256 = "18aramgqgra1shdhsa75i0090hk9i267gvabildwsk52kq2b96c6";
21 };
22
23 unpackPhase = ''
24 dpkg-deb -x $src $out
25 '';
26
27 nativeBuildInputs = [
28 dpkg
29 makeWrapper
30 ];
31
32 dontBuild = true;
33
34 installPhase = ''
35 lpr=${mfc9140cdnlpr}/opt/brother/Printers/mfc9140cdn
36 dir=$out/opt/brother/Printers/mfc9140cdn
37
38 interpreter=${pkgsi686Linux.glibc.out}/lib/ld-linux.so.2
39 patchelf --set-interpreter "$interpreter" "$dir/cupswrapper/brcupsconfpt1"
40
41 substituteInPlace $dir/cupswrapper/cupswrappermfc9140cdn \
42 --replace "mkdir -p /usr" ": # mkdir -p /usr" \
43 --replace '/opt/brother/''${device_model}/''${printer_model}/lpd/filter''${printer_model}' "$lpr/lpd/filtermfc9140cdn" \
44 --replace '/usr/share/ppd/Brother/brother_''${printer_model}_printer_en.ppd' "$dir/cupswrapper/brother_mfc9140cdn_printer_en.ppd" \
45 --replace '/usr/share/cups/model/Brother/brother_''${printer_model}_printer_en.ppd' "$dir/cupswrapper/brother_mfc9140cdn_printer_en.ppd" \
46 --replace '/opt/brother/Printers/''${printer_model}/' "$lpr/" \
47 --replace 'nup="psnup' "nup=\"${psutils}/bin/psnup" \
48 --replace '/usr/bin/psnup' "${psutils}/bin/psnup"
49
50 mkdir -p $out/lib/cups/filter
51 mkdir -p $out/share/cups/model
52
53 ln $dir/cupswrapper/cupswrappermfc9140cdn $out/lib/cups/filter
54 ln $dir/cupswrapper/brother_mfc9140cdn_printer_en.ppd $out/share/cups/model
55
56 sed -n '/!ENDOFWFILTER!/,/!ENDOFWFILTER!/p' "$dir/cupswrapper/cupswrappermfc9140cdn" | sed '1 br; b; :r s/.*/printer_model=mfc9140cdn; cat <<!ENDOFWFILTER!/' | bash > $out/lib/cups/filter/brother_lpdwrapper_mfc9140cdn
57 sed -i "/#! \/bin\/sh/a PATH=${lib.makeBinPath [ coreutils gnused gnugrep ]}:\$PATH" $out/lib/cups/filter/brother_lpdwrapper_mfc9140cdn
58 chmod +x $out/lib/cups/filter/brother_lpdwrapper_mfc9140cdn
59 '';
60
61 meta = with lib; {
62 description = "Brother MFC-9140CDN CUPS wrapper driver";
63 homepage = "http://www.brother.com/";
64 license = licenses.gpl2Plus;
65 platforms = platforms.linux;
66 maintainers = with maintainers; [ hexa ];
67 };
68}