#!/bin/bash
# This script is intended to automatically shutdown the computer $wait_time
# minutes after transitioning from being plugged in to running on battery
# power. This was added manually, by the advice of Jordan_U in #ubuntu
# on irc.freenode.net .
wait_time=5
if [[ "$1" == "true" ]]; then
# We're transitioning to battery power, trigger delayed shutdown.
shutdown -h "+${wait_time}" "Shutdown triggered by /etc/pm/power.d/99_auto_shutdown because AC power was lost." & disown
else
# Power came back, cancel shutdown.
# Note, this may cancel a shutdown that was trigged by means other than
# this script. Use at your own risk.
shutdown -c "Shutdown canceled by /etc/pm/power.d/99_auto_shutdown as laptop AC power was restored."
fi
exit 0