Gentoo Archives: gentoo-commits

From: Brian Evans <grknight@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-power/acpilight/files/, sys-power/acpilight/
Date: Mon, 24 Jan 2022 20:37:55
Message-Id: 1643056526.9ea2c61a18715c5255266d67fbcdcf72e3c06c19.grknight@gentoo
1 commit: 9ea2c61a18715c5255266d67fbcdcf72e3c06c19
2 Author: Brian Evans <grknight <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jan 24 20:35:26 2022 +0000
4 Commit: Brian Evans <grknight <AT> gentoo <DOT> org>
5 CommitDate: Mon Jan 24 20:35:26 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9ea2c61a
7
8 sys-power/acpilight: Add error handling to the OpenRC script
9
10 New script will not continue to save state when there is an error
11
12 Closes: https://bugs.gentoo.org/831857
13 Signed-off-by: Brian Evans <grknight <AT> gentoo.org>
14
15 sys-power/acpilight/acpilight-1.2-r4.ebuild | 57 +++++++++++++++++++++++++++++
16 sys-power/acpilight/files/acpilight.initd | 17 +++++++--
17 2 files changed, 70 insertions(+), 4 deletions(-)
18
19 diff --git a/sys-power/acpilight/acpilight-1.2-r4.ebuild b/sys-power/acpilight/acpilight-1.2-r4.ebuild
20 new file mode 100644
21 index 000000000000..6b815fddb262
22 --- /dev/null
23 +++ b/sys-power/acpilight/acpilight-1.2-r4.ebuild
24 @@ -0,0 +1,57 @@
25 +# Copyright 1999-2021 Gentoo Authors
26 +# Distributed under the terms of the GNU General Public License v2
27 +
28 +EAPI=7
29 +
30 +PYTHON_COMPAT=( python3_7 python3_8 python3_9 )
31 +
32 +inherit python-single-r1 udev
33 +
34 +MY_P="${PN}-v${PV}"
35 +
36 +DESCRIPTION="Replacement for xbacklight that uses the ACPI interface to set brightness"
37 +HOMEPAGE="https://gitlab.com/wavexx/acpilight/"
38 +SRC_URI="https://gitlab.com/wavexx/acpilight/-/archive/v${PV}/${MY_P}.tar.gz"
39 +LICENSE="GPL-3+"
40 +SLOT="0"
41 +KEYWORDS="~amd64 ~x86"
42 +IUSE=""
43 +
44 +S="${WORKDIR}/${MY_P}"
45 +
46 +RDEPEND="virtual/udev
47 + acct-group/video
48 + !dev-libs/light
49 + ${PYTHON_DEPS}
50 + !x11-apps/xbacklight"
51 +REQUIRED_USE="${PYTHON_REQUIRED_USE}"
52 +DOCS=( README.rst NEWS.rst )
53 +
54 +PATCHES=( "${FILESDIR}/acpilight-1.2-fix-log10-of-zero.patch" )
55 +
56 +# Disable Makefile that installs by default
57 +src_compile() { :; }
58 +
59 +src_install() {
60 + python_doscript xbacklight
61 + udev_dorules "${S}"/90-backlight.rules
62 + doman xbacklight.1
63 + einstalldocs
64 + newinitd "${FILESDIR}"/acpilight.initd acpilight
65 + newconfd "${FILESDIR}"/acpilight.confd acpilight
66 +}
67 +
68 +pkg_postinst() {
69 + udev_reload
70 + einfo
71 + elog "To use the xbacklight binary as a regular user, you must be a part of the video group"
72 + einfo
73 + elog "If this utility does not find any backlights to manipulate,"
74 + elog "verify you have kernel support on the device and display driver enabled."
75 + einfo
76 + elog "To take advantage of the OpenRC init script, and automate the process of"
77 + elog "saving and restoring the brightness level you should add acpilight"
78 + elog "to the boot runlevel. You can do this as root like so:"
79 + elog "# rc-update add acpilight boot"
80 + einfo
81 +}
82
83 diff --git a/sys-power/acpilight/files/acpilight.initd b/sys-power/acpilight/files/acpilight.initd
84 index 0de6029867e0..780828246712 100644
85 --- a/sys-power/acpilight/files/acpilight.initd
86 +++ b/sys-power/acpilight/files/acpilight.initd
87 @@ -1,5 +1,5 @@
88 #!/sbin/openrc-run
89 -# Copyright 1999-2017 Gentoo Foundation
90 +# Copyright 1999-2022 Gentoo Authors
91 # Distributed under the terms of the GNU General Public License v2
92
93 state_dir=/var/lib/acpilight
94 @@ -19,13 +19,22 @@ restore() {
95 return 0
96 fi
97 xbacklight "$(cat "${state_dir}/state")"
98 - eend $?
99 + ewend $? "Could not restore brightness. The state file ${state_dir}/state is invalid or the system cannot apply the value."
100 }
101
102 save() {
103 + local newValue
104 ebegin "Saving brightness level"
105 - mkdir -p "${state_dir}" && xbacklight -get > "${state_dir}/state"
106 - eend $?
107 + # Save the value here so an error won't record an empty/invalid value
108 + newValue=$(xbacklight -get) && \
109 + mkdir -p "${state_dir}" && \
110 + echo "${newValue}" > "${state_dir}/state"
111 + if [ $? -gt 0 ]; then
112 + ewarn "Could not save brightness."
113 + ewarn "The state file ${state_dir}/state cannot be written to or the system cannot read the brightness value."
114 + fi
115 + # Don't fail on error
116 + eend 0
117 }
118
119 start() {