]> git.pld-linux.org Git - packages/alsa-utils.git/blob - alsasound.init
- typo
[packages/alsa-utils.git] / alsasound.init
1 #!/bin/sh
2 #
3 # alsasound     This shell script takes care of starting and stopping \
4 #               ALSA sound driver.
5 #
6 # This script requires /usr/sbin/alsactl program from alsa-utils package.
7 #
8 # Copyright (c) by Jaroslav Kysela <perex@jcu.cz> 
9 #
10 #  This program is free software; you can redistribute it and/or modify
11 #  it under the terms of the GNU General Public License as published by
12 #  the Free Software Foundation; either version 2 of the License, or
13 #  (at your option) any later version.
14 #
15 #  This program is distributed in the hope that it will be useful,
16 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #  GNU General Public License for more details.
19 #
20 #  You should have received a copy of the GNU General Public License
21 #  along with this program; if not, write to the Free Software
22 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #
24 #
25 # For PLD Linux Distribution:
26 # chkconfig:    2345 87 14
27 # description:  ALSA driver
28 #
29
30 # Source function library.
31 . /etc/rc.d/init.d/functions
32
33 alsactl=/usr/sbin/alsactl
34
35 if [ $(kernelverser) = "002006" ]; then
36         MODULES_CONF=/etc/modprobe.conf
37 elif [ -r /etc/modules.conf ]; then
38         MODULES_CONF=/etc/modules.conf
39 else
40         MODULES_CONF=/etc/conf.modules
41 fi
42
43 driver_start()
44 {
45   #
46   # insert all sound modules
47   #
48   if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then
49         /sbin/loglevel 1
50   fi
51   awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $2}' < $MODULES_CONF | \
52     while read line; do \
53       msg_starting "sound driver: $line"
54       busy
55       /sbin/modprobe $line
56       ok
57     done
58   awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' < $MODULES_CONF | \
59     while read line; do \
60       msg_starting "sound driver: $line"
61       busy
62       /sbin/modprobe $line
63       ok
64     done
65   if [ -n "$OLDLOGLEV" ]; then
66         /sbin/loglevel "$OLDLOGLEV"
67   fi
68   #
69   # restore driver settings
70   #
71   if [ -x $alsactl ]; then
72     if [ -f /etc/asound.state ]; then
73       $alsactl restore
74     fi
75   else
76     show "ERROR: alsactl not found"; fail
77   fi
78 }
79
80 detect_stop()
81 {
82   #
83   # remove all sound modules
84   #
85   /sbin/lsmod | awk '/^snd/ { print $0 }' | while read line; do \
86      /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
87   done
88 }
89
90 driver_stop()
91 {
92   #
93   # store driver settings
94   #
95   if [ -x $alsactl ]; then
96     $alsactl store
97   else
98     show '!!!alsactl not found!!!'; fail
99   fi
100   #
101   # remove all sound modules
102   #
103   detect_stop
104 }
105
106 detect_start()
107 {
108   #
109   # run only detect module
110   #
111   /sbin/modprobe snd-detect
112 }
113
114 # See how we were called.
115 case "$1" in
116   start)
117         # Start driver.
118         if [ ! -d /proc/asound ]; then
119                 driver_start
120                 if [ -d /proc/asound ]; then
121                         touch /var/lock/subsys/alsasound
122                 else
123                         exit 1
124                 fi
125         else
126                 if [ -f /proc/asound/detect ]; then
127                         show "Shutting down sound detect module:"
128                         detect_stop
129                         ok
130                         driver_start
131                         if [ -d /proc/asound ]; then
132                                 touch /var/lock/subsys/alsasound
133                         else
134                                 exit 1
135                         fi
136                 else
137                         msg_already_running "ALSA driver"
138                 fi
139         fi
140         ;;
141   stop)
142         # Stop daemons.
143         if [ -d /proc/asound ]; then
144                 show "Shutting down sound driver:"
145                 busy
146                 if [ -f /proc/asound/detect ]; then
147                         detect_stop
148                 else
149                         driver_stop
150                 fi
151                 (rmmod isapnp; rmmod soundcore) 2> /dev/null
152                 if [ -d /var/lock/subsys ]; then
153                         rm -f /var/lock/subsys/alsasound
154                 fi
155                 ok
156         else
157                 msg_not_running "ALSA driver"
158         fi
159         ;;
160   restart|force-reload)
161         $0 stop
162         $0 start
163         exit $?
164         ;;
165   status)
166         # TODO
167         ;;
168   *)
169         msg_usage "$0 {start|stop|restart|force-reload|status}"
170         exit 3
171 esac
172
173 exit 0
This page took 0.035027 seconds and 3 git commands to generate.