#!/bin/sh
#
### BEGIN INIT INFO
# Provides: weston
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description:	Start Weston
# Description:			Start Weston on tty1 with /etc/xdg/weston/weston.ini as configuration file
### END INIT INFO

if test -e /etc/default/weston ; then
        . /etc/default/weston
fi

killproc() {
        pid=`/bin/pidof $1`
        [ "$pid" != "" ] && kill $pid
}

read CMDLINE < /proc/cmdline
for x in $CMDLINE; do
        case $x in
        weston=false)
		echo "Weston disabled"
		exit 0;
                ;;
        esac
done

WESTON_BIN=/usr/bin/weston-start
WESTON_ARGS="--tty=1"
WESTON_PID=/var/run/weston.pid

start_weston() {
	printf "Starting Weston: "
	start-stop-daemon -b -S -q -m -p ${WESTON_PID} --exec ${WESTON_BIN} -- ${WESTON_ARGS} ${OPTARGS}
	echo "OK"
}

stop_weston() {
	printf "Stoping Weston: "
	start-stop-daemon -K -q -p ${WESTON_PID}
	echo "OK"
}

case "$1" in
  start)
	. /etc/profile
	start_weston

  ;;

  stop)
	stop_weston
  ;;

  restart)
	stop_weston
	sleep 1
	start_weston
  ;;

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

exit 0
