#!/bin/sh
########################################################################
# Begin gpm
#
# Description : Handles the gpm daemon.
#
# Authors     : Gerard Beekmans - 
#             : Mark Hymers - 
#             : D. Nicholson
# Update      : Jonathan Oksman - jonathan.oksman@gmail.com
#
# Version     : BLFS (Development)
#
# Notes       : Based off version from blfs-bootscripts-20100825
#
########################################################################

### BEGIN INIT INFO
# Provides:            gpm
# Required-Start:
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   General Purpose Mouse (gpm)
# Description:         The gpm mouse service provides console mouse support.
# X-LFS-Provided-By:   BLFS
### END INIT INFO

. /lib/lsb/diodus-functions

if [ -f /etc/sysconfig/mouse ]; then
  . /etc/sysconfig/mouse
else
  msg="\nFAILURE:\n\n/etc/sysconfig/mouse was not found.\n"
  msg="${msg}Please create this configuration file with\n"
  msg="${msg}MDEVICE and PROTOCOL values to use gpm."
  log_failure_msg $msg
  exit 1
fi

if [ -z "$MDEVICE" ] || [ -z "$PROTOCOL" ]; then
  msg="\nFAILURE:\n\n/etc/sysconfig/mouse is not completely configured.\n"
  msg="${msg}Please edit this configuration file with\n"
  msg="${msg}MDEVICE and PROTOCOL values to use gpm."
  msg=""
fi

case "${1}" in
   start)
      log_info_msg "Starting gpm..."
      start_daemon /usr/sbin/gpm -m $MDEVICE -t $PROTOCOL $GPMOPTS
      pid=`pidofproc /usr/sbin/gpm`
      if [ -z "$pid" ]; then
        log_failure_msg
      else
        log_success_msg
      fi
      ;;

   stop)
      log_info_msg "Stopping gpm..."
      killproc /usr/sbin/gpm
      evaluate_retval
      ;;

   restart)
      ${0} stop
      sleep 1
      ${0} start
      ;;

   status)
      status_proc /usr/sbin/gpm
      ;;

   *)
      echo "Usage: ${0} {start|stop|restart|status}"
      exit 1
      ;;
esac

exit 0

# End gpm
