]>
Commit | Line | Data |
---|---|---|
678c4fff | 1 | #!/bin/sh |
634db781 AM |
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 | # | |
678c4fff | 25 | # For Polish Linux Distribution: |
634db781 AM |
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 [ -r /etc/modules.conf ]; then | |
36 | MODULES_CONF=/etc/modules.conf | |
37 | else | |
38 | MODULES_CONF=/etc/conf.modules | |
39 | fi | |
40 | ||
678c4fff AM |
41 | driver_start() |
42 | { | |
634db781 AM |
43 | # |
44 | # insert all sound modules | |
45 | # | |
150b8378 | 46 | if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then |
678c4fff AM |
47 | /sbin/loglevel 1 |
48 | fi | |
150b8378 | 49 | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/ || $2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' < $MODULES_CONF | \ |
634db781 | 50 | while read line; do \ |
150b8378 | 51 | show "Starting sound driver: $line" |
52 | busy | |
53 | /sbin/modprobe $line | |
54 | ok | |
634db781 | 55 | done |
150b8378 | 56 | # |
57 | # set (non-)blocking state of pcm devices | |
58 | # | |
59 | for card in /proc/asound/[0-9]; do | |
60 | card=`echo $card | awk '{ sub(/^.*\//, ""); print $0 }'` | |
61 | for dev in /proc/asound/$card/pcmD[0-9]o; do | |
62 | dev=`echo $dev | awk '{ sub(/^.*pcmD/, ""); sub(/o$/, ""); print $0 }'` | |
63 | show "Setting up blocking state for card $card device $dev" | |
64 | busy | |
65 | echo "Playback erase" > /proc/asound/$card/pcmD${dev}o | |
66 | echo "Capture erase" > /proc/asound/$card/pcmD${dev}o | |
67 | awk -v CARD=$card '($1 ~ CARD || $1 ~ /\*/) { $1 = ""; sub(/^ /, ""); print $0}' < /etc/sysconfig/alsa-oss-pcm > /proc/asound/$card/pcmD${dev}o | |
68 | ok | |
69 | done | |
70 | done | |
678c4fff AM |
71 | if [ -n "$OLDLOGLEV" ]; then |
72 | /sbin/loglevel "$OLDLOGLEV" | |
73 | fi | |
634db781 AM |
74 | # |
75 | # restore driver settings | |
76 | # | |
77 | if [ -x $alsactl ]; then | |
78 | $alsactl restore | |
79 | else | |
80 | show "ERROR: alsactl not found"; fail | |
81 | fi | |
82 | } | |
83 | ||
678c4fff AM |
84 | detect_stop() |
85 | { | |
634db781 AM |
86 | # |
87 | # remove all sound modules | |
88 | # | |
150b8378 | 89 | /sbin/lsmod | awk '/^snd/ { print $0 }' | while read line; do \ |
634db781 AM |
90 | /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \ |
91 | done | |
92 | } | |
93 | ||
678c4fff AM |
94 | driver_stop() |
95 | { | |
634db781 AM |
96 | # |
97 | # store driver settings | |
98 | # | |
99 | if [ -x $alsactl ]; then | |
100 | $alsactl store | |
101 | else | |
678c4fff | 102 | show '!!!alsactl not found!!!'; fail |
634db781 AM |
103 | fi |
104 | # | |
105 | # remove all sound modules | |
106 | # | |
107 | detect_stop | |
108 | } | |
109 | ||
678c4fff AM |
110 | detect_start() |
111 | { | |
634db781 AM |
112 | # |
113 | # run only detect module | |
114 | # | |
115 | /sbin/modprobe snd-detect | |
116 | } | |
117 | ||
118 | # See how we were called. | |
119 | case "$1" in | |
120 | start) | |
121 | # Start driver. | |
122 | if [ ! -d /proc/asound ]; then | |
678c4fff | 123 | driver_start |
634db781 AM |
124 | if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then |
125 | touch /var/lock/subsys/alsasound | |
126 | fi | |
127 | else | |
128 | if [ -f /proc/asound/detect ]; then | |
678c4fff | 129 | show "Shutting down sound detect module:" |
634db781 AM |
130 | detect_stop |
131 | ok | |
678c4fff | 132 | driver_start |
634db781 AM |
133 | if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then |
134 | touch /var/lock/subsys/alsasound | |
135 | fi | |
136 | else | |
678c4fff | 137 | show "ALSA driver is already running"; fail |
634db781 AM |
138 | fi |
139 | fi | |
140 | ;; | |
141 | stop) | |
142 | # Stop daemons. | |
143 | if [ -d /proc/asound ]; then | |
678c4fff | 144 | show "Shutting down sound driver:" |
150b8378 | 145 | busy |
634db781 AM |
146 | if [ -f /proc/asound/detect ]; then |
147 | detect_stop | |
148 | else | |
678c4fff | 149 | driver_stop |
634db781 | 150 | fi |
678c4fff | 151 | (rmmod isapnp; rmmod soundcore) 2> /dev/null |
634db781 AM |
152 | if [ -d /var/lock/subsys ]; then |
153 | rm -f /var/lock/subsys/alsasound | |
154 | fi | |
155 | ok | |
156 | else | |
157 | show "ALSA driver isn't running "; fail | |
158 | fi | |
159 | ;; | |
160 | restart) | |
161 | $0 stop | |
162 | $0 start | |
163 | ;; | |
164 | detect) | |
165 | # Start driver only in detect mode. | |
166 | if [ -d /proc/asound ]; then | |
167 | if [ -f /proc/asound/detect ]; then | |
678c4fff | 168 | show "ALSA is already running detection mode"; fail |
634db781 AM |
169 | exit 0 |
170 | else | |
678c4fff AM |
171 | show "Shutting down sound driver:" |
172 | driver_stop | |
634db781 AM |
173 | ok |
174 | fi | |
175 | fi | |
678c4fff | 176 | show "Starting sound detect module:" |
634db781 AM |
177 | detect_start |
178 | ok | |
179 | if [ -d /var/lock/subsys ]; then | |
180 | touch /var/lock/subsys/alsasound | |
181 | fi | |
182 | ;; | |
183 | *) | |
184 | echo "Usage: $0 {start|stop|restart|detect}" | |
185 | exit 1 | |
186 | esac | |
187 | ||
188 | exit 0 |