#!/bin/sh

# code taken from rc.shutdown
### 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="$(echo "$xline" | sed 's/.*-auth //;s/ .*//')"
		[ "$XAUTHORITY" ] && [ -e "$XAUTHORITY" ] && export XAUTHORITY		
	fi
}

get_DISPLAY
exec wmexit poweroff
