diff options
Diffstat (limited to 'PKGBUILD')
-rw-r--r-- | PKGBUILD | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..c03cff61f1e7 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,330 @@ +# Maintainer: Chris Severance aur.severach aATt spamgourmet dott com + +_brinf=( +[MFC-J895DW] +PRN_CUP_RPM= +PRN_CUP_DEB= +PRN_LPD_RPM= +PRN_LPD_DEB= +PRN_DRV_RPM=mfcj895dwpdrv-1.0.5-0.i386.rpm +PRN_DRV_DEB=mfcj895dwpdrv-1.0.5-0.i386.deb +REQUIRE32LIB=yes +PRINTERNAME=MFCJ895DW +SCANNER_DRV=brscan4 +SCANKEY_DRV=brscan-skey +) + +_opt_DEB=0 + +set -u +_brotheru='MFC-J895DW' +_brotherl="${_brotheru,,}" # mfc-0000dw +_brotherlnd="${_brotherl//-/}" # mfc0000dw +_brotherund="${_brotheru//-/}" # MFC0000DW +_brotherxnd="${_brotherlnd}" # upper or lower as required by scripts +pkgname="brother-${_brotherl}" +pkgver='1.0.5_0' +pkgrel='1' +pkgdesc="LPR and CUPS driver for the Brother ${_brotheru} printer" +arch=('i686' 'x86_64') +url='https://support.brother.com/g/s/id/linux/en/' +license=('GPL' 'custom') +depends=('cups' 'ghostscript' 'sed' 'grep') +# We look at the scripts and find these programs from which we decide on the depends above. +# gs: lpr rendering +# pdf2ps: cups rendering +# (no) a2ps: rendering ascii text files +# (no) pstops: pdf resizing +# (no) psnup: printing n-up pages +# sed grep awk +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=670055 +# Printing a text file fails when Liberation is the only TrueType font available +depends+=('perl') # cupswrapper +optdepends=( + 'ttf-dejavu: printing text files from lpr' +) +options=('!strip') +#install="${pkgname}.install" +_dlf='http://www.brother.com/pub/bsc/linux' +_inf="${_brotherlnd}-${pkgver}.inf" +source=( + 'cupswrapper-license.txt' + "${_inf}::${_dlf}/infs/${_brotherund}" + 'lpr-license.txt' +) +md5sums=('97ad0cffd216059e9d1d3121899d8646' + 'b1360fb8143d0d8d3c6a6ddf9e45c262' + '5e87a3dc0f3e3438c088eda0f3565f0d' + 'c8eefd35715e7fc58ee0096fbeef723e') +sha256sums=('2c6aa6a641332e5c87e971ac2a8beae13b059747bdba331bbd515914770d72d9' + 'ca4385a1b6ba11440466e6fad2bbf4296dedbd179c9e9770f3e69ab1ae2e5f30' + '9d85a8aafdaac8fac80e04234ad2acf5642bbf0b91ee582d2a89519a55f6dd67' + '5981ebb6905dc1b546a635218f952bc5f6b47a888cc1282e721595fd77efb193') + +_mismatch=0 +_brverchk() { + local _ver="$1" + _ver="${_ver%.*}" + _ver="${_ver%.*}" + local _vb="${_ver%-*}" + _vb="${_vb%-*}-" + _ver="${_ver#${_vb}}" + local _pv="$2" + if [ -z "${_pv}" ]; then + _pv="$3" + fi + if [ -z "${_pv}" ]; then + _pv="$4" + fi + if [ "${_ver}" != "${_pv//_/-}" ]; then + echo "Version mismatch: ${_ver} ${_pv//_/-}" 1>&2 + _mismatch=$((_mismatch+1)) + fi +} + +_procinf() { + local _fd _fvar _fval + for _fd in "${_brinf[@]}"; do + _fvar="${_fd%%=*}=" + _fval="${_fd##*=}" + if [ ! -z "${_fval}" ]; then + case "${_fvar}" in + '['*);; + PRN_CUP_RPM=) + _brverchk "${_fval}" "${_cuprpmver:-}" "${_cupver:-}" "${pkgver}" + if [ "${_opt_DEB}" -eq 0 ]; then + source+=("${_dlf}/packages/${_fval}") + fi + ;; + PRN_CUP_DEB=) + _brverchk "${_fval}" "${_cupdebver:-}" "${_cupver:-}" "${pkgver}" + if [ "${_opt_DEB}" -ne 0 ]; then + source+=("${_dlf}/packages/${_fval}") + fi + ;; + PRN_LPD_RPM=) + _brverchk "${_fval}" "${_lprrpmver:-}" "${_lprver:-}" "${pkgver}" + if [ "${_opt_DEB}" -eq 0 ]; then + source+=("${_dlf}/packages/${_fval}") + fi + ;; + PRN_LPD_DEB=) + _brverchk "${_fval}" "${_lprdebver:-}" "${_lprver:-}" "${pkgver}" + if [ "${_opt_DEB}" -ne 0 ]; then + source+=("${_dlf}/packages/${_fval}") + fi + ;; + PRN_DRV_RPM=) + _brverchk "${_fval}" "" "" "${pkgver}" + if [ "${_opt_DEB}" -eq 0 ]; then + source+=("${_dlf}/packages/${_fval}") + fi + ;; + PRN_DRV_DEB=) + _brverchk "${_fval}" "" "" "${pkgver}" + if [ "${_opt_DEB}" -ne 0 ]; then + source+=("${_dlf}/packages/${_fval}") + fi + ;; + REQUIRE32LIB=) + if [ "${_fval}" = 'yes' ]; then + depends_x86_64+=('lib32-glibc') + fi + ;; + PRINTERNAME=);; + SCANNER_DRV=)optdepends+=("${_fval}: Scanner support");; + SCANKEY_DRV=)optdepends+=("${_fval}: Scanner button support");; + *) echo "Unrecognized line: ${_fd}" 1>&2; exit 1;; + esac + fi + done + test "${_mismatch}" -eq 0 || exit 1 +} +_procinf +unset -f _procinf _brverchk +unset _mismatch _brinf + +# Must be same length as +# 'Brother' +_conflict='brother' + +prepare() { + set -u + + shopt -s nullglob + local _deb + local _debn=1 + for _deb in *.deb; do + local _dx="debextract.${_debn}" + mkdir "${_dx}" + bsdtar -C "${_dx}" -xf "${_deb}" + bsdtar -C "${_dx}" -xf "${_dx}"/control.tar.?z + bsdtar -xf "${_dx}"/data.tar.?z + rm "${_dx}"/*.tar.?z + _debn=$((_debn+1)) + done + shopt -u nullglob + + # Do not Install in '/usr/local'. Does not apply to all Brother models. + # This may modify binary blobs which only + # works when the old and new strings are exactly the same length. + if [ -d 'usr/local' ]; then + install -d 'usr/share' + mv 'usr/local/Brother' "usr/share/${_conflict}" + rmdir 'usr/local' + sed -e "s:/usr/local/Brother:/usr/share/${_conflict}:g" -i $(grep -lare '/usr/local/Brother' ./) + fi + + # setup cups-directories, some installers create these for us + install -d 'usr/lib/cups/filter' + install -d 'usr/share/cups/model' + #install -d 'usr/share/ppd' # For cups we don't need the ppd file here. + + # /etc/printcap is managed by cups + find . -type 'f' -name 'setupPrintcap*' -delete + + set +u +} + +build() { + set -u + + local _basedir="opt/brother/Printers/${_brotherxnd}" + #local _basedir="usr/share/${_conflict}" + #local _basedir="usr/share/${_conflict}/Printer/${_brotherxnd}" + shopt -s nullglob + local _wrapper_source=("${_basedir}/cupswrapper/cupswrapper${_brotherxnd}"*) + shopt -u nullglob + test "${#_wrapper_source[@]}" -eq 1 || echo "${}" + _wrapper_source="${_wrapper_source[0]}" + test -x "${_wrapper_source}" || echo "${}" + echo "Wrapper source: ${_wrapper_source}" + + # Some Brother installers create files here + mkdir -p 'var/tmp' + + # This generated wrapper isn't used. We just want to run the install commands. + + # Modify the installer so we can finish the install here in PKGBUILD. + #cp -p "${_wrapper_source}" "${_wrapper_source}.Arch" # debug: diff compare with Total Commander + sed -e '# Install to _srcdir. Some folders may not apply to this model.' \ + -e '# quick fix for path that needs to be double quoted' \ + -e "s:'/usr/share/ppd':"'"/usr/share/ppd":g' \ + -e 's:/usr:"${_srcdir}"&:g' \ + -e 's:/opt:"${_srcdir}"&:g' \ + -e 's:/var:"${_srcdir}"&:g' \ + -e 's:/etc:"${_srcdir}"&:g' \ + -e '# Remove unwanted srcdir from the generated files' \ + -e '/^cat <<ENDOFPPDFILE/,/^ENDOFPPDFILE/ s:"${_srcdir}"::g' \ + -e '/^cat <<!ENDOFWFILTER/,/^!ENDOFWFILTER!/ s:"${_srcdir}"::g' \ + -e '# Remove extra quotes where path was already quoted' \ + -e 's:""\${_srcdir}":"${_srcdir}:g' \ + -e '#s:/model/Brother:/model:g' \ + -e "# Stop the Install script after the files are generated. cups doesn't require a reload to see the printer driver." \ + -e 's:^sleep.*$:exit 0 # & #Arch Linux Compatible:g' \ + -e '# not using set -u allows bugs like this to slip by' \ + -e '#/Nup=/ s:`:\\`:g' \ + -e '# Fix a forgotten escape script error' \ + -e 's: \$errorcode: \\$errorcode:g' \ + -e '# Fix symlinks' \ + -e 's:^ldpwrapper="\${_srcdir}":ldpwrapper=:g' \ + -i "${_wrapper_source}" + grep -lqe '#Arch Linux Compatible$' "${_wrapper_source}" || echo "${}" + test -f "${_wrapper_source}.Arch" && echo "${}" # Halt for debugging + # Generate PPD and wrapper. Use sh -x to debug + # Possible bug: copying to /usr/share/ppd is disabled. + _srcdir="${srcdir}" \ + sh -u -e "${_wrapper_source}" -i + local _ppdir='usr/share/cups/model/Brother' + chmod 644 "${_ppdir}"/*.ppd # Some installers make ppd executable + rm -rf 'var' + + local _wrapgen="${_basedir}/cupswrapper/brother_lpdwrapper_${_brotherxnd}" + #local _wrapgen="usr/lib/cups/filter/brlpdwrapper${_brotherxnd}" + #local _wrapgen="usr/lib/cups/filter/brother_lpdwrapper_${_brotherxnd}" + test -s "${_wrapgen}" || echo "${}" + + # Ensure all paths were removed + grep -qFe $'${_srcdir}\n'"${srcdir}" "${_wrapgen}" && echo "${}" + + # We did everything in the installer so we can get rid of it. + rm "${_wrapper_source}" + + # Misnamed printer does not sort or autodetect properly + #sed -e "s:Brother ${_brotherund} :Brother ${_brotheru} :g" -i "${_ppdir}"/*.ppd + + # Check to see if the lpd wrapper is referenced by the ppd + # Check to see if our compiled code is referenced by the lpd wrapper + local _nppdfound=0 + #local _ncodefound=0 + #local _lwrapper + for _lwrapper in 'usr/lib/cups/filter'/*; do + if grep -q "$(basename "${_lwrapper}")" "${_ppdir}"/*.ppd; then + _nppdfound=$((_nppdfound+1)) + fi + #if grep -q "${_brcupsconf##*/}" "${_lwrapper}"; then + # _ncodefound=$((_ncodefound+1)) + #fi + done + test "${_nppdfound}" -ne 0 || echo "${}" + #test "${_ncodefound}" -ne 0 || echo "${}" + + set +u +} + +makedepends=('patchelf') +_fn_libconflict() { + # Change lib name to prevent conflicts with other printers that use the same one + local _f1='libbrcompij2' + local _f2="${_f1}-${_brotherlnd}" + local _fp='' # blank enables name change, pound sign # disables + + # Execute ln soname commands from postin + if [ "${_opt_DEB}" -ne 0 ]; then + local _postin='debextract.2/postinst' + else + local _postin="${source[1]##*/}" + fi + + grep -ae '^ln -s' "${_postin}" | \ + sed -e 's:/usr/lib/::' \ + -e "s:/usr/lib/:${pkgdir}&:g" \ + -e '# Prevent lib conflicts with similar printers' \ + -e "${_fp}s:${_f1}:${_f2}:g" \ + | bash -e -u -- + + if [ -z "${_fp}" ]; then + mv "${pkgdir}/usr/lib/${_f1}.so.1.0.2" "${pkgdir}/usr/lib/${_f2}.so.1.0.2" + grep -aqFe "${_f1}.so.1" "${pkgdir}/usr/share/${_conflict}/lpd/rastertobrij2" || echo "${}" + patchelf --replace-needed "${_f1}.so.1" "${_f2}.so.1" "${pkgdir}/usr/share/${_conflict}/lpd/rastertobrij2" + patchelf --set-soname "${_f2}.so.1" "${pkgdir}/usr/lib/${_f2}.so.1.0.2" + fi +} + +package() { + set -u + + local _dir + # /var/spool is not used anywhere in this package. Maybe it's needed for non cups lprng. + for _dir in 'usr' 'opt'; do # 'var' + if [ -d "${srcdir}/${_dir}" ]; then + cp -pR "${srcdir}/${_dir}" "${pkgdir}" + fi + done + + if [ "${_conflict}" != 'brother' ]; then + _fn_libconflict + fi + + # Ensure we got a ppd and a filter for CUPS + test ! -z "$(find "${pkgdir}/usr/share/cups/model" -type 'f' -name '*.ppd')" || echo "${}" + test ! -z "$(find "${pkgdir}/usr/lib/cups/filter/" '(' -type 'f' -o -type 'l' ')')" || echo "${}" + + # Ensure there are no forbidden paths + ! grep -alqr "/sbin" "${pkgdir}" || echo "${}" + ! grep -alqr "/usr/tmp" "${pkgdir}" || echo "${}" + + install -Dpm644 'cupswrapper-license.txt' 'lpr-license.txt' -t "${pkgdir}/usr/share/licenses/${pkgname}/" + set +u +} +set +u |