]> git.pld-linux.org Git - packages/alsa-utils.git/blob - alsasound.init
- BR: xmlto
[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 }
103
104 # Stop daemons.
105 stop() {
106         if [ -d /proc/asound ]; then
107                 show "Shutting down sound driver"
108                 busy
109                 if [ -f /proc/asound/detect ]; then
110                         detect_stop
111                 else
112                         driver_stop
113                 fi
114                 (rmmod isapnp; rmmod soundcore) 2> /dev/null
115                 if [ -d /var/lock/subsys ]; then
116                         rm -f /var/lock/subsys/alsasound
117                 fi
118                 ok
119         else
120                 msg_not_running "ALSA driver"
121         fi
122 }
123
124 condrestart() {
125         if [ -f /var/lock/subsys/alsasound ]; then
126                 stop
127                 start
128         else
129                 msg_not_running "ALSA driver"
130                 RETVAL=$1
131         fi
132 }
133
134
135 # See how we were called.
136 case "$1" in
137   start)
138         start
139         ;;
140   stop)
141         stop
142         ;;
143   restart)
144         stop
145         start
146         ;;
147   try-restart)
148         condrestart 0
149         ;;
150   force-reload)
151         condrestart 7
152         ;;
153   status)
154         # TODO
155         ;;
156   *)
157         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
158         exit 3
159 esac
160
161 exit 0
This page took 0.039803 seconds and 3 git commands to generate.