summaryrefslogtreecommitdiff
path: root/bin/extra/saveself
blob: 90eba98f904aa6b4cf9771c0be875e426ba09de4 (plain) (blame)
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
#!/bin/sh

Threshold=5

GetBatteryCapacity()
{
	File="$(find /sys/class/power_supply \
		-maxdepth 1 \
		-type l \
		-name 'BAT*' |
		head -n 1)"
	cat "$File"/capacity
}

PrevCapacity="$(GetBatteryCapacity)"
[ "$PrevCapacity" ] || exit 1

while true
do
	Capacity="$(GetBatteryCapacity)"
	if [ "$Capacity" -lt "$PrevCapacity" ] 
	then
		if [ "$Capacity" -le "$Threshold" ]
		then
			HostName="$(hostname)"
			if [ "$HostName" = "spring" ]
			then
				setsid doas /usr/sbin/zzz -Z
			fi
		fi
		PrevCapacity="$Capacity"
	fi
done