#!/bin/sh -e
#
#    powernap - have the system "take a nap"; this can be a user defined
#               program or script at /etc/powernap/action, or a best-
#               effort action among:
#                 1) suspend
#                 2) hibernate
#                 3) poweroff
#
#    Copyright (C) 2009 Canonical Ltd.
#
#    Authors: Dustin Kirkland <kirkland@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


PKG="powernap"

# Use the specified action, if configured
# Otherwise, use the best available, supported sleep state
if [ -x "/etc/$PKG/action" ]; then
	exec /etc/$PKG/action
elif pm-is-supported --suspend; then
	exec /usr/sbin/pm-suspend
elif pm-is-supported --hibernate; then
	exec /usr/sbin/pm-hibernate
else
	exec /sbin/poweroff
fi
