]>
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 |
678c4fff AM |
56 | if [ -n "$OLDLOGLEV" ]; then |
57 | /sbin/loglevel "$OLDLOGLEV" | |
58 | fi | |
634db781 AM |
59 | # |
60 | # restore driver settings | |
61 | # | |
62 | if [ -x $alsactl ]; then | |
63 | $alsactl restore | |
64 | else | |
65 | show "ERROR: alsactl not found"; fail | |
66 | fi | |
67 | } | |
68 | ||
678c4fff AM |
69 | detect_stop() |
70 | { | |
634db781 AM |
71 | # |
72 | # remove all sound modules | |
73 | # | |
150b8378 | 74 | /sbin/lsmod | awk '/^snd/ { print $0 }' | while read line; do \ |
634db781 AM |
75 | /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \ |
76 | done | |
77 | } | |
78 | ||
678c4fff AM |
79 | driver_stop() |
80 | { | |
634db781 AM |
81 | # |
82 | # store driver settings | |
83 | # | |
84 | if [ -x $alsactl ]; then | |
85 | $alsactl store | |
86 | else | |
678c4fff | 87 | show '!!!alsactl not found!!!'; fail |
634db781 AM |
88 | fi |
89 | # | |
90 | # remove all sound modules | |
91 | # | |
92 | detect_stop | |
93 | } | |
94 | ||
678c4fff AM |
95 | detect_start() |
96 | { | |
634db781 AM |
97 | # |
98 | # run only detect module | |
99 | # | |
100 | /sbin/modprobe snd-detect | |
101 | } | |
102 | ||
103 | # See how we were called. | |
104 | case "$1" in | |
105 | start) | |
106 | # Start driver. | |
107 | if [ ! -d /proc/asound ]; then | |
678c4fff | 108 | driver_start |
634db781 AM |
109 | if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then |
110 | touch /var/lock/subsys/alsasound | |
111 | fi | |
112 | else | |
113 | if [ -f /proc/asound/detect ]; then | |
678c4fff | 114 | show "Shutting down sound detect module:" |
634db781 AM |
115 | detect_stop |
116 | ok | |
678c4fff | 117 | driver_start |
634db781 AM |
118 | if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then |
119 | touch /var/lock/subsys/alsasound | |
120 | fi | |
121 | else | |
678c4fff | 122 | show "ALSA driver is already running"; fail |
634db781 AM |
123 | fi |
124 | fi | |
125 | ;; | |
126 | stop) | |
127 | # Stop daemons. | |
128 | if [ -d /proc/asound ]; then | |
678c4fff | 129 | show "Shutting down sound driver:" |
150b8378 | 130 | busy |
634db781 AM |
131 | if [ -f /proc/asound/detect ]; then |
132 | detect_stop | |
133 | else | |
678c4fff | 134 | driver_stop |
634db781 | 135 | fi |
678c4fff | 136 | (rmmod isapnp; rmmod soundcore) 2> /dev/null |
634db781 AM |
137 | if [ -d /var/lock/subsys ]; then |
138 | rm -f /var/lock/subsys/alsasound | |
139 | fi | |
140 | ok | |
141 | else | |
142 | show "ALSA driver isn't running "; fail | |
143 | fi | |
144 | ;; | |
145 | restart) | |
146 | $0 stop | |
147 | $0 start | |
148 | ;; | |
149 | detect) | |
150 | # Start driver only in detect mode. | |
151 | if [ -d /proc/asound ]; then | |
152 | if [ -f /proc/asound/detect ]; then | |
678c4fff | 153 | show "ALSA is already running detection mode"; fail |
634db781 AM |
154 | exit 0 |
155 | else | |
678c4fff AM |
156 | show "Shutting down sound driver:" |
157 | driver_stop | |
634db781 AM |
158 | ok |
159 | fi | |
160 | fi | |
678c4fff | 161 | show "Starting sound detect module:" |
634db781 AM |
162 | detect_start |
163 | ok | |
164 | if [ -d /var/lock/subsys ]; then | |
165 | touch /var/lock/subsys/alsasound | |
166 | fi | |
167 | ;; | |
168 | *) | |
169 | echo "Usage: $0 {start|stop|restart|detect}" | |
170 | exit 1 | |
171 | esac | |
172 | ||
173 | exit 0 |