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