#!/bin/sh

# code taken from rc.shutdown
SLIM_CONF=/etc/slim.conf
### find the local X server of the foreground console 
get_DISPLAY() {
	local xline p
	xline=$(ps -o tty=,args= -C X,Xorg | grep "^tty$(fgconsole)")
	if [ "$xline" ]; then
		DISPLAY=:0
		for p in $xline; do
			case $p in
				*:*) DISPLAY=$p; break ;;
			esac
		done
		export DISPLAY
		XAUTHORITY=$(awk '/^authfile/ { print $2; exit }' $SLIM_CONF)
		[ "$XAUTHORITY" ] && [ -e "$XAUTHORITY" ] && export XAUTHORITY		
	fi
}

get_DISPLAY
exec wmexit poweroff
