]> git.pld-linux.org Git - packages/alsa-utils.git/blob - alsasound.init
- use modprobe -c to get modprobe config (so alsaconf generated /etc/modprobe.d/sound...
[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 driver_start()
34 {
35   #
36   # insert all sound modules
37   #
38   if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then
39         /sbin/loglevel 1
40   fi
41   modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $2}' | \
42     while read line; do \
43       msg_starting "sound driver: $line"
44       busy
45       /sbin/modprobe $line
46       ok
47     done
48   modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' | \
49     while read line; do \
50       msg_starting "sound driver: $line"
51       busy
52       /sbin/modprobe $line
53       ok
54     done
55   if [ -n "$OLDLOGLEV" ]; then
56         /sbin/loglevel "$OLDLOGLEV"
57   fi
58   #
59   # restore driver settings
60   #
61   if [ -x /usr/sbin/alsactl ]; then
62     if [ -f /etc/asound.state ]; then
63       if [ "$(kernelver)" -lt "002006012" ]; then
64         for i in 1 2 3 4; do
65           [ -a /dev/snd/controlC0 ] && break
66           sleep 1
67         done
68       fi
69       /usr/sbin/alsactl restore
70     fi
71   else
72     show "ERROR: alsactl not found"; fail
73   fi
74 }
75
76 detect_stop()
77 {
78   #
79   # remove all sound modules
80   #
81   /sbin/lsmod | awk '/^(snd|ac97_bus)/ { print $0 }' | while read line; do \
82      /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
83   done
84 }
85
86 driver_stop()
87 {
88   #
89   # store driver settings
90   #
91   if [ -x /usr/sbin/alsactl ]; then
92     /usr/sbin/alsactl store
93   else
94     show '!!!alsactl not found!!!'; fail
95   fi
96   #
97   # remove all sound modules
98   #
99   detect_stop
100 }
101
102 detect_start()
103 {
104   #
105   # run only detect module
106   #
107   /sbin/modprobe snd-detect
108 }
109
110 # Start driver.
111 start() {
112         if [ ! -d /proc/asound ]; then
113                 driver_start
114                 if [ -d /proc/asound ]; then
115                         touch /var/lock/subsys/alsasound
116                 else
117                         exit 1
118                 fi
119         else
120                 if [ -f /proc/asound/detect ]; then
121                         show "Shutting down sound detect module"
122                         detect_stop
123                         ok
124                         driver_start
125                         if [ -d /proc/asound ]; then
126                                 touch /var/lock/subsys/alsasound
127                         else
128                                 exit 1
129                         fi
130                 else
131                         msg_already_running "ALSA driver"
132                 fi
133         fi
134 }
135
136 # Stop daemons.
137 stop() {
138         if [ -d /proc/asound ]; then
139                 show "Shutting down sound driver"
140                 busy
141                 if [ -f /proc/asound/detect ]; then
142                         detect_stop
143                 else
144                         driver_stop
145                 fi
146                 (rmmod isapnp; rmmod soundcore) 2> /dev/null
147                 if [ -d /var/lock/subsys ]; then
148                         rm -f /var/lock/subsys/alsasound
149                 fi
150                 ok
151         else
152                 msg_not_running "ALSA driver"
153         fi
154 }
155
156
157 # See how we were called.
158 case "$1" in
159   start)
160         start
161         ;;
162   stop)
163         stop
164         ;;
165   restart|force-reload)
166         stop
167         start
168         ;;
169   status)
170         # TODO
171         ;;
172   *)
173         msg_usage "$0 {start|stop|restart|force-reload|status}"
174         exit 3
175 esac
176
177 exit 0
This page took 2.046823 seconds and 3 git commands to generate.