# Reference: <https://postmarketos.org/devicepkg>
pkgname=device-samsung-goyawifi
pkgdesc="Samsung Galaxy Tab 3 Lite"
pkgver=1
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="armv7"
options="!check !archcheck"
depends="
	alsa-ucm-conf
	linux-samsung-goyawifi
	mkbootimg
	postmarketos-base
"
makedepends="devicepkg-dev"
source="
	deviceinfo
	goyawifi.conf
	sd8xxx.conf
	galcore.conf
	dhcp-client.conf
	ipv4-workaround.sh
	etc-lightdm-lightdm.conf
	initfs-hook.sh
	ucm/HiFi.conf
	ucm/emei-dkb-hifi.conf
"
subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-networkmanager-dhclient:networkmanager_dhclient
	$pkgname-fix-lightdm:fix_lightdm
"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname

	# Add module rules for Wi-Fi (mbt8xxx kernel panic)
	install -D -m644 "$srcdir"/goyawifi.conf \
		"$pkgdir"/etc/modprobe.d/goyawifi.conf
	install -D -m644 "$srcdir"/sd8xxx.conf \
		"$pkgdir"/lib/modules-load.d/sd8xxx.conf
	# Load Vivante GPU module
	install -D -m644 "$srcdir"/galcore.conf \
		"$pkgdir"/lib/modules-load.d/galcore.conf

	# Alsa UCM configs
	install -Dm644 "$srcdir"/emei-dkb-hifi.conf \
		"$pkgdir"/usr/share/alsa/ucm2/conf.d/emei-dkb-hifi/emei-dkb-hifi.conf
	install -Dm644 "$srcdir"/HiFi.conf \
		"$pkgdir"/usr/share/alsa/ucm2/conf.d/emei-dkb-hifi/HiFi.conf
}

nonfree_firmware() {
	pkgdesc="Samsung T110 (goyawifi) WiFi & BT firmware"
	depends="firmware-samsung-goyawifi"
	mkdir "$subpkgdir"
}

networkmanager_dhclient() {
	install_if="$pkgname networkmanager"
	pkgdesc="Install and use dhclient for networkmanager to get IP throught DHCP"
	depends="dhclient"

	# Use DHCLIENT for networkmanager as internal client would not work on goyawifi
	install -D -m644 "$srcdir"/dhcp-client.conf \
		"$subpkgdir"/etc/NetworkManager/conf.d/dhcp-client.conf

	install -D -m755 "$srcdir"/ipv4-workaround.sh \
		"$subpkgdir"/etc/NetworkManager/dispatcher.d/ipv4-workaround.sh
}

fix_lightdm() {
	install_if="$pkgname lightdm"
	pkgdesc="Fix the problem for CanGraphical=no in LightDM according to Display Manager in PMOS Wiki"
	depends="lightdm"
	replaces="lightdm"

	# Install lightdm configuration with logind-check-graphical=false
	install -D -m644 "$srcdir"/etc-lightdm-lightdm.conf \
		"$subpkgdir"/etc/lightdm/lightdm.conf
}

sha512sums="
10fd6444d5d8a9a67eca2fa063f135aa25e992c137291bc38e200fb7d1772efa98dbeea94648ee87a73c871c5d06abe65ca495618f8103b7f79b77326a351838  deviceinfo
73d03f53e08a650b3073e33653d3bcfa6951042203dde7104ffddbe59e29bafbb26c0e41cd9357ede8f01abe0049b190a2acae82e5a5b92868129ab66b118a8d  goyawifi.conf
33f81e747f68472709c9933837809853d2786df627b1f3e41b5a0524577097cf0fadcdbaf403cbe1e16f3480f5b1924ea6d1c0b67e37340e9a0f51bd154a1dc4  sd8xxx.conf
2be76a8208a5d7244aa975d122e73ad76d8ca4f6ef0776fb84c2e1ac075d5f4e810338c09009ef3317bf447b42f3b6657ba762e73d6ae7392a756c37ba5b34d4  galcore.conf
c1c9b58b5325ad11afc98bf1b20179c725b7627416270fe87558bdc259fbb996628d404aaaef6e8c9ea41c21b015ae767ce1c3054490481c24cc97d0002d69bb  dhcp-client.conf
94a84eb3c91108596e8edcb0a615ce642a37af4092011845d2c0e7214b3c2daa6c51ca9951501be9277c7c0d3c71c32a0bca60d806d284a97a350db4a9e9bbd2  ipv4-workaround.sh
861270c6bc0b2a3e6cd389c21c8c895e62de8cf8bec6fcf23c178f8cbaae855d62b0ee98692671ab4f518d84cb43dd0b2fe46f5a609f65af6a6c06e0fdbb6d0c  etc-lightdm-lightdm.conf
efcf13b927a984bc99b86ea0fee907a7be555d02bb38cc7e020c53120be8a1cd9c53ec1754b316b6422621fc13768e81fd00b837713178f5024e12664dad47d5  initfs-hook.sh
a947334f0e8a3b46ab7905a7291ea0cb94b4f73303ec1f7307478a5a7a316300907af033eb58035044738701185ef715ff22eb168f2eba281728d2ef039ffac9  HiFi.conf
80d44e328e31eacdaba6a56536ab68bcbda71e20be1fb62e8a13262ad165ce9de0d92c88bae9079b38a02956b8fa5a81e8675a21b5a825587542a786d12817f2  emei-dkb-hifi.conf
"
