home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / etc / init.d / pcmcia < prev    next >
Text File  |  1999-11-12  |  4KB  |  162 lines

  1. #!/bin/sh
  2. #
  3. # rc.pcmcia 1.26 1999/04/15 03:02:41 (David Hinds)
  4. #
  5. # This is designed to work in BSD as well as SysV init setups.  See
  6. # the HOWTO for customization instructions.
  7. # Modified to comply with Debian's standards by Brian Mays <brian@debian.org>.
  8. #
  9. # Modifications to this program were made by Corel Corporation, November, 1999.  All such modifications are copyright (C)
  10. # 1999 Corel Corporation and are licensed under the terms of the GNU General Public License.  
  11.  
  12. usage()
  13. {
  14.     echo "Usage: $0 {start|stop|restart|reload}"
  15. }
  16.  
  17. cleanup()
  18. {
  19.     while read SN CLASS MOD INST DEV EXTRA ; do
  20.     if [ "$SN" != "Socket" ] ; then
  21.         /etc/pcmcia/$CLASS stop $DEV 2> /dev/null
  22.     fi
  23.     done
  24. }
  25.  
  26. # Allow environment variables to override all options
  27. if [ "$PCMCIA" ] ; then readonly PCMCIA ; fi
  28. if [ "$PCIC" ] ; then readonly PCIC ; fi
  29. if [ "$PCIC_OPTS" ] ; then readonly PCIC_OPTS ; fi
  30. if [ "$CORE_OPTS" ] ; then readonly CORE_OPTS ; fi
  31. if [ "$CARDMGR_OPTS" ] ; then readonly CARDMGR_OPTS ; fi
  32. if [ "$SCHEME" ] ; then readonly SCHEME ; fi
  33.  
  34. # Source PCMCIA configuration, if available
  35. if [ -f /etc/pcmcia.conf ] ; then
  36.     . /etc/pcmcia.conf
  37. elif [ -f /etc/sysconfig/pcmcia ] ; then
  38.     . /etc/sysconfig/pcmcia
  39. else
  40.     # Should be either i82365 or tcic
  41.     PCIC=i82365
  42.     # Put socket driver timing parameters here
  43.     PCIC_OPTS=
  44.     # Put pcmcia_core options here
  45.     CORE_OPTS=
  46.     # Put cardmgr options here
  47.     CARDMGR_OPTS=
  48.     # To set the PCMCIA scheme at startup...
  49.     SCHEME=
  50. fi
  51. if [ "$PCMCIA" -a "$PCMCIA" != "yes" ] ; then exit 0 ; fi
  52.  
  53. EXITCODE=1
  54. for x in "1" ; do
  55.  
  56.     if [ "$PCIC" = "" ] ; then
  57.     echo "PCIC not defined in /etc/init.d/pcmcia!"
  58.     break
  59.     fi
  60.  
  61.     if [ $# -lt 1 ] ; then usage ; break ; fi
  62.     action=$1
  63.  
  64.     case "$action" in
  65.  
  66.     'start')
  67.     echo -n "Starting PCMCIA services:"
  68.     SC=/var/lib/misc/pcmcia-scheme
  69.     if [ -L $SC -o ! -O $SC ] ; then rm -f $SC ; fi
  70.     if [ ! -f $SC ] ; then umask 022 ; touch $SC ; fi
  71.     if [ "$SCHEME" ] ; then umask 022 ; echo $SCHEME > $SC ; fi
  72.     fgrep -q pcmcia /proc/devices
  73.     if [ $? -ne 0 ] ; then
  74.         if [ -d /lib/modules/preferred ] ; then
  75.         PC=/lib/modules/preferred/pcmcia
  76.         else
  77.         PC=/lib/modules/`uname -r`/pcmcia
  78.         fi
  79.         if [ -d $PC ] ; then
  80.         echo -n " modules"
  81.         /sbin/insmod $PC/pcmcia_core.o $CORE_OPTS
  82.         /sbin/insmod $PC/$PCIC.o $PCIC_OPTS  || ( rmmod pcmcia_core  ; exit 1 )
  83.         /sbin/insmod $PC/ds.o 2>&1 > /dev/null
  84.         else
  85.         echo " module directory $PC not found."
  86.         break
  87.         fi
  88.     fi
  89.     if [ -s /var/run/cardmgr.pid ] && \
  90.        start-stop-daemon --stop --quiet --signal 0 \
  91.            --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr ; then
  92.         echo " cardmgr is already running."
  93.     else
  94.         if [ -r /var/run/stab ] ; then
  95.         cat /var/run/stab | cleanup
  96.         fi
  97.         echo " cardmgr."
  98.         start-stop-daemon --start --quiet --pidfile /var/run/cardmgr.pid \
  99.         --exec /sbin/cardmgr -- $CARDMGR_OPTS
  100.     fi
  101.     if [ -d /var/lock/subsys ] ; then
  102.         touch /var/lock/subsys/pcmcia
  103.     fi
  104.         sleep 5 #to put it to sleep for 5 seconds
  105.         /etc/init.d/network #Have network up and running after the pcmcia is started. 
  106.     EXITCODE=0
  107.     ;;
  108.  
  109.     'stop')
  110.     echo -n "Shutting down PCMCIA services:"
  111.     start-stop-daemon --stop --quiet \
  112.         --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr
  113.     echo -n " cardmgr"
  114.     # Give cardmgr a few seconds to handle the signal
  115.     start-stop-daemon --stop --quiet --signal 0 \
  116.            --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr && \
  117.     sleep 2 && \
  118.     start-stop-daemon --stop --quiet --signal 0 \
  119.            --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr && \
  120.     sleep 2 && \
  121.     start-stop-daemon --stop --quiet --signal 0 \
  122.            --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr && \
  123.     sleep 2 && \
  124.     start-stop-daemon --stop --quiet --signal 0 \
  125.            --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr
  126.     if fgrep -q "ds  " /proc/modules ; then
  127.         echo -n " modules"
  128.         /sbin/rmmod ds
  129.         /sbin/rmmod $PCIC
  130.         /sbin/rmmod pcmcia_core
  131.     fi
  132.     echo "."
  133.     rm -f /var/lock/subsys/pcmcia
  134.     EXITCODE=0
  135.     ;;
  136.  
  137.     'restart')
  138.     $0 stop
  139.     $0 start
  140.     EXITCODE=0
  141.     ;;
  142.  
  143.     'reload')
  144.     echo "Reloading $DESC configuration files."
  145.     start-stop-daemon --stop --signal 1 --quiet \
  146.         --pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr
  147.     EXITCODE=0
  148.     ;;
  149.  
  150.     *)
  151.     usage
  152.     ;;
  153.  
  154.     esac
  155.  
  156. done
  157.  
  158. # Only exit if we're in our own subshell
  159. if [ "${0##*/}" = "pcmcia" ] ; then
  160.     exit $EXITCODE
  161. fi
  162.