#!/bin/bash # # /etc/init.d/alsa This shell script takes care of starting and stopping # ALSA sound driver. # # This script requires /usr/sbin/alsactl and /usr/bin/aconnect programs # from the alsa-utils package. # # Copyright (c) by Jaroslav Kysela <perex@jcu.cz> # # Slightly modified for Debian GNU/Linux by Wichert Akkerman. # Masato Taruishi. # # Slightly modified for Linux-Mandrake by Chmouel Boudjnah # <chmouel@mandrakesoft.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #daemon # # chkconfig: 2345 17 70 # description: This shell script launch the alsa sound system on your # system. . /etc/init.d/functions PKLVL=$(cut -f1 /proc/sys/kernel/printk) sysctl -n -w kernel.printk=0 alsactl=/usr/sbin/alsactl aconnect=/usr/bin/aconnect [[ ! -f /usr/share/alsa/alsa-utils ]] && exit 0 [[ -e /etc/sysconfig/alsa ]] && . /etc/sysconfig/alsa . /usr/share/alsa/alsa-utils function start() { found_driver="false" gprintf "Starting ALSA version %s:" "$alsa_version" # First load the ALSA common driver and check whether devfs properly # can be available when the working kernel has devfs support. /sbin/modprobe snd if [ ! -e /dev/snd ]; then if [ -d /proc/asound/dev ]; then # you are using the kernel without devfs so simply create # symlink ln -s /proc/asound/dev /dev/snd else # you are using the kernel with devfs but disabling devfs. /sbin/modprobe -r snd exit 0 fi fi awk '/^((alias)|(probe)) +(sound|snd)-(slot|card)-[0-9]/ {print $3}' /etc/modules.conf | ( \ while read line; do [[ $line != snd-* ]] && continue found_driver="found" desc=`echo $line | cut -d- -f 2` if /sbin/modprobe $line >/dev/null 2>&1; then echo -n " $desc" found_driver="detect" else echo -n " ($desc)" fi done case $found_driver in detect) echo -n "." success;echo ;; false) if [ $alsa_version = "none" ]; then gprintf " no driver installed."; failure;echo exit 1 else gprintf " no sound cards defined."; failure;echo exit 1 fi ;; found) success;echo exit 1 ;; esac ) || exit 0 # # Enabling sound devices for alsactl. get_sound_devs enable_sound_devs # restore driver settings # if [ -x $alsactl ]; then gprintf "Doing alsactl to restore mixer settings..." $alsactl restore >/dev/null 2>&1 || true success;echo fi } function startoss() { [ "$startosslayer" = true ] && for i in mixer pcm seq ; do /sbin/modprobe snd-${i}-oss >/dev/null 2>&1 ; done } function detect_stop() { # # remove all sound modules # clean=0 modprobe -r snd-seq-oss modprobe -r snd-pcm-oss modprobe -r snd-mixer-oss /sbin/lsmod | grep -E "^snd" | ( while read line; do \ /sbin/rmmod `echo $line | cut -d ' ' -f 1` >/dev/null 2>&1 || clean=1; \ done # remove the 2.2 soundcore module (if possible) /sbin/rmmod soundcore >/dev/null 2>&1 || true /sbin/rmmod gameport 2> /dev/null || true if [ $clean = 1 ]; then exit 1 fi ) if [ $? = 1 ]; then return 1 fi } function stop() { # # store driver settings # if [ -x $alsactl ]; then gprintf "Doing alsactl to store mixer settings..." $alsactl store >/dev/null 2>&1 || true sleep 1 success;echo fi gprintf "Shutting down ALSA sound driver (version %s): " "$alsa_version" # Make sure that no devices are opened while # we are killing the procs that have devices open get_sound_devs get_sound_devs_proc disable_sound_devs #chmod 000 $sound_devs_proc As of drivers 0.5.8a these permissions can't be changed if [ "$ALSA_KILL_MODE" = "force" ]; then kill_procs_using_sound_devs # # remove all sequencer connections if any # if [ -f /proc/asound/seq/clients -a -x $aconnect ]; then $aconnect --removeall fi else get_procs_using_sound_devs if [ -n "$procs_using_sound_devs" ]; then gprintf "no. (sound is being used by pid %s)" "$procs_using_sound_devs)" chmod 660 $sound_devs_dev failure;echo exit 0 fi fi # # remove all sound modules # detect_stop enable_sound_devs #chmod 600 $sound_devs_proc As of drivers 0.5.8a these permissions can't be changed if [ ! -f /dev/.devfsd ] && [ -L /dev/snd ]; then rm -f /dev/snd fi } function detect_start() { # # run only detect module # /sbin/modprobe snd-detect >/dev/null 2>&1 || true } # Initialize some variables. get_alsa_version # See how we were called. case "$1" in start) # Start driver. if [ ! -d /proc/asound ]; then if egrep -qs "^alias( |\t)+(snd|sound)-(card|slot)-[0-9]( |\t)+snd-" /etc/modules.conf;then start && startoss touch /var/lock/subsys/alsa fi else if [ -f /proc/asound/detect ]; then gprintf "Shutting down ALSA sound detect module (version %s): " "$alsa_version" detect_stop success;echo start && startoss touch /var/lock/subsys/alsa else gprintf "ALSA driver (version %s) is already running." "$alsa_version" echo fi fi ;; stop) # Stop daemons. if [ -d /proc/asound ]; then if [ -f /proc/asound/detect ]; then detect_stop rm -f /var/lock/subsys/alsa else if stop; then success;echo rm -f /var/lock/subsys/alsa else failure;echo rm -f /var/lock/subsys/alsa fi fi else gprintf "ALSA driver isn't running." echo fi ;; status) if egrep -q '(sparcaudio|sound)' /proc/devices;then gprintf "Sound loaded" echo fi ;; force-stop) ALSA_KILL_MODE="force" $0 stop ;; condrestart) if [ -f /var/lock/subsys/alsa ];then $0 stop && $0 $start fi ;; restart) $0 stop && $0 start ;; force-reload) ALSA_KILL_MODE="force" $0 restart ;; force-restart) ALSA_KILL_MODE="force" $0 stop $0 start ;; *) echo "Usage: %s\n" "$(basename $0) {start|stop|restart|force-reload|force-stop|force-restart}" exit 1 esac sysctl -n -w kernel.printk=$PKLVL exit 0