summaryrefslogtreecommitdiff
path: root/sys-power/acpilight/files/acpilight.initd
blob: 780828246712bd568f3f985d574c9918a8ea0a4f (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
#!/sbin/openrc-run
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

state_dir=/var/lib/acpilight

extra_commands="save restore"

depend() {
	need localmount
	after bootmisc modules isapnp coldplug hotplug
}

restore() {
	ebegin "Restoring brightness level"
	if [ ! -r "${state_dir}/state" ] ; then
		ewarn "No brightness level in ${state_dir}/state"
		eend 0
		return 0
	fi
	xbacklight "$(cat "${state_dir}/state")"
	ewend $? "Could not restore brightness. The state file ${state_dir}/state is invalid or the system cannot apply the value."
}

save() {
	local newValue
	ebegin "Saving brightness level"
	# Save the value here so an error won't record an empty/invalid value
	newValue=$(xbacklight -get) && \
		mkdir -p "${state_dir}" && \
		echo "${newValue}" > "${state_dir}/state"
	if [ $? -gt 0 ]; then
		ewarn "Could not save brightness."
		ewarn "The state file ${state_dir}/state cannot be written to or the system cannot read the brightness value."
	fi
	# Don't fail on error
	eend 0
}

start() {
	if [ "${RESTORE_ON_START}" = "yes" ]; then
		restore
	fi
}

stop() {
	if [ "${SAVE_ON_STOP}" = "yes" ]; then
		save
	fi
}