From 2dee2021d08a0837ce40941fff43a4b09d692146 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 29 Sep 2014 16:05:00 +0200 Subject: [alsa] Set default sound card to first non-HDMI card --- .../etc/systemd/system/alsa-default-card.service | 11 +++++ .../alsa-default-card.service | 1 + .../data/opt/openslx/scripts/alsa-default_card | 47 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 remote/modules/alsa/data/etc/systemd/system/alsa-default-card.service create mode 120000 remote/modules/alsa/data/etc/systemd/system/multi-user.target.wants/alsa-default-card.service create mode 100755 remote/modules/alsa/data/opt/openslx/scripts/alsa-default_card diff --git a/remote/modules/alsa/data/etc/systemd/system/alsa-default-card.service b/remote/modules/alsa/data/etc/systemd/system/alsa-default-card.service new file mode 100644 index 00000000..db35eeb7 --- /dev/null +++ b/remote/modules/alsa/data/etc/systemd/system/alsa-default-card.service @@ -0,0 +1,11 @@ +[Unit] +Description=Set default card ALSA will use +DefaultDependencies=no +After=tmp.target +Wants=tmp.target + +[Service] +Type=oneshot +ExecStart=/opt/openslx/scripts/alsa-default_card +RemainAfterExit=yes + diff --git a/remote/modules/alsa/data/etc/systemd/system/multi-user.target.wants/alsa-default-card.service b/remote/modules/alsa/data/etc/systemd/system/multi-user.target.wants/alsa-default-card.service new file mode 120000 index 00000000..55e393fd --- /dev/null +++ b/remote/modules/alsa/data/etc/systemd/system/multi-user.target.wants/alsa-default-card.service @@ -0,0 +1 @@ +../alsa-default-card.service \ No newline at end of file diff --git a/remote/modules/alsa/data/opt/openslx/scripts/alsa-default_card b/remote/modules/alsa/data/opt/openslx/scripts/alsa-default_card new file mode 100755 index 00000000..4edfcdd5 --- /dev/null +++ b/remote/modules/alsa/data/opt/openslx/scripts/alsa-default_card @@ -0,0 +1,47 @@ +#!/bin/ash + +PROC="/proc/asound/cards" + +if [ ! -r "$PROC" ]; then + echo "'${PROC}' not found or not readable." + exit 1 +fi + +if [ -w "/etc" ]; then + FILE="/etc/asound.conf" +elif [ -n "$HOME" ]; then + FILE="${HOME}/.asoundrc" +else + FILE="$(getent passwd root | awk -F ':' '{print $6}')/.asoundrc" +fi + +if [ -e "${FILE}" -a "x$1" != "x--force" ]; then + echo "'${FILE}' already exists, use --force to overwrite." + exit 1 +fi + +# Try to filter HDMI cards first +CARD=$(grep -v -i 'HDMI' "${PROC}" | grep -E -o '^[[:space:]]*[0-9]+[[:space:]]+' | head -n 1) +# If empty, try again with all +[ -z "${CARD}" ] && CARD=$(cat "${PROC}" | grep -E -o '^[[:space:]]*[0-9]+[[:space:]]+' | head -n 1) + +if [ -z "${CARD}" ]; then + echo "No sound card found." + exit 1 +fi + +cat > "${FILE}" <