# pmbootstrap installs this, if systemd is selected in "pmbootstrap init".
maintainer="Clayton Craft <clayton@craftyguy.net>"
pkgname=postmarketos-base-systemd
pkgver=86
pkgrel=0
pkgdesc="Meta package for running postmarketOS with systemd"
url="https://postmarketos.org"
# armhf: pmb#2618
arch="noarch !armhf"
license="GPL-3.0-or-later"
options="!check"
triggers="$pkgname.trigger=/usr/lib/systemd/system:/usr/lib/systemd/user"

# systemd <-> util-linux is an expected cycial dependency
# Also we can't parse .note.dlopen yet.
#
# Optional dependencies by systemd, but needed on an actual system:
# less
# login-utils
# so:libkmod.so.2
#
# linux-pam:
# - pam_systemd.so is added since 1.7.0-r1
# - pam_limits.so isn't used in alpine/pmOS, so it isn't supported and tested.
#   Additionally pam_limits.so can be compiled with (e)logind support, which
#   isn't currently done in aports. In the unlikely case this is changed
#   upstream and elogind-libs are used.
depends="
	dbus-broker
	kbd
	kmod
	less
	linux-pam>=1.7.0-r1
	login-utils
	polkit>9990
	rtkit
	so:libkmod.so.2
	systemd
	systemd-services
	systemd-timesyncd
	treescan
	tzdata
	"
provides="postmarketos-base-init"
provider_priority=100
replaces="alpine-baselayout openssh-server-pam postmarketos-baselayout postmarketos-base systemd systemd-logind"
replaces_priority=100
install="
	$pkgname.post-install
	$pkgname.post-upgrade
	$pkgname.pre-upgrade
	$pkgname-resolved.post-install
	"
subpackages="
	$pkgname-resolved
	postmarketos-base-apk-systemd:_apk
	"

_source644="
	etc/pam.d/sshd
	etc/profile.d/20locale.sh
	usr/lib/NetworkManager/conf.d/50-dns.conf
	usr/lib/systemd/journald.conf.d/10-postmarketos.conf
	usr/lib/systemd/logind.conf
	usr/lib/systemd/resolved.conf.d/disable-dnsovertls.conf
	usr/lib/systemd/resolved.conf.d/disable-mdns.conf
	usr/lib/systemd/system-preset/90-base.preset
	usr/lib/systemd/system/-.slice.d/10-oomd-defaults.conf
	usr/lib/systemd/system/apk-inhibit.path
	usr/lib/systemd/system/apk-inhibit.service
	usr/lib/systemd/system/system.slice.d/10-oomd-defaults.conf
	usr/lib/systemd/system/tmp.mount.d/10-min-memory.conf
	usr/lib/systemd/system/user@.service.d/10-oomd-defaults.conf
	usr/lib/systemd/user-preset/90-base.preset
	usr/lib/systemd/user/app.slice.d/10-oomd-defaults.conf
	usr/share/mkinitfs/files-extra/01-initramfs-base-systemd.files
"

_source755="
	etc/apk/commit_hooks.d/postmarketos-base-systemd
	usr/bin/setup-timezone
	usr/libexec/systemd-apk-trigger
	usr/libexec/apk-inhibit
"

flatpath() {
	local i
	for i in $@; do
		echo "rootfs-$i" | sed s./.-.g
	done
}
source="$(flatpath $_source644 $_source755)"

package() {
	local i
	for i in $_source644; do
		install -Dm644 "$srcdir/$(flatpath "$i")" "$pkgdir/$i"
	done
	for i in $_source755; do
		install -Dm755 "$srcdir/$(flatpath "$i")" "$pkgdir/$i"
	done

	# Setup VT template generation:
	# Distros must create this symlink manually. See
	# https://www.freedesktop.org/software/systemd/man/latest/logind.conf.html#NAutoVTs=
	# https://github.com/systemd/systemd/commit/072e72424b2e6da1c96489ef6996f49fabd46474
	ln -s getty@.service \
		"$pkgdir"/usr/lib/systemd/system/autovt@.service
}

resolved() {
	install_if="$pkgname=$pkgver-r$pkgrel systemd-resolved"

	amove usr/lib/systemd/resolved.conf.d/disable-dnsovertls.conf
	amove usr/lib/systemd/resolved.conf.d/disable-mdns.conf
	amove usr/lib/NetworkManager/conf.d/50-dns.conf
}

_apk() {
	install_if="$pkgname=$pkgver-r$pkgrel apk-tools"
	depends="inotify-tools flock"

	amove usr/libexec/apk-inhibit
	amove usr/lib/systemd/system/apk-inhibit.path
	amove usr/lib/systemd/system/apk-inhibit.service
}

sha512sums="
ff5b22d095d240a7a222afcdea14cbca8ee78472df3553827c5c02753ee97d84b59624a87952afa5690581910f8f4aaebfe035e97be465ee07ca17c6a7c4cdd7  rootfs-etc-pam.d-sshd
084f6256e712d33e605c4a1d794ed6ed2d3f31c7ddce5baaad7f44ba74f371f969a16e06f25884a71e4e7216496df0ff0afb6d3246e23932681ad64abfb96975  rootfs-etc-profile.d-20locale.sh
94063e3a3f983b7613d9de6bfc067096f79b12688f45667faf968f9a9bae194c4c8e554311f2ab5614edcc4d4499f6d30aa965a67b7417c26ce4d07edc847178  rootfs-usr-lib-NetworkManager-conf.d-50-dns.conf
b7c3e70f5e4d88d6df6a8d58f4bb6af3d3051c5130cf13ad86a491fcbf7a69ae33ba31d663946c35ddaed03a16b6eb9d9d4b7cabcb58bfec7a254920ff375178  rootfs-usr-lib-systemd-journald.conf.d-10-postmarketos.conf
bd85f6153d857e1aec191b5fc8c8fc0d87125bf0198bef20d1e91ef40ca7e9ed1209a64ae279f98dc8733969ad6e71e29623180ef2203e386023a950d9ce8269  rootfs-usr-lib-systemd-logind.conf
e49972d276441e9da284315bab5f70d8d25ccba5e43d7e7ec6607c34a3d4dfa512f7303d5ce41076819ef24f5dced5acc74001b4d569258269de34da27912466  rootfs-usr-lib-systemd-resolved.conf.d-disable-dnsovertls.conf
93ab180810dbd2a1477f7ea0f0959be90f099272fe5840030a0772771c97a066b70068c476d32c6a4610b8f7b9fc5bfcf1d7a93f071cec026553ac6a3b8b5324  rootfs-usr-lib-systemd-resolved.conf.d-disable-mdns.conf
a5f8d179b1d00f604e185539a333be5d5ac64c6b9550afc242daf1bca88d5e6587a63bf90c3d8ddbc458f5ec997865e5c878f33372e0f49411396b13850aafa3  rootfs-usr-lib-systemd-system-preset-90-base.preset
bde7052939d1ddde22fe1df86439d3f1b0cd41810911cee7acf26aac08afe1610360cbbd257b3c1a2e5e7409dff27ade8f3a302a38cd1b99c6cc6eed4cc64a78  rootfs-usr-lib-systemd-system--.slice.d-10-oomd-defaults.conf
e81ffc21ef12fe41555bf065836b01bdaeb4e332e8fbb083fb3f1743f920f1d2a1a4fe848d759ec486f7da0add32478ff2fd7f24c0dec9f9974406ac075f61b0  rootfs-usr-lib-systemd-system-apk-inhibit.path
5af6294b8936dee1e2e8429c7eecd28c0e641adffb55d45b05624845971d0ed99ce31b4a1f3c80bc8aa1c59dc2b60ab9e32f78f03c21650c61957c567547f464  rootfs-usr-lib-systemd-system-apk-inhibit.service
bde7052939d1ddde22fe1df86439d3f1b0cd41810911cee7acf26aac08afe1610360cbbd257b3c1a2e5e7409dff27ade8f3a302a38cd1b99c6cc6eed4cc64a78  rootfs-usr-lib-systemd-system-system.slice.d-10-oomd-defaults.conf
cedd159b98ce47ee9d03e5f332c4132c7c3eff32135aa7b7993e19c4867d55aff689b418fc549e139c0ea4690f1094e86efcee7a5bc6cd6998ba99821064a917  rootfs-usr-lib-systemd-system-tmp.mount.d-10-min-memory.conf
c5252710d8e2f95f5c216cce17737bb14e112c7f1e0b73f085ac0bc3da5a718bb831cc62c0c62e7e5e99337fdcc5c4ace76c5c11bb0ae1f242181ce6829e4fd3  rootfs-usr-lib-systemd-system-user@.service.d-10-oomd-defaults.conf
c6b22809e77d3134285233988d805c9cdbc3e3c90af320e920aaf4dcfd83582c2a85278f2edf07e70574fdc6cf6ebce58bfc470060ab504061ed8aa389209537  rootfs-usr-lib-systemd-user-preset-90-base.preset
4217385ab8e0d0e53a6f6eb2ad0ef5c1ae88cab431c9fdca3528f147241edfefe7eec8f2927670dcf79c6f853d2c8a930782fad7e2a28ef6575b55df115f2f83  rootfs-usr-lib-systemd-user-app.slice.d-10-oomd-defaults.conf
15423bfda57c90ab62fe69865ca4072a0aeb83bf77d9c278257e346f4da81843d010b41003c91ae9f3fcb1c67447645e7c19078eea2bf11312051e6ad7523ad1  rootfs-usr-share-mkinitfs-files-extra-01-initramfs-base-systemd.files
6ff3fbd88493e50de5821c6e3db92623b38de52be4e8e967f4f297d8f70e31a86d91f1243b973387b80c8520edcc89a8233db6f234bca22a56ee61a1b4333670  rootfs-etc-apk-commit_hooks.d-postmarketos-base-systemd
605df1f004783d2e0ec5dd99a688bca27502c8c24bc05fb4dc26589b2070b0fbd1cf9bd56e6861d7cda2f8ac8147e7eb040acfd886185c01c8cf9de8b1ce2dcd  rootfs-usr-bin-setup-timezone
d96898efb28508b172f148c0a468a7dddd363dde94efea7c2274b9f746544b4e8bf7905ce3f8134a97c1eb33210ad97380f3da452082f346f1f3f0f665f79d47  rootfs-usr-libexec-systemd-apk-trigger
237f5478bed05128bba6b44f1545e904447b53779d37bf0bedb1c1bc68c53394ba767ef52d3ff4980d593f02daea0b05454a316a0348821de924308109deced6  rootfs-usr-libexec-apk-inhibit
"
