#!/bin/sh

set -e

export DISPLAY=:0.0

killproc() {            # kill the named process(es)
        pid=`/bin/ps -e x |
             /bin/grep $1 |
             /bin/grep -v grep |
             /bin/sed -e 's/^  *//' -e 's/ .*//'`
        [ "$pid" != "" ] && kill $pid
}

case "$1" in
  start)
	echo "Starting X"
	/usr/bin/x-window-manager
  ;;

  stop)
        echo "Stopping X"
        killproc /usr/bin/x-window-manager
	dd if=/dev/zero of=/dev/fb0 2>/dev/null || dd if=/dev/zero of=/dev/fb/0 2>/dev/null
  ;;

  *)
        echo "usage: $0 { start | stop }"
  ;;
esac

exit 0
