#!/bin/sh
set -e
. /lib/lsb/init-functions

# init script for SNESpad joystick support
# 2005.05.14 - Tyler J. Wagner
# http://www.tolaris.com/snes-to-parallel
#
# To install, copy this file to /etc/init.d, then run the following commands:
#   update-rc.d snespad defaults
#   /etc/init.d/snespad start
#
# Modify the following command, depending on your controller design.
# Syntax is:
#
#   map=port,pad1,pad2,pad3,pad4,pad5
#
# Where "map" is the parallel port number (zero for most PCs) and padX
# refers to controllers one through five (Linux controller pinout).
#
# Default assumes all five controllers.

STARTCMD="modprobe gamecon map=0,1,1,1,1,1"
STOPCMD="modprobe -r gamecon"

# List of modules to disable before starting and enable after stopping.
# By default, the lp module must be disabled to free the parallel port.
# This will break printing by parallel port.

PRESTARTCMD="modprobe -r lp"
POSTSTOPCMD="modprobe lp"

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
  start)
    log_success_msg "Starting SNESpad driver... "
    $PRESTARTCMD
    $STARTCMD
    ;;
  stop)
    log_success_msg "Stopping SNESpad driver... "
    $STOPCMD
    $POSTSTOPCMD
    ;;
  restart)
    log_success_msg "Restarting SNESpad driver... "
    $STOPCMD
    $PRESTARTCMD
    $STARTCMD
    ;;
  *)
    log_success_msg "Usage: $0 {start|stop|restart}"
    exit 1
    ;;
esac

log_end_msg 0
