check_battery (652B)
1 #!/bin/sh 2 3 readonly CAPACITY="$(cat /sys/class/power_supply/BAT0/capacity)" 4 5 if [ "$(cat /sys/class/power_supply/BAT0/status)" = "Discharging" ]; then 6 exit 0 7 fi 8 9 if [ "${CAPACITY}" -ge 0 ] && [ "${CAPACITY}" -le 1 ]; then 10 notify-send --urgency critical "CRITICAL BATTERY" \ 11 "Battery capacity is ${CAPACITY}%, hibernating in 30 seconds." 12 paplay /usr/share/sounds/woodenbeaver/stereo/battery-low.ogg 13 sleep 30 14 systemctl hibernate 15 elif [ "${CAPACITY}" -ge 5 ] && [ "${CAPACITY}" -le 10 ]; then 16 notify-send --urgency low "LOW BATTERY" "Battery capacity is ${CAPACITY}%." 17 paplay /usr/share/sounds/woodenbeaver/stereo/battery-low.ogg 18 fi