# Template file for 'samsung-unified-driver-nonfree'
pkgname=samsung-unified-driver
version=1.00.37
revision=2
create_wrksrc=yes
only_for_archs="i686 x86_64"
repository=nonfree
depends="libxml2 libusb-compat cups sane ghostscript"
short_desc="Unified Linux Driver for Samsung printers and scanners"
maintainer="Thomas Bernard <thomas@famillebernardgouriou.fr>"
license="Propietary"
homepage="http://www.samsung.com"
distfiles="http://downloadcenter.samsung.com/content/DR/201512/20151210091120064/uld_v${version}_00.99.tar.gz"
checksum="6b85253ea0bb51d241f6fd665ff0d39464cdad87084802a77a385c707fa2c664"
nostrip=true

post_extract() {
	mv uld/i386 uld/i686
}

do_install() {

	vlicense uld/noarch/license/eula.txt
	vlicense uld/noarch/license/eula-fr.txt

	# install the printer driver
	vmkdir /usr/lib
	vcopy uld/$XBPS_TARGET_MACHINE/libscmssc.so /usr/lib

	vmkdir /usr/lib/cups/backend
	vcopy uld/$XBPS_TARGET_MACHINE/smfpnetdiscovery /usr/lib/cups/backend

	vmkdir /usr/lib/cups/filter
	vcopy uld/$XBPS_TARGET_MACHINE/pstosecps /usr/lib/cups/filter
	vcopy uld/$XBPS_TARGET_MACHINE/rastertospl /usr/lib/cups/filter

	vmkdir /usr/share/ppd/suld
	for ppd in uld/noarch/share/ppd/*.ppd; do
		gzip < "$ppd" > "$DESTDIR"/usr/share/ppd/suld/"${ppd##*/}".gz
	done

	vmkdir /usr/share/ppd/suld/cms
	for cts in uld/noarch/share/ppd/cms/*.cts; do
		vcopy "$cts" /usr/share/ppd/suld/cms
	done

	# install the scanner driver

	vmkdir /usr/share

	vcopy uld/noarch/share/locale /usr/share
	rm -f "$DESTDIR"/usr/share/locale/fr/LC_MESSAGES/install.mo

	vmkdir /etc/sane.d
	vcopy uld/noarch/etc/smfp.conf /etc/sane.d
	vcopy $FILESDIR/xerox_mfp-smfp.conf /etc/sane.d

	vmkdir /etc/sane.d/dll.d
	echo smfp > "$DESTDIR"/etc/sane.d/dll.d/smfp-scanner
	echo $FILESDIR/xerox_mfp-smfp > "$DESTDIR"/etc/sane.d/dll.d/smfp-scanner-fix

	vmkdir /usr/lib/sane
	vcopy uld/$XBPS_TARGET_MACHINE/libsane-smfp.so.1.0.1 /usr/lib/sane

	vmkdir /usr/lib/udev/rules.d
	(
	OEM_FILE=uld/noarch/oem.conf
	INSTALL_LOG_FILE=/dev/null
	source uld/noarch/scripting_utils
	source uld/noarch/package_utils
	source uld/noarch/scanner-script.pkg
	fill_full_template uld/noarch/etc/smfp.rules.in "$DESTDIR"/usr/lib/udev/rules.d/60_smfp_samsung.rules

	vmkdir /opt/samsung/scanner/share
	vcopy "$OEM_FILE" /opt/samsung/scanner/share
	)

}
