aboutsummaryrefslogtreecommitdiff
blob: 435ed6011333e77923d4fcb02b47fd2a8a12f9b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{9..12} )

inherit linux-mod-r1 git-r3 distutils-r1 desktop systemd

EGIT_REPO_URI="https://github.com/johnfanv2/LenovoLegionLinux.git"

DESCRIPTION="Lenovo Legion Linux kernel module"
HOMEPAGE="https://github.com/johnfanv2/LenovoLegionLinux"

RDEPEND="sys-kernel/linux-headers
		sys-apps/lm-sensors
		sys-apps/dmidecode
		legion-tools? ( dev-python/PyQt5 dev-python/pyyaml dev-python/argcomplete )
		legion-acpi? ( sys-power/acpid )
		radeon-dgpu? ( dev-util/rocm-smi )
		downgrade-nvidia? ( <=x11-drivers/nvidia-drivers-525 )
		ryzenadj? ( sys-power/RyzenAdj )
"

DEPEND="${RDEPEND}"

LICENSE="GPL-2"
SLOT="0"
IUSE="legion-tools legion-acpi systemd radeon-dgpu downgrade-nvidia ryzenadj"
REQUIRED_USE="|| ( systemd legion-acpi radeon-dgpu downgrade-nvidia ryzenadj legion-tools ) legion-acpi? ( legion-tools ) radeon-dgpu? ( !downgrade-nvidia legion-tools ) downgrade-nvidia? ( !radeon-dgpu legion-tools )"

MODULES_KERNEL_MIN=5.10

src_compile() {
	local modlist=(
		legion-laptop=kernel/drivers/platform/x86:kernel_module:kernel_module:all
	)
    KERNELVERSION=${KV_FULL} linux-mod-r1_src_compile
	if use legion-tools; then
		#Define build dir (fix sandboxed)
		cd "${WORKDIR}/${P}/python/legion_linux"
		distutils-r1_src_compile --build-dir "${WORKDIR}/${P}/python/legion_linux/build"
	fi
}

src_install() {
	linux-mod-r1_src_install
	#Load the module without reboot
	pushd python/legion_linux/ || die
		make forcereloadmodule
	popd || die
	if use legion-tools; then
		#Define build dir (fix sandboxed)
		cd "${WORKDIR}/${P}/python/legion_linux/"
		distutils-r1_src_install --build-dir "${WORKDIR}/${P}/python/legion_linux/build"

		cd "${WORKDIR}/${P}/extra"

		if use legion-acpi; then
			insinto /etc/acpi/events/ && doins acpi/events/{ac_adapter_legion-fancurve,novo-button,PrtSc-button,fn-r-refrate}
			insinto /etc/acpi/actions/ && doins acpi/actions/{battery-legion-quiet.sh,snipping-tool.sh,fn-r-refresh-rate.sh}
        fi

		if use systemd; then
			systemd_dounit service/legion-linux.service service/legion-linux.path
			dobin service/fancurve-set
			insinto /usr/share/legion_linux && doins service/profiles/*
			insinto /etc/legion_linux && doins service/profiles/*

			#AMD
    		if use radeon-dgpu; then
				insinto /usr/share/legion_linux && newins "${FILESDIR}/radeon" .env
				insinto /etc/legion_linux && newins "${FILESDIR}/radeon" .env
    		fi
    		#NVIDIA (need dowgrade because nvidia-smi -pl was removed)
			if use downgrade-nvidia; then 
				insinto /usr/share/legion_linux && newins "${FILESDIR}/nvidia" .env
				insinto /etc/legion_linux && newins "${FILESDIR}/nvidia" .env
    		fi

			if use ryzenadj; then 
				insinto /usr/share/legion_linux && newins "${FILESDIR}/cpu" .env
				insinto /etc/legion_linux && newins "${FILESDIR}/cpu" .env
    		fi
		fi

		# Desktop Files and Polkit
		domenu "${FILESDIR}/legion_gui.desktop"
		doicon "${WORKDIR}/${P}/python/legion_linux/legion_linux/legion_logo.png"
		insinto "/usr/share/polkit-1/actions/" && doins "${FILESDIR}/legion_cli.policy"

	fi
}

pkg_postinst() {
	if use systemd; then
		ewarn "Default config files are present in /usr/share/legion_linux"
		ewarn "Pls copy that folder to /etc/legion_linux and edit the fancurves to your liking"
		ewarn "Note:can be done using the gui app"
		ewarn "Dont forget to edit /etc/legion_linux/.env to enable and disable extra features"
		ewarn "Note: use flag downgrade-nvidia in need for nvidia TDP control"
	fi
	ewarn "For Intel Users is need to install undervolt manally since and ebuild exist"
	ewarn "Undervolt Repo: https://github.com/georgewhewell/undervolt"
	ewarn "More information on this README: https://github.com/Petingoso/legion-fan-utils-linux/blob/main/README.md"
}