pcmcia 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/sh
  2. # rc.pcmcia 1.47 2004/09/08 05:34:02 (David Hinds)
  3. #
  4. # This is designed to work in BSD as well as SysV init setups. See
  5. # the HOWTO for customization instructions.
  6. # Tags for Red Hat init configuration tools
  7. #
  8. # chkconfig: 2345 45 96
  9. # processname: cardmgr
  10. # pidfile: /var/run/cardmgr.pid
  11. # config: /etc/pcmcia/config
  12. # config: /etc/pcmcia/config.opts
  13. # description: PCMCIA support is usually to support things like ethernet \
  14. # and modems in laptops. It won't get started unless \
  15. # configured so it is safe to have it installed on machines \
  16. # that don't need it.
  17. # Exit if pcmcia-cs is not installed
  18. test -x /sbin/cardmgr || exit 0
  19. # Save option values passed in through the environment
  20. for N in PCMCIA PCIC PCIC_OPTS CORE_OPTS CARDMGR_OPTS SCHEME ; do
  21. V=`eval echo '$'$N` ; if [ "$V" ] ; then eval ENV_$N=\"$V\" ; fi
  22. done
  23. # Source PCMCIA configuration, if available
  24. if [ -f /etc/pcmcia.conf ] ; then
  25. # Debian startup option file
  26. . /etc/pcmcia.conf
  27. elif [ -f /etc/sysconfig/pcmcia ] ; then
  28. # Red Hat startup option file
  29. . /etc/sysconfig/pcmcia
  30. else
  31. # Slackware startup options go right here:
  32. # Should be either i82365 or tcic
  33. PCIC=i82365
  34. # Put socket driver timing parameters here
  35. PCIC_OPTS=
  36. # Put pcmcia_core options here
  37. CORE_OPTS=
  38. # Put cardmgr options here
  39. CARDMGR_OPTS=
  40. # To set the PCMCIA scheme at startup...
  41. SCHEME=
  42. fi
  43. for N in PCMCIA PCIC PCIC_OPTS CORE_OPTS CARDMGR_OPTS SCHEME ; do
  44. V=`eval echo '$'ENV_$N` ; if [ "$V" ] ; then eval $N=\"$V\" ; fi
  45. done
  46. if [ "$PCMCIA" -a "$PCMCIA" != "yes" ] ; then exit 0 ; fi
  47. usage()
  48. {
  49. echo "Usage: $0 {start|stop|status|restart|reload}"
  50. }
  51. cleanup()
  52. {
  53. while read SN CLASS MOD INST DEV EXTRA ; do
  54. if [ "$SN" != "Socket" ] ; then
  55. /etc/pcmcia/$CLASS stop $DEV 2> /dev/null
  56. fi
  57. done
  58. }
  59. EXITCODE=1
  60. for x in "1" ; do
  61. if [ "$PCIC" = "" ] ; then
  62. echo "PCIC module not defined in startup options!"
  63. break
  64. fi
  65. if [ $# -lt 1 ] ; then usage ; break ; fi
  66. action=$1
  67. case "$action" in
  68. start)
  69. echo -n "Starting PCMCIA services: "
  70. if [ -d /var/lib/pcmcia ] ; then
  71. SC=/var/lib/pcmcia/scheme
  72. RUN=/var/lib/pcmcia
  73. else
  74. SC=/var/run/pcmcia-scheme
  75. RUN=/var/run
  76. fi
  77. if [ -L $SC -o ! -O $SC ] ; then rm -f $SC ; fi
  78. if [ ! -f $SC ] ; then umask 022 ; touch $SC ; fi
  79. if [ "$SCHEME" ] ; then umask 022 ; echo $SCHEME > $SC ; fi
  80. if ! grep -q pcmcia /proc/devices ; then
  81. if [ -d /lib/modules/preferred ] ; then
  82. PC=/lib/modules/preferred/pcmcia
  83. else
  84. PC=/lib/modules/`uname -r`/pcmcia
  85. fi
  86. if [ -x /sbin/modprobe ] ; then
  87. /sbin/modprobe pcmcia_core $CORE_OPTS || break
  88. /sbin/modprobe $PCIC $PCIC_OPTS >/dev/null 2>&1 ||
  89. (/sbin/modprobe yenta_socket >/dev/null 2>&1 &&
  90. echo "using yenta_socket instead of $PCIC") ||
  91. /sbin/modprobe $PCIC $PCIC_OPTS || break
  92. /sbin/modprobe ds || break
  93. elif [ -d $PC ] ; then
  94. /sbin/insmod $PC/pcmcia_core.o $CORE_OPTS
  95. /sbin/insmod $PC/$PCIC.o $PCIC_OPTS
  96. /sbin/insmod $PC/ds.o
  97. else
  98. echo "module directory $PC not found."
  99. break
  100. fi
  101. fi
  102. if [ -s /var/run/cardmgr.pid ] && \
  103. kill -0 `cat /var/run/cardmgr.pid` 2>/dev/null ; then
  104. echo "cardmgr is already running."
  105. else
  106. if [ -r $RUN/stab ] ; then
  107. cat $RUN/stab | cleanup
  108. fi
  109. /sbin/cardmgr $CARDMGR_OPTS
  110. fi
  111. echo "done."
  112. touch /var/lock/subsys/pcmcia 2>/dev/null
  113. EXITCODE=0
  114. ;;
  115. stop)
  116. echo -n "Shutting down PCMCIA services: "
  117. if [ -s /var/run/cardmgr.pid ] ; then
  118. PID=`cat /var/run/cardmgr.pid`
  119. kill $PID
  120. # Give cardmgr a few seconds to handle the signal
  121. for N in 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 ; do
  122. kill -0 $PID 2>/dev/null || break
  123. sleep 2
  124. done
  125. fi
  126. killall -q "CardBus Watcher"
  127. if grep -q "^ds " /proc/modules ; then
  128. /sbin/rmmod ds
  129. /sbin/rmmod $PCIC 2>/dev/null || \
  130. /sbin/rmmod yenta_socket 2>/dev/null
  131. /sbin/rmmod pcmcia_core
  132. fi
  133. echo "done."
  134. rm -f /var/lock/subsys/pcmcia
  135. EXITCODE=0
  136. ;;
  137. status)
  138. pid=`/sbin/pidof cardmgr`
  139. if [ "$pid" != "" ] ; then
  140. echo "cardmgr (pid $pid) is running..."
  141. EXITCODE=0
  142. else
  143. echo "cardmgr is stopped"
  144. EXITCODE=3
  145. fi
  146. ;;
  147. restart|reload)
  148. $0 stop
  149. $0 start
  150. EXITCODE=$?
  151. ;;
  152. *)
  153. usage
  154. ;;
  155. esac
  156. done
  157. # Only exit if we're in our own subshell
  158. case $0 in *rc.pcmcia) exit $EXITCODE ;; esac