#!/bin/sh

# sqp_JogglerPower v1.09 (21st June 2012) by Andy Davison
#  Executed by JogglerPower and Quit applets.

PLATFORM=`cat /tmp/sqp_platform`
[ "$PLATFORM" = "native" ] || export PATH=$PATH:`dirname $0`

if [ "$1" = "platform" ]; then
	echo -n $PLATFORM
	exit 0
fi

if [ "$1" = "quit" ]; then

	xset -display :0.0 dpms 0 0 0
	sqp_JogglerBacklight.sh `cat /tmp/sqp_initial_bl` &

	if [ "$PLATFORM" != "native" ] && [ "$PLATFORM" != "sqpos" ]; then
		/usr/bin/gnome-power-manager &
		togglepanel.sh show
	fi

fi

if [ "$1" = "relaunch" ]; then

	if [ "$PLATFORM" = "sqpos" ]; then
		
		sleep 2
		killall jive
		
	else
		
		exit 0
		
	fi

fi

if [ "$1" = "reboot" ]; then

	if [ "$PLATFORM" = "native" ]; then
		
		reboot
		
	elif [ "$PLATFORM" = "sqpos" ]; then
		
		sleep 2
		sudo reboot
		
	else
		
		sleep 2
		sudo reboot
		
	fi

fi

if [ "$1" = "halt" ] || [ "$1" = "poweroff" ]; then

	if [ "$PLATFORM" = "native" ]; then
		
		halt
		
	elif [ "$PLATFORM" = "sqpos" ]; then
				
		sleep 2
		sudo poweroff
		
	else
		
		sleep 2
		sudo poweroff
		
	fi

fi

exit 0