]> git.pld-linux.org Git - packages/alsa-utils.git/blob - alsasound.init
up to 1.2.11
[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 # Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
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 #
23 # For PLD Linux Distribution:
24 # chkconfig:    2345 87 14
25 # description:  ALSA driver
26 #
27
28 # Source function library.
29 . /etc/rc.d/init.d/functions
30
31 driver_start()
32 {
33   #
34   # insert all sound modules
35   #
36   modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $3}' | \
37     while read line; do \
38       msg_starting "sound driver: $line"
39       busy
40       /sbin/modprobe $line
41       ok
42     done
43   modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $3}' | \
44     while read line; do \
45       msg_starting "sound driver: $line"
46       busy
47       /sbin/modprobe $line
48       ok
49     done
50 }
51
52 detect_stop()
53 {
54   #
55   # remove all sound modules
56   #
57   /sbin/lsmod | awk '/^(snd|ac97_bus)/ { print $1 }' | while read module; do \
58      /sbin/rmmod $module
59   done
60 }
61
62 driver_stop()
63 {
64   #
65   # remove all sound modules
66   #
67   detect_stop
68 }
69
70 detect_start()
71 {
72   #
73   # run only detect module
74   #
75   /sbin/modprobe snd-detect
76 }
77
78 # Start driver.
79 start() {
80         if [ ! -d /proc/asound ]; then
81                 driver_start
82                 if [ -d /proc/asound ]; then
83                         touch /var/lock/subsys/alsasound
84                 else
85                         exit 1
86                 fi
87         else
88                 if [ -f /proc/asound/detect ]; then
89                         show "Shutting down sound detect module"
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
99                         msg_already_running "ALSA driver"
100                 fi
101         fi
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
107 }
108
109 # Stop daemons.
110 stop() {
111         if [ -d /proc/asound ]; then
112                 show "Shutting down sound driver"
113                 busy
114                 if [ -f /proc/asound/detect ]; then
115                         detect_stop
116                 else
117                         driver_stop
118                 fi
119                 (rmmod isapnp; rmmod soundcore) 2> /dev/null
120                 if [ -d /var/lock/subsys ]; then
121                         rm -f /var/lock/subsys/alsasound
122                 fi
123                 ok
124         else
125                 msg_not_running "ALSA driver"
126         fi
127 }
128
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
139
140 # See how we were called.
141 case "$1" in
142   start)
143         start
144         ;;
145   stop)
146         stop
147         ;;
148   restart)
149         stop
150         start
151         ;;
152   try-restart)
153         condrestart 0
154         ;;
155   force-reload)
156         condrestart 7
157         ;;
158   status)
159         # TODO
160         ;;
161   *)
162         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
163         exit 3
164 esac
165
166 exit 0
This page took 0.087812 seconds and 3 git commands to generate.