#!/bin/sh

# This script was provided for those systems with broken APM and those
# systems with problem cards that cannot handle a suspend/resume cycle.
# The average user will not need to activate it.  Systems with broken
# APM will not correctly issue a "cardctl suspend" and "cardctl resume"
# during a suspend/resume cycle.  However, the apm daemon can be used
# to run this script which will properly power down and power up your
# cards.  Some drivers, notably the PCMCIA SCSI drivers, cannot recover
# from a suspend/resume cycle.  When using a PCMCIA SCSI card, always
# use "cardctl eject" prior to suspending the system.  This script can
# be used to issue the eject command and other necessary commands, such
# as unmounting filesystems, etc.
#
# To activate this script, create a file /etc/pcmcia/apm.opts.  This
# file should contain one line.  Either
#
# APM=suspend
#
# if the PCMCIA cards are supposed to be suspended before the system is
# suspended or
#
# APM=eject
#
# if the PCMCIA cards are supposed to be ejected before the system is
# suspended.

# name        : pcmcia
# author      : Craig Markwardt <craigm@lheamail.gsfc.nasa.gov>
#               David Brownell <db@post.harvard.edu>
# modified    : Matthias Grimm <matthiasgrimm@users.sourceforge.net>
# description : handle PCMCIA cards with broken APM
# requirements: cardctl in path
# limitations : 
#
# --- end of public part -- don't change below this line ---

# source configuration
. pmcs-config

if [ -r /etc/pcmcia/apm.opts ]; then
  . /etc/pcmcia/apm.opts
  general_PCMCIAShutdown=$APM
fi
  
case "$1" in
  powersave)
    ;;
  custom)
    ;;
  performance)
    ;;
  suspend)
    case "$general_PCMCIAShutdown" in
      suspend)
        # May be necessary to prevent system freeze if pcmcia
        # network card is in.
	#/sbin/ifconfig eth0 down # prevent "card busy"
	cardctl suspend
	;;
      eject)
        # May be necessary to prevent system freeze if pcmcia
        # network card is in.
	#/sbin/ifconfig eth0 down # prevent "card busy"
	cardctl eject
	;;
    esac
    ;;
  resume)
    case "$general_PCMCIAShutdown" in
      suspend)
        cardctl resume;;
      eject)
	cardctl insert;;
    esac
    ;;
esac

