#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          kdm-gdmcompat
# Required-Start:    $remote_fs $syslog kdm
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts GDM emulation daemon.
# Description:       Starts the GDM emulation daemon gdm-emulator to provide
#                    the gdm control socket.
### END INIT INFO
#
# Copyright (C) 2007, 2008 Fabian Knittel
# Licensed under the GNU General Public License; either version 2 of the
# license, or (at your option) any later version.  See the file
# /usr/share/common-licenses/GPL-2 or <http://www.gnu.org/licences/gpl-2.0.txt>.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/gdm-emulatord
DAEMON_OPTS=""
NAME=gdm-emulatord
DESC="GDM emulation daemon for KDM"
PID_FILE=/var/run/$NAME.pid
DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

start_daemon() {
	start-stop-daemon --start --quiet --pidfile $PID_FILE \
		--exec $DAEMON -- $DAEMON_OPTS
}

stop_daemon() {
	start-stop-daemon --stop --quiet --pidfile $PID_FILE
}

case "$1" in
    start)
	if [ -e $DEFAULT_DISPLAY_MANAGER_FILE ] &&
           [ "$(cat $DEFAULT_DISPLAY_MANAGER_FILE)" != "/usr/bin/kdm" ]; then
            echo -n "Not starting $DESC; "
	    echo "kdm is not the default display manager."
	else
	    log_begin_msg "Starting $DESC"
	    start_daemon
	    log_end_msg 0
	fi
	;;
    stop)
	log_begin_msg "Stopping $DESC"
	stop_daemon
	log_end_msg 0
	;;
  restart|force-reload)
	log_begin_msg "Restarting $DESC"
	stop_daemon
	sleep 1
	start_daemon
	log_end_msg 0
	;;
  status)
	status_of_proc $DAEMON "$DESC" -p $PID_FILE
	exit $?
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0
