#!/bin/sh
#
# chkconfig: 2345 85 15
# description: GPM adds mouse support to text-based Linux applications such \
#              the Midnight Commander. Is also allows mouse-based console \
#              cut-and-paste operations, and includes support for pop-up \
#              menus on the console.
# processname: gpm
# pidfile: /var/run/gpm.pid
# config: /etc/sysconfig/mouse

# source function library
. /etc/rc.d/init.d/functions

MOUSECFG=/etc/sysconfig/mouse
LOCKFILE=/var/lock/subsys/gpm
RETVAL=0

start()
{
	echo -n "Starting console mouse services: "
	if [ -f "$MOUSECFG" ]; then
		. "$MOUSECFG"
	else
		echo "(no mouse is configured)"
		exit 0
	fi

	if [ "$MOUSETYPE" = "none" ]; then
		echo "(no mouse is configured)"
		exit 0
	fi

	if [ "$MOUSETYPE" = "Microsoft" ]; then
		MOUSETYPE=ms
	fi

	if [ -n "$MOUSETYPE" ]; then
		daemon gpm -m /dev/$device -t $MOUSETYPE
	else
		daemon gpm -m /dev/$device
	fi

	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
}

stop()
{
	echo -n "Shutting down console mouse services: "
	killproc gpm

	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
}

restart()
{
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	condstop)
		if [ -f "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -f "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status gpm
		RETVAL=$?
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
