#!/bin/sh
#
# smartcard 1.0 2000/10/10  15:18:16 MET 2000 (Herbert Rosmanith)
#
# Initialize or shutdown the CardMan 4040
#
# The first argument should be either 'start' or 'stop'.  The second
# argument is the device name.
#

################################################################
# Set PCMCIA script path
################################################################
SetPcmciaPath()
{
RETCODE=0
#
#SuSE
#
  if [ -x /sbin/init.d/pcmcia ]; then
    pcmciascript=/sbin/init.d/pcmcia
  fi
#
# Redhat, Mandrake
#
  if [ -x /etc/rc.d/init.d/pcmcia ]; then
    pcmciascript=/etc/rc.d/init.d/pcmcia
  fi
#
# Knoppix (Debian based)
#
  if [ -x /etc/init.d/pcmcia ]; then
    pcmciascript=/etc/init.d/pcmcia
  fi

  if [ "$pcmciascript" = "" ]; then
    RETCODE=1
  fi
  return $RETCODE
}

####################################
# Main
####################################
if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi

# Get device attributes
get_info $DEVICE

# Get device 3-character name
devprefix=`echo $DEVICE | cut -c-3`

maj=`awk "\\$2==\"$devprefix\" {print \\$1}" /proc/devices`
if [ "$maj" = "" ]
then
  echo CardMan 4040 kernel driver not loaded, exiting
  exit
fi
min=`echo $DEVICE | cut -c4-`

SetPcmciaPath
if [ $? -ne 0 ]; then
  echo Could not locate your PCMCIA script file
  exit 1
fi

case $ACTION in
'start')
    rm -f /dev/$DEVICE
    mknod /dev/$DEVICE c $maj $min
    ;;
'check')
    fuser -s /dev/$DEVICE && exit 1 
    ;;
'stop')
    rm -f /dev/$DEVICE
    ;;
'suspend')
    ;;
'resume')
    ;;
*)
    echo Action not supported
    echo usage $0 [start|stop|check] {devicename}
    ;;
esac

exit 0
