home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / init.d / alsasound < prev    next >
Text File  |  2006-05-02  |  5KB  |  219 lines

  1. #!/bin/sh
  2. #
  3. # alsasound     This shell script takes care of starting and stopping
  4. #               the ALSA sound driver.
  5. #
  6. # This script requires /usr/sbin/alsactl program from alsa-utils package.
  7. #
  8. # Copyright (c) by Jaroslav Kysela <perex@suse.cz> 
  9. #
  10. #
  11. #  This program is free software; you can redistribute it and/or modify
  12. #  it under the terms of the GNU General Public License as published by
  13. #  the Free Software Foundation; either version 2 of the License, or
  14. #  (at your option) any later version.
  15. #
  16. #  This program is distributed in the hope that it will be useful,
  17. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. #  GNU General Public License for more details.
  20. #
  21. #  You should have received a copy of the GNU General Public License
  22. #  along with this program; if not, write to the Free Software
  23. #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. #
  25. #
  26. # For RedHat 5.0+:
  27. # chkconfig: 2345 87 14
  28. # description: ALSA driver
  29. #
  30. # modified to visually fit into SuSE 6.0+ by Philipp Thomas <pthomas@suse.de>
  31. # further improvements by Bernd Kaindl, Olaf Hering and Takashi Iwai.
  32. ### BEGIN INIT INFO
  33. # Provides:       alsasound
  34. # Required-Start: $remote_fs resmgr
  35. # Required-Stop: $remote_fs resmgr
  36. # Default-Start:  2 3 5
  37. # Default-Stop:
  38. # Description:    Loading ALSA drivers and store/restore the current setting
  39. ### END INIT INFO
  40.  
  41. . /etc/rc.status
  42. . /etc/sysconfig/sound
  43.  
  44. # Shell functions sourced from /etc/rc.status:
  45. #      rc_check         check and set local and overall rc status
  46. #      rc_status        check and set local and overall rc status
  47. #      rc_status -v     ditto but be verbose in local rc status
  48. #      rc_status -v -r  ditto and clear the local rc status
  49. #      rc_failed        set local and overall rc status to failed
  50. #      rc_reset         clear local rc status (overall remains)
  51. #      rc_exit          exit appropriate to overall rc status
  52.  
  53. # First reset status of this service
  54. rc_reset
  55.  
  56. alsactl=/usr/sbin/alsactl
  57. asoundcfg=/etc/asound.state
  58. aconnect=/usr/bin/aconnect
  59. lsmod=/bin/lsmod
  60.  
  61. #
  62. # insert sequencer modules
  63. #
  64. load_sequencer() {
  65.   test "$LOAD_SEQUENCER" = "yes" && modprobe -q snd-seq
  66.   if [ x"$LOAD_SEQUENCER" = xyes -a -r /proc/asound/seq/drivers ]; then
  67.     OLDIFS="$IFS"
  68.     IFS=","
  69.     while read t x c; do
  70.       /sbin/modprobe $t
  71.     done < /proc/asound/seq/drivers
  72.     IFS="$OLDIFS"
  73.   fi
  74. }
  75.  
  76. get_drivers() {
  77.   if [ -f /etc/modprobe.d/sound ]; then
  78.     cat /etc/modprobe.d/sound
  79.   else
  80.     /sbin/modprobe -c
  81.   fi | \
  82.     grep -E "^[[:space:]]*alias[[:space:]]+snd-card-[[:digit:]]" | sort | \
  83.     while read a b card; do
  84.     echo $card
  85.     done
  86. }
  87.  
  88. #
  89. # insert all sound modules
  90. #
  91. load_modules() {
  92.   module_loaded=0
  93.   c=""
  94.   drivers=`get_drivers`
  95.   for i in $drivers; do
  96.     if [ $i != off ]; then
  97.       if [ x$c = x ]; then
  98.         echo -n ": "
  99.     c=1
  100.       fi
  101.       echo -n " ${i##snd-}"
  102.       /sbin/modprobe $i && module_loaded=1
  103.     fi
  104.   done
  105.   rc_status -v -r
  106.   test $module_loaded -eq 0 && return 1
  107.   return 0
  108. }
  109.  
  110. #
  111. # rest of start action
  112. #
  113. start_rest() {
  114.   load_sequencer
  115.   if [ x"$LOAD_OSS_EMUL_MODULES" = xyes ]; then
  116.     /sbin/modprobe snd-pcm-oss
  117.     test x"$LOAD_OSS_SEQ_MODULE" = xyes && /sbin/modprobe snd-seq-oss
  118.   fi
  119. }
  120.  
  121. # manual load and force to store the status
  122. start_all() {
  123.     echo -n "Starting sound driver"
  124.     load_modules && start_rest
  125.     # hack - in case the mixer isn't restored
  126.     (sleep 1; $alsactl -F -f $asoundcfg restore >/dev/null 2>&1)
  127.     rc_status
  128. }
  129.  
  130. terminate() {
  131.   #
  132.   # Kill processes holding open sound devices
  133.   #
  134.   fuser -k /dev/admmidi* /dev/adsp* /dev/amidi* /dev/audio* /dev/dmfm* \
  135.      /dev/dmmidi* /dev/dsp* /dev/dspW* /dev/midi* /dev/mixer* /dev/music \
  136.      /dev/patmgr* /dev/sequencer* /dev/sndstat >/dev/null 2>&1
  137.   if [ -d /dev/snd ]; then
  138.     fuser -k /dev/snd/* >/dev/null 2>&1
  139.   fi
  140.   #
  141.   # remove all sequencer connections if any
  142.   #
  143.   if [ -f /proc/asound/seq/clients -a -x $aconnect ]; then
  144.     $aconnect --removeall
  145.   fi
  146. }
  147.  
  148. # mute master to avoid clicks at unload/shutdown
  149. unmute_system() {
  150.   /usr/bin/amixer set Master mute >/dev/null 2>&1
  151. }
  152.  
  153. #
  154. # remove all sound modules
  155. #
  156. unload_modules() {
  157.   unmute_system
  158.   $lsmod | grep -E "^snd" | grep -Ev "(snd-page-alloc|snd_page_alloc)" | while read m s; do
  159.      /sbin/rmmod $m
  160.   done
  161. }
  162.  
  163. unload_all() {
  164.     echo -n "Shutting down sound driver"
  165.     terminate
  166.     unload_modules
  167.     rc_status -v
  168. }
  169.  
  170. stop_all() {
  171.     if [ -d /proc/asound ]; then
  172.     $alsactl -f $asoundcfg store
  173.         unload_all
  174.     fi
  175. }
  176.  
  177. # See how we were called.
  178. case "$1" in
  179.   start)
  180.     if [ "$PREVLEVEL" = "N" ]; then
  181.         test -d /proc/asound && start_rest
  182.     else
  183.         start_all
  184.     fi
  185.         ;;
  186.   stop)
  187.     if [ "$RUNLEVEL" = "6" ]; then
  188.         if [ -d /proc/asound ]; then
  189.         $alsactl -f $asoundcfg store
  190.         unmute_system
  191.         fi
  192.     else
  193.         stop_all
  194.     fi
  195.         ;;
  196.   unload)
  197.     test -d /proc/asound && unload_all
  198.     ;;
  199.   reload|restart)
  200.     stop_all
  201.     start_all
  202.     ;;
  203.   status)
  204.         if [ -d /proc/asound ]; then
  205.           echo -n "ALSA sound driver loaded."
  206.           rc_status -v
  207.         else
  208.           echo -n "ALSA sound driver not loaded."
  209.       rc_status -u
  210.         fi
  211.         ;;
  212.   *)
  213.     echo "Usage: $0 {start|stop|restart|reload|unload|status}"
  214.         exit 1
  215. esac
  216.  
  217. rc_exit
  218.