#!/bin/ash PROC="/proc/asound/pcm" i=0 while [ "$(( ++i ))" -lt 10 ]; do [ -r "$PROC" ] && break sleep 1 done if ! [ -r "$PROC" ]; then echo "'${PROC}' not found or not readable. Not setting default sound card." exit 0 fi if [ -w "/etc" ]; then FILE="/etc/asound.conf" elif [ -n "$HOME" ]; then FILE="${HOME}/.asoundrc" else FILE="$(getent passwd "$(id -u)" | 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 . /opt/openslx/config GREPOPT="-v -m 1" if [ "x$SLX_PREFERRED_SOUND_OUTPUT" = "xHDMI" ]; then # Prefer HDMI, so let's check whether there is actually # something connected via HDMI. This might still be screen # that doesn't support sound output, but it's better than nothing found=false cnt=1 for i in /sys/class/drm/card*-HDMI*; do if [ "x$(cat "$i/status")" = "xconnected" ]; then found=true break fi cnt=$(( cnt + 1 )) done if $found; then GREPOPT="-m $cnt" fi fi # Try to filter/prefer HDMI cards tmpf=$( mktemp ) [ -z "$tmpf" ] && tmpf=/tmp/borkenbämpfong sort -u "${PROC}" | grep $GREPOPT -i HDMI | tail -n 1 | cut -c1-5 | tr -- '-' ' ' > "$tmpf" < "$tmpf" read card device _ rm -f -- "$tmpf" # If empty, do nothing so defaults get used if [ -z "${card}" ]; then echo "No suitable sound card found, defaults apply." exit 0 fi # Remove leading zero if any (both values are two digit) card=${card#0} device=${device#0} cat > "${FILE}" <