3
# alsa-utils initscript
7
# Required-Start: $local_fs $remote_fs
8
# Required-Stop: $remote_fs
11
# Short-Description: Restore and store ALSA driver settings
12
# Description: This script stores and restores mixer levels on
13
# shutdown and bootup.On sysv-rc systems: to
14
# disable storing of mixer levels on shutdown,
15
# remove /etc/rc[06].d/K50alsa-utils. To disable
16
# restoring of mixer levels on bootup, rename the
17
# "S50alsa-utils" symbolic link in /etc/rcS.d/ to
21
# Don't use set -e; check exit status instead
23
# Exit silently if package is no longer installed
24
[ -x /usr/sbin/alsactl ] || exit 0
26
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
27
MYNAME=/etc/init.d/alsa-utils
29
. /lib/lsb/init-functions
30
. /usr/share/alsa/utils.sh
34
log_action_end_msg_and_exit()
36
log_action_end_msg "$1" ${2:+"$2"}
43
# If which is not available then we must be running before
44
# /usr is mounted on a system that has which in /usr/bin/.
45
# Conclude that $1 is not executable.
46
[ -x /bin/which ] || [ -x /usr/bin/which ] || return 1
47
which "$1" >/dev/null 2>&1
50
executable amixer || { echo "${MYNAME}: Error: No amixer program available." >&2 ; exit 1 ; }
52
# $1 <card ID> | "all"
55
[ -f /var/lib/alsa/asound.state ] || return 1
57
[ "$1" = all ] && CARD=""
58
# Assume that if alsactl prints a message on stderr
59
# then it failed somehow. This works around the fact
60
# that alsactl doesn't return nonzero status when it
61
# can't restore settings for the card
62
if MSG="$(alsactl restore $CARD 2>&1 >/dev/null)" && [ ! "$MSG" ] ; then
65
# Retry with the "force" option. This restores more levels
66
# but it results in much longer error messages.
67
alsactl -F restore $CARD >/dev/null 2>&1
68
log_action_cont_msg "warning: 'alsactl restore${CARD:+ $CARD}' failed with error message '$MSG'"
73
# $1 <card ID> | "all"
77
[ "$1" = all ] && CARD=""
78
if MSG="$(alsactl store $CARD 2>&1)" ; then
82
log_action_cont_msg "warning: 'alsactl store${CARD:+ $CARD}' failed with error message '$MSG'"
89
mute_and_zero_levels_on_card()
111
mute_and_zero_level "$CTL"
114
# "Audigy Analog/Digital Output Jack" \
115
# "SB Live Analog/Digital Output Jack"
117
# switch_control "$CTL" off
122
# $1 <card ID> | "all"
123
mute_and_zero_levels()
128
for CARD in $(echo_card_indices) ; do
129
mute_and_zero_levels_on_card "$CARD" || TTZML_RETURNSTATUS=1
133
mute_and_zero_levels_on_card "$1" || TTZML_RETURNSTATUS=1
136
return $TTZML_RETURNSTATUS
140
# $1 <card ID> | "all"
144
if [ "$1" = all ] ; then
148
[ -d "/proc/asound/card$1" ] || [ -d "/proc/asound/$1" ]
153
# If a card identifier is provided in $2 then regard it as an error
154
# if that card is not present; otherwise don't regard it as an error.
160
case "$TARGET_CARD" in
161
""|all) TARGET_CARD=all ; log_action_begin_msg "Setting up ALSA" ;;
162
*) log_action_begin_msg "Setting up ALSA card ${TARGET_CARD}" ;;
164
card_OK "$TARGET_CARD" || log_action_end_msg_and_exit "$( [ ! "$2" ] ; echo $? ; )" "none loaded"
165
preinit_levels "$TARGET_CARD" || EXITSTATUS=1
166
if ! restore_levels "$TARGET_CARD" ; then
167
sanify_levels "$TARGET_CARD" || EXITSTATUS=1
168
restore_levels "$TARGET_CARD" >/dev/null 2>&1 || :
170
log_action_end_msg_and_exit "$EXITSTATUS"
175
case "$TARGET_CARD" in
176
""|all) TARGET_CARD=all ; log_action_begin_msg "Shutting down ALSA" ;;
177
*) log_action_begin_msg "Shutting down ALSA card ${TARGET_CARD}" ;;
179
card_OK "$TARGET_CARD" || log_action_end_msg_and_exit "$( [ ! "$2" ] ; echo $? ; )" "none loaded"
180
store_levels "$TARGET_CARD" || EXITSTATUS=1
181
#mute_and_zero_levels "$TARGET_CARD" || EXITSTATUS=1
182
log_action_end_msg_and_exit "$EXITSTATUS"
184
restart|force-reload)
186
$0 stop || EXITSTATUS=1
187
$0 start || EXITSTATUS=1
192
case "$TARGET_CARD" in
193
""|all) TARGET_CARD=all ; log_action_begin_msg "Resetting ALSA" ;;
194
*) log_action_begin_msg "Resetting ALSA card ${TARGET_CARD}" ;;
196
card_OK "$TARGET_CARD" || log_action_end_msg_and_exit "$( [ ! "$2" ] ; echo $? ; )" "none loaded"
197
preinit_levels "$TARGET_CARD"
198
sanify_levels "$TARGET_CARD"
199
log_action_end_msg_and_exit "$?"
202
echo "Usage: $MYNAME {start [CARD]|stop [CARD]|restart [CARD]|reset [CARD]}" >&2