-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·157 lines (125 loc) · 4.21 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# 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.
model=$1
if [[ -z $model ]]; then
echo "Usage: $0 printer_model"
echo
echo "The printer model has to be specified without dashes."
echo "Example: $0 dcp9020cdw"
echo
echo "Installs Brother MFC/DCP drivers in a sane way. Unlike the vendor"
echo "installer, this does not make mess out of your system. Everything"
echo "is kept under /opt/brother, system configuration is not touched."
echo "A few symlinks are added to cups directories under /usr, their"
echo "full list is output at the end."
echo
echo "This script assumes x86_64. It should be reasonably distro neutral."
echo "Note that some of the binaries are 32bit. You're responsible for"
echo "installing 32bit versions of glibc and libstdc++."
echo
echo "On Debian, these would be: libstdc++6:i386 libgcc1:i386"
echo " (you'll need: dpkg --add-architecture i386 ; apt-get update)"
echo "On older Debian: ia32-libs lib32stdc++6"
echo "On Fedora: glibc.i686 libstdc++.i686"
exit 0
fi
tmpd=$(mktemp -d)
trap 'cd / ; rm -rf $tmpd' EXIT
# First, download the list of packages from Brother server.
curl -sL http://www.brother.com/pub/bsc/linux/infs/${1^^} -o $tmpd/inf || exit 1
pkg1=$(sed -n 's/^PRN_CUP_DEB=\(.*\)$/\1/p' $tmpd/inf)
pkg2=$(sed -n 's/^PRN_LPD_DEB=\(.*\)$/\1/p' $tmpd/inf)
if [[ -z $pkg1 ]]; then
echo "Your printer model was not found."
echo "Try models with a different suffix or other similar models."
exit 1
fi
# Copy our files to the temp location.
cp brother_lpdwrapper* $tmpd/
# Download and extract the packages.
function download_and_extract()
{
curl -sL http://www.brother.com/pub/bsc/linux/packages/$1 -o $1
mkdir unpack
cd unpack
ar x ../$1
cd ../tree
tar -x --no-same-owner --no-same-permissions -f ../unpack/data.tar.*
cd ..
rm -rf unpack
}
cd $tmpd
mkdir tree
echo "Downloading and extracting packages."
download_and_extract $pkg1
download_and_extract $pkg2
# Find the expected name of the printer (lower case vs. upper case).
if [[ ! -d tree/opt/brother/Printers/$model ]]; then
model=${model^^}
if [[ ! -d tree/opt/brother/Printers/$model ]]; then
echo "Could not find the expected files in the downloaded packages." >&2
exit 1
fi
fi
# Detect where the libraries should be.
function find_first_cups()
{
while [[ -n $1 ]]; do
[[ -d $1 ]] && { echo "$1"; return 0; }
shift
done
echo "Could not find cups libraries." >&2
return 1
}
libpath=$(find_first_cups /usr/lib64/cups/filter /usr/lib/cups/filter /usr/libexec/cups/filter) || exit 1
# Move stuff to opt...
cd tree
[[ -d usr/bin ]] && mv usr/bin opt/brother/Printers/$model/
# ...find and process the right lpdwrapper...
wrapper_path=opt/brother/Printers/$model/cupswrapper
function find_wrapper()
{
while [[ -n $1 ]]; do
name=${1##*/brother_lpdwrapper_}
[[ -f $wrapper_path/brcupsconf$name ]] && { echo $1; return 0; }
shift
done
echo "Could not find a supported cupswrapper." >&2
return 1
}
wrapper=$(find_wrapper $tmpd/brother_lpdwrapper_*) || exit 1
wrapper_dest=opt/brother/Printers/$model/brother_lpdwrapper_$model
sed "s/@@MODEL@@/$model/g" $wrapper > $wrapper_dest
chmod 755 $wrapper_dest
# ...find the ppd name...
ppd=
for f in opt/brother/Printers/$model/cupswrapper/brother?${model}*; do
[[ -e $f ]] || break
if [[ -n $ppd ]]; then
echo "Error: multiple ppd files found:" >&2
cd opt/brother/Printers/$model/cupswrapper/
ls brother_${model}* >&2
exit 1
fi
ppd=$f
done
if [[ -z $ppd ]]; then
echo "Error: no ppd file found in the downloaded packages." >&2
exit 1
fi
ppd=${ppd##*/}
# ...and move the files to the live system.
mkdir -p /opt/brother/Printers || exit 1
mv opt/brother/Printers/$model /opt/brother/Printers/ || exit 1
cd ..
# Create the needed symlinks.
mkdir -p /usr/share/cups/model/Brother
ln -s /opt/brother/Printers/$model/cupswrapper/$ppd /usr/share/cups/model/Brother/${model}.ppd
ln -s /opt/brother/Printers/$model/brother_lpdwrapper_$model $libpath/
# Echo the symlinks.
echo "Symlinks created:"
echo /usr/share/cups/model/Brother/${model}.ppd
echo $libpath/brother_lpdwrapper_$model