#!/bin/bash
# Time-stamp: <2008-09-02 11:31:18 kojima>

# This file is derived from  avahi.
# Start/stop/restart daemon in init.d/XXXX

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="gpm(General Purpose Mouse)"
NAME="gpm"
DAEMON1="/usr/sbin/gpm -m /dev/input/mice -t imps2"
DAEMON2="/usr/bin/gpm-root"

start()
{
  echo "Starting $DESC:  $DAEMON "
  $DAEMON1 &
  $DAEMON2 &
}

status()
{
  chk=`ps axww | gawk '{print $5}' | grep $NAME`
  if [ "$chk.x" != ".x" ]; then
      return 0
  else
      return 1
  fi
}

stop()
{

  if ( ! status ); then
     echo "$DESC seems already stopped"
  else
     echo "Stopping $DESC: "
     killall gpm
     killall gpm-root
  fi
}

restart()
{
  stop
  start
}

case "$1" in
'start')
  if ( ! status ); then
    start
  else
    echo "$DESC is already running (will not start it twice)."
  fi
  ;;
'stop')
  stop
  ;;
'restart')
  restart
  ;;
'status')
  if ( status ); then
    echo "$DESC is currently running"
  else
    echo "$DESC is not running."
  fi
  ;;
*)
  echo "usage $0 start|stop|status|restart"
esac
