Apocrypha

brillo-9999nadevko

# Copyright 2026 Nadeŭka <[email protected]>
# Distributed under the terms of the GNU General Public License v2
EAPI=8

inherit udev

: "${BRILLO_GROUP:=video}"

DESCRIPTION="Control the brightness of backlight and keyboard LED \
	devices"
HOMEPAGE=https://gitlab.com/cameronnemo/brillo

if [[ $PV == 9999 ]]; then
	inherit git-r3
	EGIT_REPO_URI="$HOMEPAGE.git"
else
	SRC_URI="$HOMEPAGE/-/archive/v$PV/$PN-v$PV.tar.bz2 -> $P.tar.bz2"
	KEYWORDS='amd64 ~arm64 ~x86'
	S="$WORKDIR/$PN-v$PV"
fi

LICENSE=GPL-3
SLOT=0

IUSE='apparmor man policykit setgid +udev'
REQUIRED_USE='
	|| ( policykit setgid udev )
	policykit? ( udev )
'

BDEPEND='man? ( dev-go/go-md2man )'
RDEPEND="
	policykit? ( sys-auth/polkit )
	udev? ( virtual/udev acct-group/${BRILLO_GROUP} )
"

src_prepare() {
	default
	sed -i 's|override CFLAGS|CFLAGS|g' Makefile ||
		die "failed to patch Makefile"
}

src_compile() {
	default
	use man && emake GROUP="$BRILLO_GROUP" build/brillo.1
}

src_install() {
	local targets=( "install.bin$(usev setgid .setgid)" )

	use apparmor && targets+=( install.apparmor )
	use man && targets+=( install.man )
	use policykit && targets+=( install.polkit )
	use udev && targets+=( install.udev )

	emake DESTDIR="$D" GROUP="$BRILLO_GROUP" "${targets[@]}"
	einstalldocs

	newinitd "$FILESDIR/brillo.initd" brillo
}

pkg_postinst() {
	if use udev; then
		udev_reload

		elog "brillo requires the calling user to be in the '$BRILLO_GROUP'"
		elog 'group to control backlight and keyboard LEDs.'
	fi
	elog 'To make brightness persistent across reboots on OpenRC,'
	elog 'enable the service:'
	elog '  rc-update add brillo boot'
	elog '  rc-service brillo start'
}

pkg_postrm() {
	use udev && udev_reload
}