#!/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.
# description(es): GPM aade soporte al ratn para aplicaciones Linux \
#               consola como el Midnight Commander.  Tambin permite \
#               operaciones con el ratn de cortar y pegar e incluye soporte \
#               para mens pop-up en la consola.
# description(pt_BR): O GPM adiciona suporte a mouse para aplicaes Linux \
#		      console como o Midnight Commander. Tambm permite \
#		      operaes com o mouse de cortar-e-colar e inclui suporte \
#		      a menus pop-up no console.
#
# processname:	gpm
# pidfile:	/var/run/gpmpid
# config:	/etc/sysconfig/mouse

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

# Get service config
[ -f /etc/sysconfig/mouse ] && . /etc/sysconfig/mouse

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/gpm ]; then
		msg_starting "Gpm"
		OPTIONS=""
		[ -n "$DEVICE" ] && OPTIONS="-m $DEVICE"
		[ -n "$MOUSETYPE" ] && OPTIONS="$OPTIONS -t $MOUSETYPE"
		[ -n "$BAUD_RATE" ] && OPTIONS="$OPTIONS -b $BAUD_RATE"
		[ -n "$CLEAR_LINES" ] && OPTIONS="$OPTIONS -o $CLEAR_LINES"
		[ -n "$BUTTON_SEQ" ] && OPTIONS="$OPTIONS -B $BUTTON_SEQ"
		[ -n "$TAP_BUTTON" ] && OPTIONS="$OPTIONS -g $TAP_BUTTON"
		[ -n "$ACCEL" ] && OPTIONS="$OPTIONS -a $ACCEL"
		[ -n "$DELTA" ] && OPTIONS="$OPTIONS -d $DELTA"
		[ -n "$INTERVAL" ] && OPTIONS="$OPTIONS -i $INTERVAL"
		[ -n "$RESP" ] && OPTIONS="$OPTIONS -r $RESP"
		[ -n "$SAMPLE_RATE" ] && OPTIONS="$OPTIONS -s $SAMPLE_RATE"
		[ -n "$CHARSET" ] && OPTIONS="$OPTIONS -l \"$CHARSET\""
		[ "$BUTTON_COUNT" = "2" ] && OPTIONS="$OPTIONS -2"
		[ "$BUTTON_COUNT" = "3" ] && OPTIONS="$OPTIONS -3"
		if [ -n "$POINTER_VIS" ] && [ "$POINTER_VIS" != "no" ]; then
			OPTIONS="$OPTIONS -p"
		fi
		if [ -n "$REPEATER" ] && [ "$REPEATER" != "no" ]; then
			OPTIONS="$OPTIONS -R"
		fi
		daemon gpm $OPTIONS < /dev/null
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/gpm
	else
		msg_already_running "Gpm"
		RETVAL=1
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/gpm ]; then
		msg_stopping "Gpm"
		killproc gpm
		rm -f /var/lock/subsys/gpm >/dev/null 2>&1
	else
		msg_not_running "Gpm"
		RETVAL=1
	fi	
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  status)
	status gpm
	;;
  *)
	msg_usage "$0 {start|stop|status|restart|reload}"
	RETVAL=1
esac

exit $RETVAL
