📄 alsaconf.in
字号:
#!/bin/bash## ALSA Configurator## Copyright (c) 1999-2002 SuSE GmbH# Jan ONDREJ## written by Takashi Iwai <tiwai@suse.de># Bernd Kaindl <bk@suse.de># Jan ONDREJ (SAL) <ondrejj@salstar.sk>## based on the original version of Jan ONDREJ's alsaconf for ALSA 0.4.## 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.#export TEXTDOMAIN=alsaconfprefix=@prefix@exec_prefix=@exec_prefix@bindir=@bindir@sbindir=@sbindir@version=@VERSION@USE_NLS=@USE_NLS@# Useful for debuggingPROCFS="/proc"SYSFS="/sys"# i18n stuffif test "$USE_NLS" = "yes" && which gettext > /dev/null; then xecho() { gettext -s "$*" }else xecho() { echo "$*" } gettext() { echo -n "$*" }fixmsg() { msg=$(gettext "$1") shift printf "$msg" $*}# Check for GNU/Linux distributionsif [ -f /etc/SuSE-release ]; then distribution="suse" suse_version=$(grep 'VERSION = ' /etc/SuSE-release | sed -e s/'VERSION = '//)elif [ -f /etc/UnitedLinux-release ]; then distribution="suse"elif [ -f /etc/gentoo-release ]; then distribution="gentoo"elif [ -f /etc/debian_version ]; then distribution="debian"elif [ -f /etc/mandrake-release ]; then distribution="mandrake"elif test -f /etc/redhat-release && grep -q "Red Hat" /etc/redhat-release; then distribution="redhat"elif test -f /etc/fedora-release && grep -q "Fedora" /etc/fedora-release; then distribution="fedora"else distribution="unknown"fifor prog in lspci lsmod; do for path in /sbin /usr/sbin /bin /usr/bin;do test -x $path/$prog && eval $prog=$path/$prog donedoneunset prog pathusage() { xecho "ALSA configurator" echo " version $version" xecho "usage: alsaconf [options] -l|--legacy check only legacy non-isapnp cards -m|--modinfo read module descriptions instead of reading card db -s|--sound wav-file use the specified wav file as a test sound -u|--uid uid set the uid for the ALSA devices (default = 0) [obsoleted] -g|--gid gid set the gid for the ALSA devices (default = 0) [obsoleted] -d|--devmode mode set the permission for ALSA devices (default = 0666) [obs.] -r|--strict set strict device mode (equiv. with -g 17 -d 0660) [obsoleted] -L|--log file logging on the specified file (for debugging purpose only) -p|--probe card-name probe a legacy non-isapnp card and print module options -P|--listprobe list the supported legacy card modules -c|--config file specify the module config file -R|--resources list available DMA and IRQ resources with debug for legacy -h|--help what you're reading"}OPTS=`getopt -o lmL:hp:Pu:g:d:rs:c:R --long legacy,modinfo,log:,help,probe:,listprobe,uid:,gid:,devmode:,strict,sound:,config:,resources -n alsaconf -- "$@"` || exit 1eval set -- "$OPTS"do_legacy_only=0use_modinfo_db=0alsa_uid=0alsa_gid=0alsa_mode=0666legacy_probe_card=""LOGFILE=""TESTSOUND="@TESTSOUND@"try_all_combination=0resources="false"# legacy supportLEGACY_CARDS="opl3sa2 cs4236 cs4232 cs4231 es18xx es1688 sb16 sb8"while true ; do case "$1" in -l|--legacy) do_legacy_only=1; shift ;; -m|--modinfo) use_modinfo_db=1; shift ;; -s|--sound) TESTSOUND=$2; shift 2;; -h|--help) usage; exit 0 ;; -L|--log) LOGFILE="$2"; shift 2;; -p|--probe) legacy_probe_card="$2"; shift 2;; -P|--listprobe) echo "$LEGACY_CARDS"; exit 0;; -u|--uid) alsa_uid="$2"; shift 2;; -g|--gid) alsa_gid="$2"; shift 2;; -d|--devmode) alsa_mode="$2"; shift 2;; -r|--strict) alsa_uid=0; alsa_gid=17; alsa_mode=0660; shift;; -c|--config) cfgfile="$2"; shift 2;; -R|--resources) resources="true"; shift;; --) shift ; break ;; *) usage ; exit 1 ;; esacdone## probe legacy ISA cards#check_dma_avail () { list="" if [ -d $SYSFS/bus/pnp/devices ]; then for dma in $*; do ok="true" for i in $SYSFS/bus/pnp/devices/??:* ; do if grep -q "state = active" $i/resources ; then if grep -q '^dma '$dma'$' $i/resources; then ok="false" fi fi done if [ -r $PROCFS/dma ]; then if grep -q '^ *'$dma': ' $PROCFS/dma ; then ok="false" fi fi if [ "$ok" = "true" ]; then list="$list $dma" fi done else if [ -r $PROCFS/dma ]; then for dma in $*; do grep -q '^ *'$dma': ' $PROCFS/dma || list="$list $dma" done fi fi if [ ! -z "$list" ]; then echo $list fi}check_irq_avail () { list="" if [ -d $SYSFS/bus/pnp/devices ]; then for irq in $*; do ok="true" for i in $SYSFS/bus/pnp/devices/??:* ; do if grep -q "state = active" $i/resources ; then if grep -q '^irq '$irq'$' $i/resources; then ok="false" fi fi done if [ -r $PROCFS/interrupts ]; then if grep -q '^ *'$irq': ' $PROCFS/interrupts ; then ok="false" fi fi if [ "$ok" = "true" ]; then list="$list $irq" fi done else if [ -r $PROCFS/interrupts ]; then for irq in $*; do grep -q '^ *'$irq': ' $PROCFS/interrupts || list="$list $irq" done fi fi if [ ! -z "$list" ]; then echo $list fi}###if [ "$resources" = "true" ]; then if [ -d $SYSFS/bus/pnp/devices ]; then for i in $SYSFS/bus/pnp/devices/??:* ; do if [ "$resources" = "true" ]; then echo ">>>>> PnP file: $i/resources" cat $i/resources fi done fi if [ -r $PROCFS/dma ]; then echo ">>>>> Allocated dma channels:" cat $PROCFS/dma fi if [ -r $PROCFS/interrupts ]; then echo ">>>>> Allocated interrupt channels:" cat $PROCFS/interrupts fi echo -n "Valid DMA channels: " check_dma_avail 0 1 2 3 4 5 6 7 echo -n "Valid IRQ channels: " check_irq_avail 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 exit 0fi# Check for root privilegesif [ `id -u` -ne 0 ]; then xecho "You must be root to use this script." exit 1fi## check the snd_ prefix for ALSA module options# snd_ prefix is obsoleted since 0.9.0rc4.#if /sbin/modinfo -p snd | grep -q snd_ ; then mpfx="snd_"else mpfx=""fialsa_device_opts=""if /sbin/modinfo -p snd | grep -q uid ; then if [ x"$alsa_uid" != x0 ]; then alsa_device_opts="$alsa_device_opts ${mpfx}device_uid=$alsa_uid" fi if [ x"$alsa_gid" != x0 ]; then alsa_device_opts="$alsa_device_opts ${mpfx}device_gid=$alsa_gid" fifiif /sbin/modinfo -p snd | grep -q device_mode ; then if [ x"$alsa_mode" != x0 ]; then alsa_device_opts="$alsa_device_opts ${mpfx}device_mode=$alsa_mode" fificase `uname -r` in2.6.*) kernel="new" ;;*) kernel="old" ;;esac# cfgfile = base config file to remove/update the sound setting# cfgout = new config file to write the sound setting (if different from $cfgfile)if [ -n "$cfgfile" ]; then if [ ! -r "$cfgfile" ]; then xecho "ERROR: The config file doesn't exist: " echo $cfgfile exit 1 fielseif [ "$distribution" = "gentoo" ]; then cfgfile="/etc/modules.d/alsa"elif [ "$kernel" = "new" ]; then if [ -d /etc/modprobe.d ]; then cfgout="/etc/modprobe.d/sound" fi cfgfile="/etc/modprobe.conf"elif [ "$distribution" = "debian" ]; then cfgfile="/etc/modutils/sound"elif [ -e /etc/modules.conf ]; then cfgfile="/etc/modules.conf"elif [ -e /etc/conf.modules ]; then cfgfile="/etc/conf.modules"else cfgfile="/etc/modules.conf" touch /etc/modules.conffifi# Check for dialog, whiptail, gdialog, awk, ... ?if which dialog > /dev/null; then DIALOG=dialogelse if which whiptail > /dev/null; then whiptail_wrapper() { X1="$1" X2="$2" if [ $1 = --yesno ]; then X3=`expr $3 + 2` else X3=$3 fi shift 3 whiptail "$X1" "$X2" $X3 "$@" } DIALOG=whiptail_wrapper else xecho "Error, dialog or whiptail not found." exit 1 fifiif which awk > /dev/null; then :else xecho "Error, awk not found. Can't continue." exit 1fi## remove entries by yast2 sound configurator#remove_y2_block() { awk ' /^alias sound-slot-[0-9]/ { next } /^alias char-major-116 / { next } /^alias char-major-14 / { next } /^alias snd-card-[0-9] / { next } /^options snd / { next } /^options snd-/ { next } /^options off / { next } /^alias sound-service-[0-9]/ { next } /^# YaST2: sound / { next } { print }'}## remove entries by sndconfig sound configurator## found strings to search for in WriteConfModules, # from sndconfig 0.68-4 (rawhide version)remove_sndconfig_block() { awk ' /^alias sound-slot-0/ { modulename = $3 ; next } /^alias sound-slot-[0-9]/ { next } /^post-install sound-slot-[0-9] / { next } /^pre-remove sound-slot-[0-9] / { next } /^options sound / { next } /^alias synth0 opl3/ { next } /^options opl3 / { next } /^alias midi / { mididev = $3 ; next } /^options / { if ($2 == mididev) next } /^pre-install / { if ($2 == mididev) next } /^alias synth0 / { synth = $3 ; next } /^post-install / { if ($2 == synth) next } /^options sb / { next } /^post-install .+ \/bin\/modprobe "aci"/ { if ($2 == modulename) next } /^options adlib_card / { next } /^options .+ isapnp=1/ { if ($2 == modulename) next } /^options i810_audio / { next } /^options / {if ($2 == modulename) next } { print }'}## remove the previous configuration by alsaconf#remove_ac_block() { awk '/^'"$ACB"'$/,/^'"$ACE"'$/ { next } { print }'}## set default mixer volumes#set_mixers() { amixer -s -q <<EOFset Master 75% unmuteset Master -12dBset 'Master Mono' 75% unmuteset 'Master Mono' -12dBset Front 75% unmuteset Front -12dBset PCM 90% unmuteset PCM 0dBmixer Synth 90% unmutemixer Synth 0dBmixer CD 90% unmutemixer CD 0dB# mute micset Mic 0% mute# ESS 1969 chipset has 2 PCM channelsset PCM,1 90% unmuteset PCM,1 0dB# Trident/YMFPCI/emu10k1set Wave 100% unmuteset Music 100% unmuteset AC97 100% unmute# CS4237B chipset:set 'Master Digital' 75% unmute# Envy24 chips with analog outsset DAC 90% unmuteset DAC -12dBset DAC,0 90% unmuteset DAC,0 -12dBset DAC,1 90% unmuteset DAC,1 -12dB# some notebooks use headphone instead of masterset Headphone 75% unmuteset Headphone -12dBset Playback 100% unmute# turn off digital switchesset "SB Live Analog/Digital Output Jack" offset "Audigy Analog/Digital Output Jack" offEOF}# INTROintro() { local msg=$(xmsg " ALSA CONFIGURATOR version %s This script is a configurator for Advanced Linux Sound Architecture (ALSA) driver. If ALSA is already running, you should close all sound apps now and stop the sound driver. alsaconf will try to do this, but it's not 100%% sure." $version) $DIALOG --msgbox "$msg" 20 63 || acex 0}# FAREWELLfarewell() { local msg=$(gettext " OK, sound driver is configured. ALSA CONFIGURATOR will prepare the card for playing now. Now I'll run alsasound init script, then I'll use amixer to raise the default volumes. You can change the volume later via a mixer program such as alsamixer or gamix. ") $DIALOG --msgbox "$msg" 17 60 || acex 0}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -