Skip to content

Commit

Permalink
dcp385c-cupswrapper: init at 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-serwin committed Dec 22, 2024
1 parent ca96b97 commit 37819cb
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkgs/by-name/dc/dcp385c-brprintconf/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
lib,
stdenv,
fetchFromSourcehut,
dcp385c-lpr,
}:
stdenv.mkDerivation {
pname = "dcp385c-brprintconf";
version = "1.1.2+1";

src = fetchFromSourcehut {
owner = "~marcin-serwin";
repo = "brprintconf";
rev = "6a1b9bf9de86ca15ca030a6a962ae5d9c2db8ad4";
hash = "sha256-hgVcFDAnHT3+0Yj276tcwD6xp8YNWN7S0WW8QGCy2hI=";
};

postPatch = ''
reldir='local/Brother/Printer/%s/inf'
substituteInPlace brprintconf_dcp385c.c \
--replace-fail "/usr/$reldir/br%sfunc" "${dcp385c-lpr}/$reldir/br%sfunc" \
--replace-fail "/usr/$reldir/br%src" "/var/cache/cups/br%src"
'';

installFlags = [ "PREFIX=$(out)" ];

meta = {
homepage = "https://git.sr.ht/~marcin-serwin/brprintconf";
description = "Decompiled source of brprintconf_dcp385c";
license = with lib.licenses; [
cc0
brotherEula
];
platforms = lib.platforms.linux;
};
}
70 changes: 70 additions & 0 deletions pkgs/by-name/dc/dcp385c-cupswrapper/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
stdenv,
lib,
fetchzip,
makeWrapper,
gnused,
gnugrep,
coreutils,
dcp385c-lpr,
dcp385c-brprintconf,
}:
let
version = "1.1.2";
model = "dcp385c";
installscript = "SCRIPT/cupswrapperdcp385c";
in
stdenv.mkDerivation {
pname = "${model}-cupswrapper";
inherit version;

src = fetchzip {
url = "https://download.brother.com/welcome/dlf006678/brcups_ink4_src_1.1.2-x.tar.gz";
hash = "sha256-2XzBF3weIlZ2g2IXFv2PE8jVXkhybrMni6jtNjkmF7I=";
};

nativeBuildInputs = [ makeWrapper ];
unpackPhase = ''
tar xzf $src/cupswrapperdcp385c_src-1.1.2-2.tar.gz
sourceRoot=cupswrapperdcp385c_src
'';

patchPhase = ''
patch ${installscript} ${./patch}
substituteInPlace ${installscript} \
--subst-var out \
--subst-var-by lpr ${dcp385c-lpr} \
'';

buildPhase = ''
$CC brcupsconfigpt1/brcupsconfig.c -o brcupsconfig
'';

installPhase = ''
install -D brcupsconfig $out/local/Brother/Printer/dcp385c/cupswrapper/brcupsconfpt1
mkdir -p $out/share/cups/model
mkdir -p $out/lib/cups/filter
sh ${installscript}
'';

fixupPhase = ''
wrapProgram $out/lib/cups/filter/brlpdwrapperdcp385c \
--prefix PATH ":" ${
lib.makeBinPath [
gnused
gnugrep
coreutils
dcp385c-brprintconf
]
}
'';

meta = {
homepage = "http://www.brother.com/";
description = "Brother ${model} printer CUPS wrapper driver";
license = lib.licenses.gpl2Plus;
platforms = lib.platforms.linux;
downloadPage = "https://support.brother.com/g/b/downloadlist.aspx?c=gb&lang=en&prod=${model}_all&os=128";
};
}
162 changes: 162 additions & 0 deletions pkgs/by-name/dc/dcp385c-cupswrapper/patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
--- cupswrapperdcp385c.orig 2008-11-18 10:31:13.000000000 +0100
+++ cupswrapperdcp385c 2024-06-22 21:09:26.993494135 +0200
@@ -25,11 +25,11 @@
device_model="Printer"
if [ "$1" = '-e' ]; then
lpadmin -x ${printer_name}
- rm -f /usr/share/cups/model/br${printer_model}.ppd
- rm -f /usr/share/ppd/br${printer_model}.ppd
- rm -f /usr/lib/cups/filter/brlpdwrapper${printer_model}
- rm -f /usr/lib64/cups/filter/brlpdwrapper${printer_model}
- rm -f /usr/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1
+ rm -f @lpr@/share/cups/model/br${printer_model}.ppd
+ rm -f @lpr@/share/ppd/br${printer_model}.ppd
+ rm -f @out@/lib/cups/filter/brlpdwrapper${printer_model}
+ rm -f @out@/lib64/cups/filter/brlpdwrapper${printer_model}
+ rm -f @out@/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1
if [ -e /etc/init.d/cups ]; then
/etc/init.d/cups restart
elif [ -e /etc/init.d/cupsys ]; then
@@ -55,21 +55,21 @@
echo ' -r : remove printer'
exit 0
fi
-#mkdir -p /usr/local/Brother/${device_model}/${printer_model}/filter
-#mkdir -p /usr/lib/cups/filter
+#mkdir -p @lpr@/local/Brother/${device_model}/${printer_model}/filter
+#mkdir -p @lpr@/lib/cups/filter

-if [ -e "/usr/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model}" ]; then
+if [ -e "@lpr@/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model}" ]; then
:
else
echo "ERROR : Brother LPD filter is not installed."
fi
-rm -f /usr/share/cups/model/br${printer_model}.ppd
-if [ -d "/usr/share/cups/model" ]; then
- ppd_file_name=/usr/share/cups/model/br${printer_model}.ppd
+rm -f @out@/share/cups/model/br${printer_model}.ppd
+if [ -d "@out@/share/cups/model" ]; then
+ ppd_file_name=@out@/share/cups/model/br${printer_model}.ppd
else
- ppd_file_name=/usr/share/ppd/br${printer_model}.ppd
+ ppd_file_name=@out@/share/ppd/br${printer_model}.ppd
fi
-#ppd_file_name=/usr/share/cups/model/br${printer_model}.ppd
+#ppd_file_name=@out@/share/cups/model/br${printer_model}.ppd

cat <<ENDOFPPDFILE1 >$ppd_file_name
*PPD-Adobe: "4.3"
@@ -699,27 +699,27 @@

chmod 644 $ppd_file_name

-if [ -d /usr/share/ppd ]
+if [ -d @out@/share/ppd ]
then
-if [ -d /usr/share/cups/model ]
+if [ -d @out@/share/cups/model ]
then
- cp $ppd_file_name /usr/share/ppd/br${printer_model}.ppd
- chmod 644 /usr/share/ppd/br${printer_model}.ppd
+ cp $ppd_file_name @out@/share/ppd/br${printer_model}.ppd
+ chmod 644 @out@/share/ppd/br${printer_model}.ppd
fi
fi

#################################################

-if [ -d /usr/lib/cups/filter ]
+if [ -d @out@/lib/cups/filter ]
then
- brotherlpdwrapper=/usr/lib/cups/filter/brlpdwrapper${printer_model}
+ brotherlpdwrapper=@out@/lib/cups/filter/brlpdwrapper${printer_model}
else
- brotherlpdwrapper=/usr/lib64/cups/filter/brlpdwrapper${printer_model}
+ brotherlpdwrapper=@out@/lib64/cups/filter/brlpdwrapper${printer_model}
fi


rm -f $brotherlpdwrapper
-#echo 'rm -f /usr/lib/cups/filter/brlpdwrapper${printer_model}'
+#echo 'rm -f @out@/lib/cups/filter/brlpdwrapper${printer_model}'


cat <<!ENDOFWFILTER! >$brotherlpdwrapper
@@ -759,7 +759,7 @@
PPDC=\`echo \$PPDC | sed -e 's/PPD=//'\`

if [ "\$PPDC" = "" ]; then
- PPDC="/usr/share/cups/model/br${printer_model}.ppd"
+ PPDC="@lpr@/share/cups/model/br${printer_model}.ppd"
fi


@@ -784,6 +784,10 @@
echo "PPD = \$PPD" >>\$LOGFILE
fi

+if ! [ -e /var/cache/cups/br${printer_model}rc ]; then
+ echo "creating rc file" >>\$LOGFILE
+ cp @lpr@/local/Brother/${device_model}/${printer_model}/inf/br${printer_model}rc /var/cache/cups/br${printer_model}rc
+fi
INPUT_TEMP_PS=\`mktemp /tmp/br_input_ps.XXXXXX\`

nup="cat"
@@ -809,7 +813,7 @@
nup="cat"
fi
echo "NUP=\$nup" >>\$LOGFILE
- if [ -e /usr/bin/psnup ]; then
+ if [ -e @lpr@/bin/psnup ]; then
if [ \$# -ge 7 ]; then
cat \$6 | \$nup > \$INPUT_TEMP_PS
else
@@ -829,25 +833,25 @@
cat > \$INPUT_TEMP_PS
fi
fi
-if [ -e "/usr/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model}" ]; then
+if [ -e "@lpr@/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model}" ]; then
:
else
- echo "ERROR: /usr/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model} does not exist" >>\$LOGFILE
+ echo "ERROR: @lpr@/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model} does not exist" >>\$LOGFILE
errorcode=30
exit
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 "/usr/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1" ]; then
+if [ -e "@out@/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1" ]; then
if [ \$DEBUG = 0 ]; then
- /usr/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1 ${printer_name} \$PPDC 0 "\$CUPSOPTION" "${printer_model}">> /dev/null
+ @out@/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1 ${printer_name} \$PPDC 0 "\$CUPSOPTION" "${printer_model}">> /dev/null
else
- /usr/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1 ${printer_name} \$PPDC \$LOGCLEVEL "\$CUPSOPTION" "${printer_model}">>\$LOGFILE
+ @out@/local/Brother/${device_model}/${printer_model}/cupswrapper/brcupsconfpt1 ${printer_name} \$PPDC \$LOGCLEVEL "\$CUPSOPTION" "${printer_model}">>\$LOGFILE
fi
fi

if [ \$DEBUG -lt 10 ]; then
- cat \$INPUT_TEMP_PS | /usr/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model} "\$\$" "CUPS" "USB"
+ cat \$INPUT_TEMP_PS | @lpr@/local/Brother/${device_model}/${printer_model}/lpd/filter${printer_model} "\$\$" "CUPS" "USB"

if [ \$LOGLEVEL -gt 2 ]; then
if [ \$LOGFILE != "/dev/null" ]; then
@@ -864,12 +868,12 @@
!ENDOFWFILTER!

chmod 755 $brotherlpdwrapper
-#if [ -e /usr/lib64/cups/backend ]; then
+#if [ -e @lpr@/lib64/cups/backend ]; then
# cp $brotherlpdwrapper $brotherlpdwrapper64
#fi

-chmod a+w /usr/local/Brother/${device_model}/${printer_model}/inf/br${printer_model}rc
-chmod a+w /usr/local/Brother/${device_model}/${printer_model}/inf
+chmod a+w @lpr@/local/Brother/${device_model}/${printer_model}/inf/br${printer_model}rc
+chmod a+w @lpr@/local/Brother/${device_model}/${printer_model}/inf
if [ -e /etc/init.d/lpd ]; then
/etc/init.d/lpd stop
fi
78 changes: 78 additions & 0 deletions pkgs/by-name/dc/dcp385c-lpr/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
lib,
stdenv,
fetchurl,
makeWrapper,
pkgsi686Linux,
ghostscript,
file,
a2ps,
which,
}:

let
version = "1.1.2";
model = "dcp385c";
in
stdenv.mkDerivation {
pname = "${model}-lpr";
inherit version;

src = fetchurl {
url = "https://download.brother.com/welcome/dlf005395/${model}lpr-${version}-2.i386.deb";
hash = "sha256-Y2lBU42fYXLG9D2qeUeG/sTpIIU8iHxyPALJUeZvHEk=";
};

nativeBuildInputs = [ makeWrapper ];

unpackPhase = ''
ar x $src
tar xvzf data.tar.gz
sourceRoot=usr
'';

patchPhase = ''
substituteInPlace local/Brother/Printer/dcp385c/lpd/filterdcp385c \
--replace-fail /usr $out \
--replace-fail '$BR_PRT_PATH/inf/brPRINTERrc' '/var/cache/cups/brPRINTERrc'
'';

installPhase = ''
cp -r . $out
'';

fixupPhase = ''
wrapProgram $out/local/Brother/Printer/dcp385c/lpd/filterdcp385c \
--prefix PATH ":" ${
lib.makeBinPath [
file
a2ps
]
}
wrapProgram $out/local/Brother/Printer/dcp385c/lpd/psconvertij2 \
--prefix PATH ":" ${
lib.makeBinPath [
which
ghostscript
]
}
interpreter="${pkgsi686Linux.glibc.out}/lib/ld-linux.so.2"
patchelf --set-interpreter $interpreter \
$out/bin/brprintconf_dcp385c
patchelf --set-interpreter $interpreter \
$out/local/Brother/Printer/dcp385c/lpd/brdcp385cfilter
'';

meta = {
homepage = "http://www.brother.com/";
description = "Brother ${model} printer driver";
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
license = lib.licenses.brotherEula;
platforms = lib.platforms.linux;
downloadPage = "https://support.brother.com/g/b/downloadlist.aspx?c=gb&lang=en&prod=${model}_all&os=128";
};
}

0 comments on commit 37819cb

Please sign in to comment.