]>
Commit | Line | Data |
---|---|---|
678c4fff | 1 | #!/bin/sh |
634db781 | 2 | # |
8e5b4036 | 3 | # alsasound This shell script takes care of starting and stopping \ |
4 | # ALSA sound driver. | |
634db781 | 5 | # |
f3ec2d8f | 6 | # Copyright (c) by Jaroslav Kysela <perex@jcu.cz> |
634db781 AM |
7 | # |
8 | # This program is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 2 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | # | |
22 | # | |
2efb5f03 | 23 | # For PLD Linux Distribution: |
8e5b4036 | 24 | # chkconfig: 2345 87 14 |
25 | # description: ALSA driver | |
634db781 AM |
26 | # |
27 | ||
28 | # Source function library. | |
29 | . /etc/rc.d/init.d/functions | |
30 | ||
678c4fff AM |
31 | driver_start() |
32 | { | |
634db781 AM |
33 | # |
34 | # insert all sound modules | |
35 | # | |
b0646167 | 36 | modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $3}' | \ |
e0831d0a | 37 | while read line; do \ |
38 | msg_starting "sound driver: $line" | |
39 | busy | |
40 | /sbin/modprobe $line | |
41 | ok | |
42 | done | |
b0646167 | 43 | modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $3}' | \ |
634db781 | 44 | while read line; do \ |
d08febb7 | 45 | msg_starting "sound driver: $line" |
150b8378 | 46 | busy |
47 | /sbin/modprobe $line | |
48 | ok | |
634db781 | 49 | done |
634db781 AM |
50 | } |
51 | ||
678c4fff AM |
52 | detect_stop() |
53 | { | |
634db781 AM |
54 | # |
55 | # remove all sound modules | |
56 | # | |
4d1ff5eb ER |
57 | /sbin/lsmod | awk '/^(snd|ac97_bus)/ { print $1 }' | while read module; do \ |
58 | /sbin/rmmod $module | |
634db781 AM |
59 | done |
60 | } | |
61 | ||
678c4fff AM |
62 | driver_stop() |
63 | { | |
634db781 AM |
64 | # |
65 | # remove all sound modules | |
66 | # | |
67 | detect_stop | |
68 | } | |
69 | ||
678c4fff AM |
70 | detect_start() |
71 | { | |
634db781 AM |
72 | # |
73 | # run only detect module | |
74 | # | |
75 | /sbin/modprobe snd-detect | |
76 | } | |
77 | ||
02813c63 ER |
78 | # Start driver. |
79 | start() { | |
634db781 | 80 | if [ ! -d /proc/asound ]; then |
d08febb7 | 81 | driver_start |
82 | if [ -d /proc/asound ]; then | |
83 | touch /var/lock/subsys/alsasound | |
84 | else | |
85 | exit 1 | |
86 | fi | |
634db781 | 87 | else |
d08febb7 | 88 | if [ -f /proc/asound/detect ]; then |
b52c7707 | 89 | show "Shutting down sound detect module" |
d08febb7 | 90 | detect_stop |
91 | ok | |
92 | driver_start | |
93 | if [ -d /proc/asound ]; then | |
94 | touch /var/lock/subsys/alsasound | |
95 | else | |
96 | exit 1 | |
97 | fi | |
98 | else | |
e0831d0a | 99 | msg_already_running "ALSA driver" |
d08febb7 | 100 | fi |
634db781 | 101 | fi |
08fa9b0b JB |
102 | # "restore" is handled via udev if running; if not, do it manually |
103 | if is_no "$START_UDEV" && [ -f /var/lib/alsa/asound.state ]; then | |
104 | sleep 1 | |
105 | /sbin/alsactl restore | |
106 | fi | |
02813c63 ER |
107 | } |
108 | ||
109 | # Stop daemons. | |
110 | stop() { | |
634db781 | 111 | if [ -d /proc/asound ]; then |
b52c7707 | 112 | show "Shutting down sound driver" |
d08febb7 | 113 | busy |
114 | if [ -f /proc/asound/detect ]; then | |
115 | detect_stop | |
116 | else | |
117 | driver_stop | |
118 | fi | |
e0831d0a | 119 | (rmmod isapnp; rmmod soundcore) 2> /dev/null |
d08febb7 | 120 | if [ -d /var/lock/subsys ]; then |
121 | rm -f /var/lock/subsys/alsasound | |
122 | fi | |
123 | ok | |
634db781 | 124 | else |
d08febb7 | 125 | msg_not_running "ALSA driver" |
634db781 | 126 | fi |
5ef1ff04 ER |
127 | } |
128 | ||
031987f5 JB |
129 | condrestart() { |
130 | if [ -f /var/lock/subsys/alsasound ]; then | |
131 | stop | |
132 | start | |
133 | else | |
134 | msg_not_running "ALSA driver" | |
135 | RETVAL=$1 | |
136 | fi | |
137 | } | |
138 | ||
02813c63 ER |
139 | |
140 | # See how we were called. | |
141 | case "$1" in | |
142 | start) | |
143 | start | |
144 | ;; | |
145 | stop) | |
146 | stop | |
d08febb7 | 147 | ;; |
031987f5 | 148 | restart) |
02813c63 ER |
149 | stop |
150 | start | |
d08febb7 | 151 | ;; |
031987f5 JB |
152 | try-restart) |
153 | condrestart 0 | |
154 | ;; | |
155 | force-reload) | |
156 | condrestart 7 | |
157 | ;; | |
d08febb7 | 158 | status) |
159 | # TODO | |
634db781 | 160 | ;; |
634db781 | 161 | *) |
031987f5 | 162 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" |
d08febb7 | 163 | exit 3 |
634db781 AM |
164 | esac |
165 | ||
166 | exit 0 |