Re: [Tails-dev] Small patch to mute sound on boot time

Nachricht löschen

Nachricht beantworten
Autor: CAN Consulting
Datum:  
To: intrigeri
CC: The Tails public development discussion list
Betreff: Re: [Tails-dev] Small patch to mute sound on boot time
On 20.06.2011 17:17, intrigeri wrote:
> Hi JohnDoe,
>
> anything new on this front?
> anything unclear in my last email?
>
> Bye,


Building Tails succeeded the first time yesterday; thanking intrigeri
for help.
init.d script tails-alsa-mute working; new line in 52-update-rc.d
seemingly works too.
Tails iso file created by lb build muted sound channels on bootup;
attached patch should
apply on devel branch without errors; besides that, all quiet on the
western front. ;)

Bye,

JohnDoe
>From 1b7b722efe7bc6c60ac11ab5fafa63af6d7b3178 Mon Sep 17 00:00:00 2001
From: use <user@localhost>
Date: Wed, 22 Jun 2011 14:27:21 +0200
Subject: [PATCH] Added init.d Script tails-alsa-mute to mute sound on
bootupand changed 52-update-rc.d hook

---
 config/chroot_local-hooks/52-update-rc.d           |    1 +
 .../etc/init.d/tails-alsa-mute                     |  179 ++++++++++++++++++++
 2 files changed, 180 insertions(+), 0 deletions(-)
 create mode 100755 config/chroot_local-includes/etc/init.d/tails-alsa-mute


diff --git a/config/chroot_local-hooks/52-update-rc.d b/config/chroot_local-hooks/52-update-rc.d
index 30c1362..efaa8d2 100755
--- a/config/chroot_local-hooks/52-update-rc.d
+++ b/config/chroot_local-hooks/52-update-rc.d
@@ -8,6 +8,7 @@ update-rc.d tails-kexec                    stop 85 0 6 .
 update-rc.d tails-wifi start 17 S .
 update-rc.d memlockd start 22 2 3 4 5 .
 update-rc.d tails-sdmem-on-media-removal start 23 2 3 4 5 . stop 01 0 6
+update-rc.d tails-alsa-mute defaults


 # we run Tor ourselves after HTP via NetworkManager hooks
 update-rc.d tor disable
diff --git a/config/chroot_local-includes/etc/init.d/tails-alsa-mute b/config/chroot_local-includes/etc/init.d/tails-alsa-mute
new file mode 100755
index 0000000..a9c4943
--- /dev/null
+++ b/config/chroot_local-includes/etc/init.d/tails-alsa-mute
@@ -0,0 +1,179 @@
+#!/bin/sh
+#
+# alsa-mute initscript
+#
+### BEGIN INIT INFO
+# Provides:          alsa-mute
+# Required-Start:    $remote_fs udev alsa-utils
+# Required-Stop:     $remote_fs
+# Default-Start:     S
+# Default-Stop:      0 1 6
+# Short-Description: Mute channels in ALSA
+# Description:       This script mutes and zeroes channel levels on
+#                    bootup. Muting the channels prevents
+#                    accidential sound playing for Tails users.
+#                    To hear sounds, just unmute and raise the volume
+#                    levels of the channels you need.
+#                    This script is just a copy of Debians alsa-utils initscript
+#                    with unneccessary parts removed and a call of the
+#                    mute procedure on start). The alsa functions are
+#                    outsourced to this script so we don't need to
+#                    patch alsa-utils and update every time alsa-utils changes.
+### END INIT INFO
+
+# Don't use set -e; check exit status instead
+
+# Exit silently if package is no longer installed
+[ -x /usr/sbin/alsactl ] || exit 0
+
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+MYNAME=/etc/init.d/alsa-utils
+
+. /lib/lsb/init-functions
+
+# $1 EXITSTATUS
+# [$2 MESSAGE]
+log_action_end_msg_and_exit()
+{
+    log_action_end_msg "$1" ${2:+"$2"}
+    exit $1
+}
+
+# $1 PROGRAM
+executable()
+{
+    # If which is not available then we must be running before
+    # /usr is mounted on a system that has which in /usr/bin/.
+    # Conclude that $1 is not executable.
+    [ -x /bin/which ] || [ -x /usr/bin/which ] || return 1
+    which "$1" >/dev/null 2>&1
+}
+
+executable amixer || { echo "${MYNAME}: Error: No amixer program available." >&2 ; exit 1 ; }
+
+bugout() { echo "${MYNAME}: Programming error" >&2 ; exit 123 ; }
+
+echo_card_indices()
+{
+    if [ -f /proc/asound/cards ] ; then
+        sed -n -e's/^[[:space:]]*\([0-7]\)[[:space:]].*/\1/p' /proc/asound/cards
+    fi
+}
+
+filter_amixer_output()
+{
+    sed \
+        -e '/Unable to find simple control/d' \
+        -e '/Unknown playback setup/d' \
+        -e '/^$/d'
+}
+
+# The following functions try to set many controls.
+# No card has all the controls and so some of the attempts are bound to fail.
+# Because of this, the functions can't return useful status values.
+
+# $1 <control>
+# $CARDOPT
+mute_and_zero_level()
+{
+    { [ "$1" ] && [ "$CARDOPT" ] ; } || bugout
+    amixer $CARDOPT -q set "$1" "0%" mute 2>&1 | filter_amixer_output || :
+    return 0
+}
+
+# $1 <control>
+# $2 "on" | "off"
+# $CARDOPT
+switch_control()
+{
+    { [ "$2" ] && [ "$CARDOPT" ] ; } || bugout
+    amixer $CARDOPT -q set "$1" "$2" 2>&1 | filter_amixer_output || :
+    return 0
+}
+
+# $1 <card ID>
+mute_and_zero_levels_on_card()
+{
+    CARDOPT="-c $1"
+    for CTL in \
+        Master \
+        PCM \
+        Synth \
+        CD \
+        Line \
+        Mic \
+        "PCM,1" \
+        Wave \
+        Music \
+        AC97 \
+        "Master Digital" \
+        DAC \
+        "DAC,0" \
+        "DAC,1" \
+        Headphone \
+        Speaker \
+        Playback
+    do
+        mute_and_zero_level "$CTL"
+    done
+#    for CTL in \
+#        "Audigy Analog/Digital Output Jack" \
+#        "SB Live Analog/Digital Output Jack"
+#    do
+#        switch_control "$CTL" off
+#    done
+    return 0
+}
+
+# $1 <card ID> | "all"
+mute_and_zero_levels()
+{
+    TTZML_RETURNSTATUS=0
+    case "$1" in
+      all)
+        for CARD in $(echo_card_indices) ; do
+            mute_and_zero_levels_on_card "$CARD" || TTZML_RETURNSTATUS=1
+        done
+        ;;
+      *)
+        mute_and_zero_levels_on_card "$1" || TTZML_RETURNSTATUS=1
+        ;;
+    esac
+    return $TTZML_RETURNSTATUS
+}
+
+
+# $1 <card ID> | "all"
+card_OK()
+{
+    [ "$1" ] || bugout
+    if [ "$1" = all ] ; then
+        [ -d /proc/asound ]
+        return $?
+    else
+        [ -d "/proc/asound/card$1" ] || [ -d "/proc/asound/$1" ]
+        return $?
+    fi
+}
+
+# If a card identifier is provided in $2 then regard it as an error
+# if that card is not present; otherwise don't regard it as an error.
+
+case "$1" in
+  start)
+    EXITSTATUS=0
+    TARGET_CARD="$2"
+    case "$TARGET_CARD" in
+      ""|all) TARGET_CARD=all ; log_action_begin_msg "Muting ALSA" ;;
+      *) log_action_begin_msg "Muting ALSA card ${TARGET_CARD}" ;;
+    esac
+    card_OK "$TARGET_CARD" || log_action_end_msg_and_exit "$( [ ! "$2" ] ; echo $? ; )" "none loaded"
+    mute_and_zero_levels "$TARGET_CARD" || EXITSTATUS=1
+    log_action_end_msg_and_exit "$EXITSTATUS"
+    ;;
+  *)
+    echo "Usage: $MYNAME {start [CARD]}" >&2
+    exit 3
+    ;;
+esac
+
-- 
1.7.5.3