~ubuntu-branches/ubuntu/trusty/alsa-utils/trusty

« back to all changes in this revision

Viewing changes to debian/init

  • Committer: Package Import Robot
  • Author(s): Luke Yelavich
  • Date: 2013-07-26 10:56:44 UTC
  • mfrom: (1.2.17) (93.1.1 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130726105644-kim9enke2jnozg73
Tags: 1.0.27.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Move init script volume settings to new alsactl database:
    + Set sane level for 'Speaker' and 'Headphone', needed for Dell Mini 9
      and Dell E series
    + ute PC Beep on hda cards that support it during initial volume setup
    + Mute *Analog/Digital Control for Creative cards by default
    + Default Digital Input Source to be Digital Mic 1 so that users
      with digital mic will be able to use it out of the box
    + Mute "IEC958 Optical Raw" by default
    + Set sane level for headphone 1 for Dell Studio XPS with 2.6.30
    + Prefer built-in digital mics on newer Dells
    + Unmute 'Line HP Swap' for Dove boards
    + Set reasonable volume levels for VMWare guests using snd.ens1371
  - debian/README.init.cs4236: Include in /usr/share/doc/alsa-utils so that
    users of snd-cs4236 (e.g., ThinkPad 600) can have audible sound
  - debian/patches/unset_pulse_internal.patch: We don't want alsamixer to
    show the pulse mixer by default, since it can be controlled from
    pulseaudio itself
  - Use upstart jobs for storing/restoring card settings
  - Add udev rule to apply UCM profiles for panda and equivalent hardware
  - Add Vcs-Bzr field
* Create a new upstart job for the alsa state daemon, and adjust the
  other upstart jobs accordingly
* Put the daemon file in /var/lib/alsa

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# alsa-utils initscript
 
4
#
 
5
### BEGIN INIT INFO
 
6
# Provides:          alsa-utils
 
7
# Required-Start:    $local_fs $remote_fs
 
8
# Required-Stop:     $remote_fs
 
9
# Default-Start:     S
 
10
# Default-Stop:      0 1 6
 
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
 
18
#                    "K50alsa-utils".
 
19
### END INIT INFO
 
20
 
 
21
# Don't use set -e; check exit status instead
 
22
 
 
23
# Exit silently if package is no longer installed
 
24
[ -x /usr/sbin/alsactl ] || exit 0
 
25
 
 
26
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 
27
MYNAME=/etc/init.d/alsa-utils
 
28
 
 
29
. /lib/lsb/init-functions
 
30
. /usr/share/alsa/utils.sh
 
31
 
 
32
# $1 EXITSTATUS
 
33
# [$2 MESSAGE]
 
34
log_action_end_msg_and_exit()
 
35
{
 
36
        log_action_end_msg "$1" ${2:+"$2"}
 
37
        exit $1
 
38
}
 
39
 
 
40
# $1 PROGRAM
 
41
executable()
 
42
{
 
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
 
48
}
 
49
 
 
50
executable amixer || { echo "${MYNAME}: Error: No amixer program available." >&2 ; exit 1 ; }
 
51
 
 
52
# $1 <card ID> | "all"
 
53
restore_levels()
 
54
{
 
55
        [ -f /var/lib/alsa/asound.state ] || return 1
 
56
        CARD="$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
 
63
                return 0
 
64
        else
 
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'"
 
69
                return 1
 
70
        fi
 
71
}
 
72
 
 
73
# $1 <card ID> | "all"
 
74
store_levels()
 
75
{
 
76
        CARD="$1"
 
77
        [ "$1" = all ] && CARD=""
 
78
        if MSG="$(alsactl store $CARD 2>&1)" ; then
 
79
                sleep 1
 
80
                return 0
 
81
        else
 
82
                log_action_cont_msg "warning: 'alsactl store${CARD:+ $CARD}' failed with error message '$MSG'"
 
83
                return 1
 
84
        fi
 
85
}
 
86
 
 
87
 
 
88
# $1 <card ID>
 
89
mute_and_zero_levels_on_card()
 
90
{
 
91
        CARDOPT="-c $1"
 
92
        for CTL in \
 
93
                Master \
 
94
                PCM \
 
95
                Synth \
 
96
                CD \
 
97
                Line \
 
98
                Mic \
 
99
                "PCM,1" \
 
100
                Wave \
 
101
                Music \
 
102
                AC97 \
 
103
                "Master Digital" \
 
104
                DAC \
 
105
                "DAC,0" \
 
106
                "DAC,1" \
 
107
                Headphone \
 
108
                Speaker \
 
109
                Playback
 
110
        do
 
111
                mute_and_zero_level "$CTL"
 
112
        done
 
113
#       for CTL in \
 
114
#               "Audigy Analog/Digital Output Jack" \
 
115
#               "SB Live Analog/Digital Output Jack"
 
116
#       do
 
117
#               switch_control "$CTL" off
 
118
#       done
 
119
        return 0
 
120
}
 
121
 
 
122
# $1 <card ID> | "all"
 
123
mute_and_zero_levels()
 
124
{
 
125
        TTZML_RETURNSTATUS=0
 
126
        case "$1" in
 
127
          all)
 
128
                for CARD in $(echo_card_indices) ; do
 
129
                        mute_and_zero_levels_on_card "$CARD" || TTZML_RETURNSTATUS=1
 
130
                done
 
131
                ;;
 
132
          *)
 
133
                mute_and_zero_levels_on_card "$1" || TTZML_RETURNSTATUS=1
 
134
                ;;
 
135
        esac
 
136
        return $TTZML_RETURNSTATUS
 
137
}
 
138
 
 
139
 
 
140
# $1 <card ID> | "all"
 
141
card_OK()
 
142
{
 
143
        [ "$1" ] || bugout
 
144
        if [ "$1" = all ] ; then
 
145
                [ -d /proc/asound ]
 
146
                return $?
 
147
        else
 
148
                [ -d "/proc/asound/card$1" ] || [ -d "/proc/asound/$1" ]
 
149
                return $?
 
150
        fi
 
151
}
 
152
 
 
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.
 
155
 
 
156
case "$1" in
 
157
  start)
 
158
        EXITSTATUS=0
 
159
        TARGET_CARD="$2"
 
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}" ;;
 
163
        esac
 
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 || :
 
169
        fi
 
170
        log_action_end_msg_and_exit "$EXITSTATUS"
 
171
        ;;
 
172
  stop)
 
173
        EXITSTATUS=0
 
174
        TARGET_CARD="$2"
 
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}" ;;
 
178
        esac
 
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"
 
183
        ;;
 
184
  restart|force-reload)
 
185
        EXITSTATUS=0
 
186
        $0 stop || EXITSTATUS=1
 
187
        $0 start || EXITSTATUS=1
 
188
        exit $EXITSTATUS
 
189
        ;;
 
190
  reset)
 
191
        TARGET_CARD="$2"
 
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}" ;;
 
195
        esac
 
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 "$?"
 
200
        ;;
 
201
  *)
 
202
        echo "Usage: $MYNAME {start [CARD]|stop [CARD]|restart [CARD]|reset [CARD]}" >&2
 
203
        exit 3
 
204
        ;;
 
205
esac
 
206