#!/bin/sh
#
# $Id: dm,v 1.6 2004/06/12 10:32:53 ldv Exp $
#
# chkconfig: 5 45 05
# description: This startup script launches the graphical display manager

# Source function library.
. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/dm
RETVAL=0

playlist=/store/playlist
lockfile=/var/run/player

start()
{
	msg_starting $"display manager"
	local args=
	echo "0"> /var/run/player
	for f in `sed -ne 's,^\([0-9]\+\):[0-9]\+:respawn:/sbin/mingetty.*,/dev/tty\1,pg' </etc/inittab`; do
		[ ! -c "$f" ] || args="$args $f"
	done
	touch $lockfile
	xinit -e /usr/bin/showreklama >/dev/null 2>/dev/null &
#	start_daemon --lockfile "$LOCKFILE" --expect-user root --no-announce -- /usr/bin/showreklama --
#	while [ `cat $lockfile` = 0 ] ; do xinit -e /usr/bin/mplayer -vo x11 -fs -stop-xscreensaver -zoom `cat $playlist `;done
#	RETVAL=$?
	return $RETVAL
}

stop()
{
	local FGCONSOLE=`absolute fgconsole`
	local CHVT=`absolute chvt`

#	local fgconsole=
#	if [ -x "$FGCONSOLE" ]; then
#		fgconsole=`$FGCONSOLE`
#	fi
	echo "1"> /var/run/player
	rm -rf $lockfile
	killall -s9 xine
	killall -s9 showreklama
	killall -s9 X
	killall -s9 xinit
#	msg_stopping $"display manager"
#	stop_daemon --lockfile "$LOCKFILE" --expect-user root --no-announce -- rundm
#	RETVAL=$?

#	if [ -n "$fgconsole" -a -x "$CHVT" ]; then
#		$CHVT "$fgconsole"
#	fi
	
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload|restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condreload|condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --expect-user root -- rundm
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
