# Maintainer: Noel Kuntze <noel.kuntze@contauro.com>
pkgname=grommunio-dav
pkgver=1.4
_commithash=ec8c674
pkgrel=0
pkgdesc="CalDAV and CardDAV interface for grommunio"
# s390x: blocked by grommunio-gromox
arch="noarch !riscv64 !s390x"
url="https://grommunio.com/"
license="AGPL-3.0-only"
options="!check" # No test suite
_php=php83
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-doc"
depends="grommunio-gromox
	grommunio-mapi-header-php
	$_php
	$_php-ctype
	$_php-curl
	$_php-dom
	$_php-iconv
	$_php-mbstring
	$_php-pdo_sqlite
	$_php-xml
	$_php-xmlreader
	$_php-xmlwriter
	"

pkgusers="grommunio grodav"
pkggroups="grommunio grodav"

source="$pkgname-$pkgver.tar.xz::https://github.com/grommunio/grommunio-dav/releases/download/$pkgver/grommunio-dav-$pkgver.0.$_commithash.tar.xz"

builddir="$srcdir/grommunio-dav-$pkgver.0.$_commithash/"

build() {
	:
}

package() {
	# webapp & vendor libraries
	install -dm755 "$pkgdir"/usr/share/webapps/$pkgname/
	cp -rp -- *.php *.xml lib vendor "$pkgdir"/usr/share/webapps/$pkgname/

	# license
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	# nginx conf
	sed -i "s@/usr/share/grommunio-dav/@/usr/share/webapps/grommunio-dav/@" build/grommunio-dav.conf
	install -Dpm644 build/grommunio-dav.conf "$pkgdir"/usr/share/grommunio-common/nginx/locations.d/grommunio-dav.conf
	sed -i "s@/php-fpm/@/php-fpm${_php#php}/@" build/grommunio-dav-upstream.conf
	install -Dpm644 build/grommunio-dav-upstream.conf "$pkgdir"/usr/share/grommunio-common/nginx/upstreams.d/grommunio-dav.conf

	# php-fpm
	sed -i "s@/php-fpm/@/php-fpm${_php#php}/@" build/pool-grommunio-dav.conf
	install -Dpm644 build/pool-grommunio-dav.conf "$pkgdir"/etc/$_php/php-fpm.d/pool-grommunio-dav.conf

	# logrotate
	install -Dm644 build/grommunio-dav.lr "$pkgdir"/etc/logrotate.d/grommunio-dav

	# config
	install -Dm644 config.php "$pkgdir"/etc/grommunio-dav/config.php
	ln -sf "/etc/grommunio-dav/config.php" "$pkgdir"/usr/share/webapps/grommunio-dav/config.php
	install -Dm644 glogger.ini "$pkgdir"/etc/grommunio-dav/glogger.ini
	ln -sf "/etc/grommunio-dav/glogger.ini" "$pkgdir"/usr/share/webapps/grommunio-dav/glogger.ini

	# log folder
	install -dm 0770 -o grodav "$pkgdir"/var/log/grommunio-dav
}

sha512sums="
d8db151def2a01efb2b525ca32b9f4d687e72d6895167a3f18d0af78846d5f9c1f412efa1a0029d0e2bf63c308e43cf7a5705a443437e71ca872c3b72bffe735  grommunio-dav-1.4.tar.xz
"
