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