]>
Commit | Line | Data |
---|---|---|
634db781 AM |
1 | #!/bin/bash |
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 RedHat 5.0+: | |
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 | ||
41 | function start() { | |
42 | # | |
43 | # insert all sound modules | |
44 | # | |
45 | cat $MODULES_CONF | grep -v "off" | \ | |
46 | grep -E "^alias.+snd-card-[[:digit:]]" | \ | |
47 | awk '{print $3}' | \ | |
48 | while read line; do \ | |
49 | show "Starting sound driver: $line " ; \ | |
50 | /sbin/modprobe $line; \ | |
51 | ok; \ | |
52 | done | |
53 | # | |
54 | # restore driver settings | |
55 | # | |
56 | if [ -x $alsactl ]; then | |
57 | $alsactl restore | |
58 | else | |
59 | show "ERROR: alsactl not found"; fail | |
60 | fi | |
61 | } | |
62 | ||
63 | function detect_stop() { | |
64 | # | |
65 | # remove all sound modules | |
66 | # | |
67 | /sbin/lsmod | grep -E "^snd" | while read line; do \ | |
68 | /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \ | |
69 | done | |
70 | } | |
71 | ||
72 | function stop() { | |
73 | # | |
74 | # store driver settings | |
75 | # | |
76 | if [ -x $alsactl ]; then | |
77 | $alsactl store | |
78 | else | |
79 | show "!!!alsactl not found!!! "; fail | |
80 | fi | |
81 | # | |
82 | # remove all sound modules | |
83 | # | |
84 | detect_stop | |
85 | } | |
86 | ||
87 | function detect_start() { | |
88 | # | |
89 | # run only detect module | |
90 | # | |
91 | /sbin/modprobe snd-detect | |
92 | } | |
93 | ||
94 | # See how we were called. | |
95 | case "$1" in | |
96 | start) | |
97 | # Start driver. | |
98 | if [ ! -d /proc/asound ]; then | |
99 | start | |
100 | if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then | |
101 | touch /var/lock/subsys/alsasound | |
102 | fi | |
103 | else | |
104 | if [ -f /proc/asound/detect ]; then | |
105 | show "Shutting down sound detect module: " | |
106 | detect_stop | |
107 | ok | |
108 | start | |
109 | if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then | |
110 | touch /var/lock/subsys/alsasound | |
111 | fi | |
112 | else | |
113 | show "ALSA driver is already running "; fail | |
114 | fi | |
115 | fi | |
116 | ;; | |
117 | stop) | |
118 | # Stop daemons. | |
119 | if [ -d /proc/asound ]; then | |
120 | show "Shutting down sound driver: " | |
121 | if [ -f /proc/asound/detect ]; then | |
122 | detect_stop | |
123 | else | |
124 | stop | |
125 | fi | |
126 | if [ -d /var/lock/subsys ]; then | |
127 | rm -f /var/lock/subsys/alsasound | |
128 | fi | |
129 | ok | |
130 | else | |
131 | show "ALSA driver isn't running "; fail | |
132 | fi | |
133 | ;; | |
134 | restart) | |
135 | $0 stop | |
136 | $0 start | |
137 | ;; | |
138 | detect) | |
139 | # Start driver only in detect mode. | |
140 | if [ -d /proc/asound ]; then | |
141 | if [ -f /proc/asound/detect ]; then | |
142 | show "ALSA is already running detection mode "; fail | |
143 | exit 0 | |
144 | else | |
145 | show "Shutting down sound driver: " | |
146 | stop | |
147 | ok | |
148 | fi | |
149 | fi | |
150 | show "Starting sound detect module: " | |
151 | detect_start | |
152 | ok | |
153 | if [ -d /var/lock/subsys ]; then | |
154 | touch /var/lock/subsys/alsasound | |
155 | fi | |
156 | ;; | |
157 | *) | |
158 | echo "Usage: $0 {start|stop|restart|detect}" | |
159 | exit 1 | |
160 | esac | |
161 | ||
162 | exit 0 |