#!/bin/bash
#
# Init file for gpm.
#
# Written by Dag Wieers <dag@wieers.com>.
#
# 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
# config: /etc/sysconfig/mouse
# pidfile: /var/run/gpm.pid

source /etc/rc.d/init.d/functions
if [ -e /etc/sysconfig/gpm ]; then
	 source /etc/sysconfig/gpm
fi

MOUSECFG="/etc/sysconfig/mouse"

RETVAL=0
prog="gpm"
desc="console mouse services"

start() {
	echo -n $"Starting $desc ($prog): "
	if [ -f "$MOUSECFG" ]; then
		source "$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 [ -z "$DEVICE" ]; then
	    DEVICE="/dev/mouse"
	fi

	if [ -n "$MOUSETYPE" ]; then
		daemon $prog -m $DEVICE -t $MOUSETYPE $OPTIONS
	else
		daemon $prog -m $DEVICE $OPTIONS
	fi
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}

stop() {
	echo -n $"Shutting down console mouse services: "
	killproc $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
}

restart() {
	stop
	start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	restart
	;;
  condrestart)
	[ -e /var/lock/subsys/$prog ] && restart
	RETVAL=$?
	;;
  status)
	status $prog
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	RETVAL=1
esac

exit $RETVAL
