2015-05-29 21:08:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#Config
|
|
|
|
WARNING_LEVEL=10
|
|
|
|
SHUTDOWN_LEVEL=2
|
|
|
|
#End config
|
|
|
|
|
|
|
|
|
|
|
|
STATE=0
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
level=$(acpi -b | awk -F, 'BEGIN{s=0}{s+=$2}END{print int(s/NR)}')
|
|
|
|
charger_connected=$(acpi -b | grep Charging)
|
|
|
|
case "$STATE" in
|
|
|
|
0) # battery ok
|
|
|
|
if [ "$level" -le "$WARNING_LEVEL" -a -z "$charger_connected" ]; then
|
|
|
|
zenity --warning --text="Your battery is getting low\!" --no-wrap &
|
|
|
|
STATE=1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
1) # battery low
|
|
|
|
if [ -n "$charger_connected" ]; then
|
|
|
|
STATE=0
|
|
|
|
elif [ "$level" -le "$SHUTDOWN_LEVEL" ]; then
|
|
|
|
systemctl hibernate;
|
|
|
|
else
|
|
|
|
notify-send -u critical -a "BatterySystem" "Battery is low!" "Please connect a charger"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2015-09-08 05:54:48 +02:00
|
|
|
sleep 2m
|
2015-05-29 21:08:06 +02:00
|
|
|
done
|
|
|
|
|