]> git.pld-linux.org Git - packages/alsa-utils.git/blame - alsasound
sh'ized + loglevel support
[packages/alsa-utils.git] / alsasound
CommitLineData
678c4fff 1#!/bin/sh
634db781
AM
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#
678c4fff 25# For Polish Linux Distribution:
634db781
AM
26# chkconfig: 2345 87 14
27# description: ALSA driver
28#
29
30# Source function library.
31. /etc/rc.d/init.d/functions
32
33alsactl=/usr/sbin/alsactl
34
35if [ -r /etc/modules.conf ]; then
36MODULES_CONF=/etc/modules.conf
37else
38MODULES_CONF=/etc/conf.modules
39fi
40
678c4fff
AM
41driver_start()
42{
634db781
AM
43 #
44 # insert all sound modules
45 #
678c4fff
AM
46 if OLDLOGLEV=$(cat /proc/sys/kernel/printk | awk '{print $1}' 2> /dev/null); then
47 /sbin/loglevel 1
48 fi
634db781
AM
49 cat $MODULES_CONF | grep -v "off" | \
50 grep -E "^alias.+snd-card-[[:digit:]]" | \
51 awk '{print $3}' | \
52 while read line; do \
53 show "Starting sound driver: $line " ; \
54 /sbin/modprobe $line; \
55 ok; \
56 done
678c4fff
AM
57 if [ -n "$OLDLOGLEV" ]; then
58 /sbin/loglevel "$OLDLOGLEV"
59 fi
634db781
AM
60 #
61 # restore driver settings
62 #
63 if [ -x $alsactl ]; then
64 $alsactl restore
65 else
66 show "ERROR: alsactl not found"; fail
67 fi
68}
69
678c4fff
AM
70detect_stop()
71{
634db781
AM
72 #
73 # remove all sound modules
74 #
75 /sbin/lsmod | grep -E "^snd" | while read line; do \
76 /sbin/rmmod `echo $line | cut -d ' ' -f 1`; \
77 done
78}
79
678c4fff
AM
80driver_stop()
81{
634db781
AM
82 #
83 # store driver settings
84 #
85 if [ -x $alsactl ]; then
86 $alsactl store
87 else
678c4fff 88 show '!!!alsactl not found!!!'; fail
634db781
AM
89 fi
90 #
91 # remove all sound modules
92 #
93 detect_stop
94}
95
678c4fff
AM
96detect_start()
97{
634db781
AM
98 #
99 # run only detect module
100 #
101 /sbin/modprobe snd-detect
102}
103
104# See how we were called.
105case "$1" in
106 start)
107 # Start driver.
108 if [ ! -d /proc/asound ]; then
678c4fff 109 driver_start
634db781
AM
110 if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then
111 touch /var/lock/subsys/alsasound
112 fi
113 else
114 if [ -f /proc/asound/detect ]; then
678c4fff 115 show "Shutting down sound detect module:"
634db781
AM
116 detect_stop
117 ok
678c4fff 118 driver_start
634db781
AM
119 if [ -d /proc/asound ] && [ -d /var/lock/subsys ]; then
120 touch /var/lock/subsys/alsasound
121 fi
122 else
678c4fff 123 show "ALSA driver is already running"; fail
634db781
AM
124 fi
125 fi
126 ;;
127 stop)
128 # Stop daemons.
129 if [ -d /proc/asound ]; then
678c4fff 130 show "Shutting down sound driver:"
634db781
AM
131 if [ -f /proc/asound/detect ]; then
132 detect_stop
133 else
678c4fff 134 driver_stop
634db781 135 fi
678c4fff 136 (rmmod isapnp; rmmod soundcore) 2> /dev/null
634db781
AM
137 if [ -d /var/lock/subsys ]; then
138 rm -f /var/lock/subsys/alsasound
139 fi
140 ok
141 else
142 show "ALSA driver isn't running "; fail
143 fi
144 ;;
145 restart)
146 $0 stop
147 $0 start
148 ;;
149 detect)
150 # Start driver only in detect mode.
151 if [ -d /proc/asound ]; then
152 if [ -f /proc/asound/detect ]; then
678c4fff 153 show "ALSA is already running detection mode"; fail
634db781
AM
154 exit 0
155 else
678c4fff
AM
156 show "Shutting down sound driver:"
157 driver_stop
634db781
AM
158 ok
159 fi
160 fi
678c4fff 161 show "Starting sound detect module:"
634db781
AM
162 detect_start
163 ok
164 if [ -d /var/lock/subsys ]; then
165 touch /var/lock/subsys/alsasound
166 fi
167 ;;
168 *)
169 echo "Usage: $0 {start|stop|restart|detect}"
170 exit 1
171esac
172
173exit 0
This page took 0.054237 seconds and 4 git commands to generate.