#!/bin/sh

CRIT_CAPACITY=3

acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
	read -r status capacity

	# Do nothing if AC is plugged
	if [ "$status" = Discharging -a "$capacity" -le $CRIT_CAPACITY ]; then
		logger "Critical battery level, hibernating"
    	/usr/sbin/pm-hibernate
	fi
}

