aports/community/brightnessctl/brightnessctl.initd
Jakob Hauser 8b90fc8196 community/brightnessctl: restrict openrc service to backlights
The application brightnessctl can control two different classes of
sysfs devices, "backlight" and "leds". When it searches for devices
it first goes thtrough the "backlight" class and thereafter through
the "leds" class. If no class or device is specified by the command
line, it acts on the first device it has found.

Using the openrc service script on boot works fine if there is a
backlight available. However, if there is no backlight, brightnessctl
starts to mess around with the first LED it finds, causing potentially
strange things.

Therefore exit the openrc service if there is no backlight.
2024-12-16 21:47:21 +00:00

28 lines
658 B
Bash

#!/sbin/openrc-run
description="Save and restore display backlight settings"
save_file="/var/lib/brightnessctl/state"
start() {
ebegin "Setting brightness to saved value"
# fails to start first time if file does not exist
if [ -f "$save_file" ]; then
brightnessctl --class=backlight --quiet set "$(cat "$save_file")" 2>/dev/null
if [ $? -ne 0 ]; then
einfo "Skipping, no backlight device available"
return 0
fi
fi
eend $?
}
stop() {
ebegin "Saving brightness value"
brightnessctl --class=backlight --quiet get 2>/dev/null > "$save_file"
if [ $? -ne 0 ]; then
einfo "Skipping, no backlight device available"
return 0
fi
eend $?
}