# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: André Klitzing <aklitzing@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=flatpak
# Follows GNOME versioning, MINOR (the 2nd number) must be even.
pkgver=1.14.10
pkgrel=0
pkgdesc="Application deployment framework for desktop apps"
url="https://flatpak.org/"
arch="all"
license="LGPL-2.1-or-later"
depends="
	bubblewrap
	desktop-file-utils
	fuse3
	gtk-update-icon-cache
	shared-mime-info
	xdg-dbus-proxy
	"
makedepends="
	appstream-dev
	appstream-glib-dev
	bison
	curl-dev
	dconf-dev
	fuse3-dev
	glib-dev
	gpgme-dev
	json-glib-dev
	libarchive-dev
	libcap-dev
	libgcab-dev
	libseccomp-dev
	libxau-dev
	libxslt-dev
	ostree-dev>=2018.08
	polkit-dev
	py3-parsing
	zstd-dev
	"
checkdepends="bash"
subpackages="
	$pkgname-dbg
	$pkgname-lang
	$pkgname-dev
	$pkgname-libs
	$pkgname-bash-completion
	$pkgname-fish-completion:fishcomp
	$pkgname-zsh-completion
	$pkgname-polkit
	$pkgname-gdm
	"
install="flatpak.pre-install flatpak.pre-upgrade flatpak.post-install"
source="https://github.com/flatpak/flatpak/releases/download/$pkgver/flatpak-$pkgver.tar.xz
	modules-load.conf
	fusermount3.patch
	tzdir.patch
	"
options="!check" # test environment setup requires glibc layout (locales..)

# secfixes:
#   1.14.10-r0:
#     - CVE-2024-42472
#   1.14.6-r1:
#     - CVE-2024-32462
#   1.12.5-r0:
#     - CVE-2022-21682
#   1.12.3-r0:
#     - CVE-2021-43860
#   1.12.2-r0:
#     - CVE-2021-41133
#   1.10.1-r0:
#     - CVE-2021-21261
#   1.2.4-r0:
#     - CVE-2019-10063

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/bin \
		--libexecdir=/usr/lib/$pkgname \
		--disable-static \
		--disable-documentation \
		--with-curl \
		--with-priv-mode=none \
		--with-system-bubblewrap \
		--with-system-helper-user=flatpak \
		--with-system-dbus-proxy \
		--enable-gdm-env-file \
		--with-dbus-config-dir=/usr/share/dbus-1/system.d
	make
}

check() {
	make -k check
}

package() {
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"

	# Remove systemd-specific files.
	rm -rf usr/lib/systemd
	rm -rf usr/lib/sysusers.d
	rm -rf usr/lib/tmpfiles.d

	install -Dm644 "$srcdir"/modules-load.conf usr/lib/modules-load.d/flatpak.conf
}

fishcomp() {
	default_fishcomp

	amove usr/share/fish/vendor_conf.d
}

polkit() {
	depends=""
	pkgdesc="$pkgdesc (polkit config)"
	install_if="$pkgname=$pkgver-r$pkgrel polkit"

	amove usr/share/polkit-1
}

gdm() {
	depends=""
	pkgdesc="$pkgdesc (gdm config)"
	install_if="$pkgname=$pkgver-r$pkgrel gdm"

	amove usr/share/gdm
}

sha512sums="
512c8545aea310aa14450f45704a57cd6fbf1d53e9497f210335e4767ac5d8b2030af17f2ee055b33d287ee5c8b761f0cc9c5f10361faab43c2422da2b354a3d  flatpak-1.14.10.tar.xz
57d23d2778556eafc3035e6be575bf95b4032f123b35f2b1657eff5e7496de253173edc657f90531ee58e25673f4f27a5cd1cc76b14a038edb244f104a231771  modules-load.conf
665dc6003360ea65ce391fe2283344d47c1dafc8f860a5ba410641c7ef54d0c68a63c41963843aeb0364b95df567a83cb80007db282bd284a0744aacced8f1d3  fusermount3.patch
e3456a7d943e89249eeba2227a25f4cf984a9d8bc3e2b614fe1290d23a3a693dc2d203f65dd240fcb3ead92f11696f7b02aa65d174559e71aff656eff0e04a9c  tzdir.patch
"
