#!/bin/sh
# BK jan 2008 for Puppy Linux GPL
#based on script from slackware.

DRIVER=probe
DRIVER_OPTS=

case "$1" in
 start)
  #/etc/rc.d/rc.modules should have already loaded a base PCMCIA module...
  if [ "`lsmod | grep -E '^yenta_socket|^i82365|^tcic'`" != "" ];then
  
   #w003 comment out, as this now done in /etc/udev/rules.d/85-pcmcia.rules
   #(which is in pcmciautils pkg, same as this script)
   #echo "Starting PCMCIA services:"
   #pcmcia-socket-startup
   echo #dummy line.

#v4.01 now have /etc/rc.modules2 and /sbin/pup_eventd that load correct modules...
#  #v3.96 temp until get udev working...
#  if [ "`ls -1 /sys/bus/pcmcia/devices/`" != "" ];then
#   for ONEPCMCIA in `ls -1 /sys/bus/pcmcia/devices/ | tr '\n' ' '`
#   do
#    [ ! -e /sys/bus/pcmcia/devices/$ONEPCMCIA/modalias ] && continue #precaution
#    MODALIAS="`cat /sys/bus/pcmcia/devices/$ONEPCMCIA/modalias`"
#    REALMOD="`modprobe.bin --show-depends $MODALIAS | tail -n 1`"
#    if [ "$REALMOD" != "" ];then
#     REALNAME="`basename $REALMOD .ko`"
#     /sbin/modprobe $REALNAME
#    else
#     PROD_ID1="`cat /sys/bus/pcmcia/devices/$ONEPCMCIA/prod_id1`"
#     PROD_ID2="`cat /sys/bus/pcmcia/devices/$ONEPCMCIA/prod_id2`"
#     #database_old is a hacked file out of the old pcmcia-cs package...
#     cat /etc/pcmcia/database_old | grep "\"${PROD_ID1}\"" | grep "\"${PROD_ID2}\"" | grep -o '| bind .*' | tr ',' ' ' | tr ' ' '\n' | grep '^"' | tr '"' ' ' | tr '\n' ' ' > /tmp/pcmciamodules
#     sync
#     for ONEPCMOD in `cat /tmp/pcmciamodules`
#     do
#      modprobe $ONEPCMOD
#     done
#    fi
#   done
#  fi

  fi
 ;;

 stop)
	        echo -n "Shutting down PCMCIA services: "
		echo -n "cards "
		/sbin/pccardctl eject
		MODULES=`/sbin/lsmod | grep "pcmcia " | awk '{print $4}' | tr , ' '`
		for i in $MODULES ; do
			echo -n "$i "
			/sbin/modprobe -r $i > /dev/null 2>&1
		done
		echo -n "pcmcia "
		/sbin/modprobe -r pcmcia > /dev/null 2>&1
		if [ "$DRIVER" = "probe" ]; then
			for DRV in yenta_socket i82365 tcic ; do
				grep -qw $DRV /proc/modules && modprobe -r $DRV && \
					echo -n "$DRV " && break
			done
		else	
			/sbin/modprobe -r $DRIVER > /dev/null 2>&1
		fi
		echo -n "rsrc_nonstatic "
		/sbin/modprobe -r rsrc_nonstatic > /dev/null 2>&1
		echo "pcmcia_core"
		/sbin/modprobe -r pcmcia_core > /dev/null 2>&1
		;;
	
 restart)
  $0 stop
  $0 start
 ;;
esac
