#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer		: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=brscan4
pkgver=0.4.11_1
pkgrel=01
pkgdesc="SANE drivers from Brother for compatible models"
depends=('sane' 'gtk2')
arch=('x86_64')
_url="https://support.brother.com"
url="https://download.brother.com"
install=brscan4.install

#[ "$CARCH" = "x86_64" ] && _pkg="dlf105203/${pkgname}-${pkgver/_/-}.x86_64.rpm" || _pkg="dlf105202/${pkgname}-${pkgver/_/-}.i386.rpm"
#[ "$CARCH" = "x86_64" ] && _pkg_md5sum="54dec75887de091fde5fcd511d9a57c3" || _pkg_md5sum="dc87c907c9a2f086dcc56eb2e8fafbbc"

source=("$url/welcome/dlf105203/${pkgname}-${pkgver/_/-}.x86_64.rpm"
	"agree.html"
	mk-udev-hwdb)

build() {
  cd "$srcdir"
  ./mk-udev-hwdb opt/brother/scanner/brscan4/{Brsane4.ini,models4/*.ini} > hwdb
}

package() {
  cp -r $srcdir/etc $pkgdir
  cp -r $srcdir/opt $pkgdir
  cp -r $srcdir/usr $pkgdir
  [ "$CARCH" = "x86_64" ] && mv $pkgdir/usr/lib64 $pkgdir/usr/lib
  install -D -m644 $srcdir/agree.html $pkgdir/usr/share/licenses/$pkgname/LICENSE.html
  install -D -m644 $srcdir/hwdb $pkgdir/usr/lib/udev/hwdb.d/20-$pkgname.hwdb
  # move the links to the right direction
  cd $pkgdir/usr/lib/sane
  ln -sf libsane-brother4.so.1.0.7 $pkgdir/usr/lib/sane/libsane-brother4.so.1
  ln -sf libsane-brother4.so.1 $pkgdir/usr/lib/sane/libsane-brother4.so
}

#---- license gpg-key sha256sums ----
license=('GPL' 'custom:Brother')

#md5sums=($_pkg_md5sum = 54dec75887de091fde5fcd511d9a57c3 dc87c907c9a2f086dcc56eb2e8fafbbc#
#	 'ccffb9a6f6d436b21be25b0241068981'
#	 '8966d38375d535028a63a6ef5f6104eb')

md5sums=(54dec75887de091fde5fcd511d9a57c3 # brscan4-0.4.11-1.x86_64.rpm
	ccffb9a6f6d436b21be25b0241068981 # agree.html
	8966d38375d535028a63a6ef5f6104eb) #  mk-udev-hwdb

sha256sums=(7d7dcbe8349ae4d4ab816e4551017f2f1fd9fd6bf3f4f3c570fbd9576248dd9f # brscan4-0.4.11-1.x86_64.rpm
	3434bca1936d6a5fd6afd810cde7e1876dd4d1496722b09af180278480f464f2 # agree.html
	116d959b841fe47eb5047ece2842af33fd659e43a20005ad26bbbaf607c319b5) #  mk-udev-hwdb
