gentoo-ebuilds/sys-apps/asahi-scripts/files/asahi-scripts-macsmc-battery.openrc
James Calligeros 41807551ba
sys-apps/asahi-scripts: add 20240822
Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
Signed-off-by: Sam James <sam@gentoo.org>
2024-11-17 05:20:45 +00:00

51 lines
986 B
Text

#!/sbin/openrc-run
# Save and restore the SMC's charge end threshold
extra_commands="save restore"
depend() {
need udev
}
has_battery() {
if [ ! -e /sys/class/power_supply/macsmc-battery ]; then
eerror "macsmc-battery was not found!"
return 2
fi
return 0
}
restore() {
ebegin "Restoring macsmc-battery saved charge end threshold"
has_battery || return $?
if [ ! -e /etc/udev/macsmc-battery.conf ]; then
ewarn "No saved charge end threshold found! Saving current value..."
save
return $?
fi
sed -e 's/CHARGE_CONTROL_END_THRESHOLD=//' /etc/udev/macsmc-battery.conf > /sys/class/power_supply/macsmc-battery/charge_control_end_threshold
return 0
}
save() {
ebegin "Saving current macsmc-battery charge end threshold"
has_battery || return $?
sed -e 's/^/CHARGE_CONTROL_END_THRESHOLD=/' /sys/class/power_supply/macsmc-battery/charge_control_end_threshold > /etc/udev/macsmc-battery.conf
return 0
}
start() {
restore
eend $?
}
stop() {
save
eend $?
}