postplug/postplug.d/35sound

104 lines
2.7 KiB
Plaintext
Raw Permalink Normal View History

2011-04-27 19:57:03 +02:00
#!/bin/bash
#
# sound - sound configuration plugin for postplug
# Copyright (c) 2005-2007 by Davide Madrisan <davide.madrisan@gmail.com>
# Copyright (c) 2005-2011 by Silvan Calarco <silvan.calarco@mambasoft.it>
2011-04-27 19:57:03 +02:00
# Note: Some code has been stolen from /usr/sbin/alsaconf version 1.0.13
if [ $UID != 0 ]; then
echo "$0: must be superuser." >&2
exit 1
fi
me="sound"
[ -r /etc/sysconfig/machine ] && . /etc/sysconfig/machine
. /etc/postplug/postplug.defs
[ -r /etc/sysconfig/postplug ] && . /etc/sysconfig/postplug
SYSCONFIG_SOUNDCARDS=/etc/sysconfig/soundcards
[ -e /etc/asound.state ] && rm -f /etc/asound.state
2011-04-27 19:57:03 +02:00
# set default mixer volumes
function set_mixers() {
[ -x /usr/bin/amixer ] || return
channel=$1
[ "$channel" ] || channel=0
2011-04-27 19:57:03 +02:00
/usr/bin/amixer -s -c $channel -q <<_EOF
# Playback channels
set 'Master' 90% unmute
# some notebooks use headphone instead of master
set 'Headphone' 75% unmute
set 'Playback' 100% unmute
2011-04-27 19:57:03 +02:00
set 'Master Mono' 75% unmute
set 'Front' 90% unmute
set 'Speaker' 90% unmute
set 'PCM' 90% unmute
set 'Surround' 90% unmute
set 'Center' 90% unmute
set 'LFE' 90% unmute
set 'Line' 75% unmute
set 'CD' 90% unmute
set 'Synth' 90% unmute
2011-04-27 19:57:03 +02:00
# mute mic
set 'Front Mic' 75% mute
set 'Mic' 75% mute
2011-04-27 19:57:03 +02:00
# ESS 1969 chipset has 2 PCM channels
set 'PCM,1' 90% unmute
2011-04-27 19:57:03 +02:00
# Trident/YMFPCI/emu10k1
set 'Wave' 100% unmute
set 'Music' 100% unmute
set 'AC97' 100% unmute
2011-04-27 19:57:03 +02:00
# CS4237B chipset:
set 'Master Digital' 75% unmute
# Envy24 chips with analog outs
set 'DAC' 90% unmute
set 'DAC,0' 90% unmute
set 'DAC,1' 90% unmute
# Capture channels
set 'Capture' 90% unmute
set 'Capture 1' 90% unmute
set 'Capture 2' 90% unmute
# virtual channels
set 'Capture Gain' 50% unmute
set 'Output Gain' 75% unmute
2011-04-27 19:57:03 +02:00
# turn off digital switches
set 'SB Live Analog/Digital Output Jack' off
set 'Audigy Analog/Digital Output Jack' off
2011-04-27 19:57:03 +02:00
_EOF
}
SOUND_DEV="`lspci -n | grep " 04[0-9][0-9]: "`"
2011-04-27 19:57:03 +02:00
if [ "$SOUND_FORCE_RESCAN" != "on" -a "$SOUND_FORCE_RESCAN" != "1" ]; then
if [ -e $postpluglibdir/sound.cache ]; then
SOUND_DEV_CACHED="`cat $postpluglibdir/sound.cache`"
[ "$SOUND_DEV" = "$SOUND_DEV_CACHED" ] && exit 0
logmsg "$me" "warning: audio device appears to have changed; re-probing"
mv $SYSCONFIG_SOUNDCARDS $SYSCONFIG_SOUNDCARDS.postplug.save
2011-04-27 19:57:03 +02:00
fi
fi
echo "$SOUND_DEV" > $postpluglibdir/sound.cache
for c in /proc/asound/card[0-9]*; do
id=`cat $c/id`
codec=`grep Codec: $c/codec* | head -n1`
logmsg "$me" $"setting volumes for $id sound card ($codec)"
index=${d1/*card}
set_mixers $index
done
if [ -x /usr/sbin/alsactl ]; then
logmsg "$me" $"saving the mixer setup (/var/lib/sound/asound.state)"
/usr/sbin/alsactl store >/dev/null
2011-04-27 19:57:03 +02:00
fi
echo "$SOUND_DEV" > $postpluglibdir/sound.cache
exit 0