# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=sphinx
pkgver=2.2.11
pkgrel=7
pkgdesc="Free open-source SQL full-text search engine"
url="http://www.sphinxsearch.com"
arch="all"
license="GPL-2.0-only"
makedepends="
	expat-dev
	libpq-dev
	libstemmer-dev
	mariadb-connector-c-dev
	unixodbc-dev
	"
pkgusers="$pkgname"
pkggroups="$pkgname"
subpackages="$pkgname-doc $pkgname-php::noarch"
source="http://sphinxsearch.com/files/sphinx-$pkgver-release.tar.gz
	sphinx.initd
	sphinx.confd
	sphinx-pagesize.patch
	CVE-2020-29050.patch
	"
builddir="$srcdir"/$pkgname-$pkgver-release

# secfixes:
#   2.2.11-r7:
#     - CVE-2020-29059

build() {
	./configure \
		--prefix=/usr \
		--exec-prefix=/usr \
		--localstatedir=/var/lib/sphinx \
		--sysconfdir=/etc/sphinx \
		--docdir=/usr/share/doc/sphinx \
		--mandir=/usr/share/man \
		--with-pgsql \
		--with-mysql \
		--with-unixodbc \
		--with-libexpat \
		--with-iconv \
		--with-libstemmer \
		--with-syslog \
		--without-re2 \
		--enable-id64
	make
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	chown -R $pkgusers:$pkggroups "$pkgdir"/var/lib/sphinx
}

php() {
	pkgdesc="PHP api for sphinx search engine"

	mkdir -p "$subpkgdir"/usr/share/php/$pkgname/api
	find $builddir/api/ -type f -maxdepth 1 -name "*.php" \
		-exec mv {} "$subpkgdir"/usr/share/php/$pkgname/api/ \;
}

doc() {
	default_doc;
	mkdir -p "$subpkgdir"/usr/share/doc/$pkgname/misc
	cp -r "$builddir"/misc/* "$subpkgdir"/usr/share/doc/$pkgname/misc

}

sha512sums="
cf1a262a5b0fbf0bd2827ec6ec629edeaf709ce855a6e7b509b65342baaeb26c02717ca63f1578d32c83d21e2fd6d1e92dceb34660e6351b93cd96fd4e623689  sphinx-2.2.11-release.tar.gz
583601ff63e663099ae40048b8a216d0bc815a50a82370a42d3e7b923c90c650d58951636041ff9000141d897357767b7895a238a4edc49c328e46241b391350  sphinx.initd
8dbbb3b75bfbde5c6d2bee801df8c7a82650d3943dd667a4330cae473cbf18390aff5eb8d6aa6e5d69c4c995065d48289047b9166fa756c6015bf71f2b13a8f0  sphinx.confd
9563c5a926e5be30477781038ccf115a809a32bbcbc02c5b82e7985fca76185005968b5f0442772ec598b2ff17ef5c185582e24ae74775e5358abc88192345f2  sphinx-pagesize.patch
b3e27a556789af966ca779136122f8d0ebb6999ef9766029a0492bcf918d3e6f94cda01797c8715ad41f6fa8f8afc755672734b4bdcacb17b35009ac9a5f05aa  CVE-2020-29050.patch
"
