summaryrefslogtreecommitdiff
path: root/sys-apps/asahi-scripts/files/asahi-scripts-macsmc-battery.openrc
blob: 19e8363116fdc8ecb35a23575dd038cf5c1915c7 (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
#!/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 $?
}