]> git.pld-linux.org Git - packages/alsa-utils.git/blame - alsasound.init
- up to 1.0.15
[packages/alsa-utils.git] / alsasound.init
CommitLineData
678c4fff 1#!/bin/sh
634db781 2#
8e5b4036 3# alsasound This shell script takes care of starting and stopping \
4# ALSA sound driver.
634db781
AM
5#
6# This script requires /usr/sbin/alsactl program from alsa-utils package.
7#
f3ec2d8f 8# Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
634db781
AM
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#
2efb5f03 25# For PLD Linux Distribution:
8e5b4036 26# chkconfig: 2345 87 14
27# description: ALSA driver
634db781
AM
28#
29
30# Source function library.
31. /etc/rc.d/init.d/functions
32
678c4fff
AM
33driver_start()
34{
634db781
AM
35 #
36 # insert all sound modules
37 #
150b8378 38 if OLDLOGLEV=$(awk '{print $1}' < /proc/sys/kernel/printk 2> /dev/null); then
678c4fff
AM
39 /sbin/loglevel 1
40 fi
ac692036 41 modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $2}' | \
e0831d0a 42 while read line; do \
43 msg_starting "sound driver: $line"
44 busy
45 /sbin/modprobe $line
46 ok
47 done
ac692036 48 modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $2}' | \
634db781 49 while read line; do \
d08febb7 50 msg_starting "sound driver: $line"
150b8378 51 busy
52 /sbin/modprobe $line
53 ok
634db781 54 done
678c4fff
AM
55 if [ -n "$OLDLOGLEV" ]; then
56 /sbin/loglevel "$OLDLOGLEV"
57 fi
634db781
AM
58 #
59 # restore driver settings
60 #
a5788d60 61 if [ -x /usr/sbin/alsactl ]; then
b8fb64c0 62 if [ -f /etc/asound.state ]; then
049f843f 63 if [ "$(kernelver)" -lt "002006012" ]; then
2a5ddd29 64 for i in 1 2 3 4; do
65 [ -a /dev/snd/controlC0 ] && break
66 sleep 1
67 done
68 fi
a5788d60 69 /usr/sbin/alsactl restore
b8fb64c0 70 fi
634db781
AM
71 else
72 show "ERROR: alsactl not found"; fail
73 fi
74}
75
678c4fff
AM
76detect_stop()
77{
634db781
AM
78 #
79 # remove all sound modules
80 #
4d1ff5eb
ER
81 /sbin/lsmod | awk '/^(snd|ac97_bus)/ { print $1 }' | while read module; do \
82 /sbin/rmmod $module
634db781
AM
83 done
84}
85
678c4fff
AM
86driver_stop()
87{
634db781
AM
88 #
89 # store driver settings
90 #
a5788d60
ER
91 if [ -x /usr/sbin/alsactl ]; then
92 /usr/sbin/alsactl store
634db781 93 else
678c4fff 94 show '!!!alsactl not found!!!'; fail
634db781
AM
95 fi
96 #
97 # remove all sound modules
98 #
99 detect_stop
100}
101
678c4fff
AM
102detect_start()
103{
634db781
AM
104 #
105 # run only detect module
106 #
107 /sbin/modprobe snd-detect
108}
109
02813c63
ER
110# Start driver.
111start() {
634db781 112 if [ ! -d /proc/asound ]; then
d08febb7 113 driver_start
114 if [ -d /proc/asound ]; then
115 touch /var/lock/subsys/alsasound
116 else
117 exit 1
118 fi
634db781 119 else
d08febb7 120 if [ -f /proc/asound/detect ]; then
b52c7707 121 show "Shutting down sound detect module"
d08febb7 122 detect_stop
123 ok
124 driver_start
125 if [ -d /proc/asound ]; then
126 touch /var/lock/subsys/alsasound
127 else
128 exit 1
129 fi
130 else
e0831d0a 131 msg_already_running "ALSA driver"
d08febb7 132 fi
634db781 133 fi
02813c63
ER
134}
135
136# Stop daemons.
137stop() {
634db781 138 if [ -d /proc/asound ]; then
b52c7707 139 show "Shutting down sound driver"
d08febb7 140 busy
141 if [ -f /proc/asound/detect ]; then
142 detect_stop
143 else
144 driver_stop
145 fi
e0831d0a 146 (rmmod isapnp; rmmod soundcore) 2> /dev/null
d08febb7 147 if [ -d /var/lock/subsys ]; then
148 rm -f /var/lock/subsys/alsasound
149 fi
150 ok
634db781 151 else
d08febb7 152 msg_not_running "ALSA driver"
634db781 153 fi
5ef1ff04
ER
154}
155
02813c63
ER
156
157# See how we were called.
158case "$1" in
159 start)
160 start
161 ;;
162 stop)
163 stop
d08febb7 164 ;;
165 restart|force-reload)
02813c63
ER
166 stop
167 start
d08febb7 168 ;;
169 status)
170 # TODO
634db781 171 ;;
634db781 172 *)
d08febb7 173 msg_usage "$0 {start|stop|restart|force-reload|status}"
174 exit 3
634db781
AM
175esac
176
177exit 0
This page took 0.074122 seconds and 4 git commands to generate.