#!/bin/bash
#
# g15daemon          Start/Stop the Logitech G15 daemon.
#
# chkconfig: 2345 99 12
# description: Logitech G15 keyboard daemon
# processname: g15daemon
# pidfile: /var/run/g15daemon.pid

# config settings
[ -f /etc/config.d/g15daemon ] && . /etc/config.d/g15daemon


start() {
  local G15ARG
  if [[ -e /proc/modules && ! -e /dev/input/uinput ]] ; then
    modprobe uinput
  fi
  G15ARG=""
  if [ "$CLIENT_SWITCH_L1" == "yes" ]; then
      G15ARG="-s"
  fi
  echo -n "Starting g15daemon: "
  /usr/sbin/g15daemon $G15ARG &&
  echo -e $RESULT_OK || echo -e $RESULT_FAIL
}

stop() {
  local G15ARG
  G15ARG="-k"
  if [ "$BACKLIGHT_OFF" == "yes" ]; then
    G15ARG="-K"
  fi
  echo -n "Stopping g15daemon: "
  /usr/sbin/g15daemon $G15ARG > /dev/null &&
  echo -e $RESULT_OK || echo -e $RESULT_FAIL

  # Give the system time to unload in case someone call start|stop to quickly
  sleep 2
}

restart() {
  $0 stop
  $0 start
}

. /lib/lsb/init-functions
