maintainer=""
pkgname=msm-modem
pkgver=12
pkgrel=0
pkgdesc="Common support for Qualcomm MSM modems"
url="https://postmarketos.org/"
arch="armhf armv7 aarch64"
license="GPL-3.0-or-later"
depends="rmtfs"
subpackages="
	$pkgname-downstream
	$pkgname-downstream-openrc:downstream_openrc
	$pkgname-openrc
	$pkgname-systemd
	$pkgname-uim-selection:uim_selection
	$pkgname-uim-selection-openrc:uim_selection_openrc
"

source="
	keepfileopen.c
	msm-modem-downstream.initd
	msm-modem-uim-selection
	msm-modem-uim-selection.confd
	msm-modem-uim-selection.initd
	msm-modem-uim-selection.service
	rmtfs.service.d.override.conf
	udev-downstream.rules
"
options="!check"

build() {
	gcc -o keepfileopen "$srcdir"/keepfileopen.c
}

package() {
	install -Dm755 "$srcdir"/msm-modem-uim-selection \
		-t "$pkgdir"/usr/libexec/
	install -Dm755 keepfileopen \
		-t "$pkgdir"/usr/bin/

	install -Dm644 "$srcdir"/msm-modem-uim-selection.service \
		-t "$pkgdir"/usr/lib/systemd/system/
	install -Dm644 "$srcdir"/rmtfs.service.d.override.conf \
		"$pkgdir"/usr/lib/systemd/system/rmtfs.service.d/override.conf
}

uim_selection() {
	pkgdesc="$pkgdesc (UIM selection)"
	depends="$pkgname libqmi qmi-utils"

	mkdir -p "$subpkgdir"
}

uim_selection_openrc() {
	install_if="$pkgname-uim-selection=$pkgver-r$pkgrel openrc"
	install="$subpkgname.post-install"
	depends="openrc"

	install -Dm644 "$srcdir/$pkgname-uim-selection.confd" \
		"$subpkgdir/etc/conf.d/$pkgname-uim-selection"
	install -Dm755 "$srcdir/$pkgname-uim-selection.initd" \
		"$subpkgdir/etc/init.d/$pkgname-uim-selection"
}

downstream() {
	pkgdesc="$pkgdesc (downstream)"
	depends="$pkgname libqipcrtr4msmipc libsmdpkt_wrapper"

	amove usr/bin/keepfileopen

	install -Dm644 "$srcdir/udev-downstream.rules" "$subpkgdir/usr/lib/udev/rules.d/55-$pkgname.rules"
}

downstream_openrc() {
	install_if="$pkgname-downstream=$pkgver-r$pkgrel openrc"
	install="$subpkgname.post-install"
	depends="openrc"

	install -Dm755 "$srcdir/$pkgname-downstream.initd" \
		"$subpkgdir/etc/init.d/$pkgname-downstream"
}

openrc() {
	install_if="$pkgname=$pkgver-r$pkgrel openrc"
	depends="openrc rmtfs-openrc"
	install="$subpkgname.post-install"

	mkdir -p "$subpkgdir"
}

sha512sums="
ac9ed0f6ec07ef813ce3a539919acbe8a5a70d5765a5fff267674a3fb239cdb1dba58a14d72a64f990bdcb87c6476d30ef7add21f152df7cb48e36932ef14dbb  keepfileopen.c
3172f8c409f552f13d1da29f14ab6c79072cd6da4acab151a1a0ea1858a416974456852609f14fe29cf97a6a45e60b99d0a57ddcde751da243ee5ac6fa8b672c  msm-modem-downstream.initd
5ad3484065c8b782cee725fcbc86a09c6b59df5555d88dc84637126f48513da543d08b8c930cc5d3c8580575c0625b3684d71704ee7e182ed1ed80ae4453cef3  msm-modem-uim-selection
abc985c76170601a22a1d5ab0c68bdf63fa2be2796593048ea3ba0d7e5cd26b2fcee2043703e46c2910c53b01e9e8092b7a8e715d57baf243a5f4612dd595443  msm-modem-uim-selection.confd
076d6de36527ac853674c2fc94120e711c1f77c4936977cf353a319f73beed21b9b0b81728572c8894e7dface3ecb5686535f0967de19a6bc5356d44e9ea8756  msm-modem-uim-selection.initd
a12d8d6994ae6e46b0d131c9f5c475ccc70ab7aaf5839b19c1917410fb3c90a208bc0c6e07c90cf251ea6e445741af83a9f77bf9fcb30490bb0fbfc07aa8cbb9  msm-modem-uim-selection.service
c2eeca53016bcc01a0822cd3799574d4404eac8d87e7aa4928f95a2fd7080e3b388294d0e98eee5595d82a842a832a6f29663bdcf6c493d54dc00a196d5700d3  rmtfs.service.d.override.conf
2a511c2e249d0ec5a52f04ffe1ef3d29cf3c4813143b103e54879ff89176ea45b1a5ffe21cb7dc2f1cdd84c3102ba45ef9926ed37e00b1ae12a36d01de35ea5a  udev-downstream.rules
"
