# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>

pkgname=firefly-iii
pkgver=5.7.18
pkgrel=0
pkgdesc="PHP personal finances manager"
arch="noarch"
url="https://github.com/firefly-iii/firefly-iii"
license="AGPL-3.0-only"
options="!check" # No testsuite
_php=php81
_php_mods="-intl -curl -bcmath -zip -gd -xml -mbstring -ldap -session -fileinfo -simplexml -sodium -tokenizer -xmlwriter -dom -pdo"
depends="$_php ${_php_mods//-/$_php-}"
makedepends="composer"
source="$pkgname-$pkgver.tar.gz::https://github.com/firefly-iii/firefly-iii/archive/$pkgver.tar.gz"
pkgusers="firefly"
pkggroups="www-data"

prepare() {
	default_prepare
	composer install --no-scripts --no-dev
}

package() {
	local datadir="/var/lib/$pkgname"
	local cachedir="/var/cache/$pkgname"
	local wwwdir="/usr/share/webapps/$pkgname"
	local confdir="/etc/$pkgname"

	install -dm 755 "$pkgdir"/$datadir "$pkgdir"/$wwwdir "$pkgdir"/$confdir "$pkgdir"/$cachedir

	cp -rv "$builddir"/. "$pkgdir"/$wwwdir//

	cp -v "$pkgdir"/$wwwdir/.env.example "$pkgdir"/$confdir/.env
	cp -v "$pkgdir"/$wwwdir/.deploy/*/.env* "$pkgdir"/$confdir
	for i in '' '.heroku' ; do
		mv -v "$pkgdir"/$confdir/.env$i "$pkgdir"/$confdir/config.env$i
	done

	mv "$pkgdir"/$wwwdir/storage/* "$pkgdir"/$datadir
	rm -rf $pkgdir/$wwwdir/storage
	rm -rf "$pkgdir"/$wwwdir/bootstrap/cache

	ln -s $confdir/config.env "$pkgdir"/$wwwdir/.env
	ln -s $cachedir "$pkgdir"/$wwwdir/bootstrap/cache
	ln -s $datadir "$pkgdir"/usr/share/webapps/$pkgname/storage
}

sha512sums="
4febc482056d1c635fb674b001442dcaa6d331ce3906aeeac80497b42b38fa1e2393e6b2a0d76da884db15d000c4364d299a11e4d28b2b6ebdeba8fae638a413  firefly-iii-5.7.18.tar.gz
"