#!/bin/sh
#
# /etc/acpi/btn-power.sh
# BASH script which acts when the 'power button' is pressed, causing
#   - shutdown
#
# Useful infos at
#   - http://acpi.sourceforge.net/documentation/sleep.html
#
# (C) 2004 - Gismo / Luca Capello <luca.pca.it> http://luca.pca.it

# shutdown
echo "Checking if resuming from S1..."
if tail -n 5 /var/log/messages | grep 'Restarting tasks... done'
then
	echo "Resuming from S1, so not acting, exited."
	exit 0
else
	echo "Shutdown in progress"
fi

if ps -Af | grep -q '[k]desktop' && test -f /usr/bin/dcop
then
    dcop --all-users ksmserver ksmserver logout 0 2 0 && exit 0
fi
/sbin/init 0
