-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbattboy.sh
More file actions
executable file
·49 lines (37 loc) · 1.04 KB
/
battboy.sh
File metadata and controls
executable file
·49 lines (37 loc) · 1.04 KB
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
#!/bin/bash
# for thinkpads with multiple batteries
# by default BAT0 completely discharges completely before engaging BAT1
# gtk/xfce/etc battery managers do not handle laptops with two batteries
# very well
# wip
path="/sys/devices/platform/smapi"
batts="BAT0 BAT1"
threshold="15" # when to flip it
ac=$(cat $path/ac_connected) # are we plugged in?
lockfile="/tmp/batboy" # make it cronable
if [ -e $lockfile ]; then
echo -e "lockfile $lockfile exists: we're already acting on the battery"
exit 0
fi
for batt in $batts; do
if [ -d $path/$batt ]; then
energy_per=$(cat $path/$batt/remaining_percent)
if [ $energy_per -lt $threshold ]; then
if [ $ac -eq 0 ]; then
echo "$batt less than $threshold percent! flipping it off, sorry"
echo "$batt " >> $lockfile
echo 0 > $path/$batt/force_discharge
else
echo "we're still charging $batt."
fi
else
if [ $ac -eq 0 ]; then
echo cool $batt still at $energy_per percent
else
rm -f $lockfile
fi
fi
else
echo "no $batt found"
fi
done