summaryrefslogtreecommitdiffstats
path: root/core/modules/alsa/data/opt/openslx/scripts/alsa-default_card
blob: cd0b301d8f9831636b7de9037210fa353ea7e365 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/ash

PROC="/proc/asound/pcm"

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 "$(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"
if [ "x$SLX_PREFERRED_SOUND_OUTPUT" = "xHDMI" ]; then
	GREPOPT=
fi
# Try to filter/prefer HDMI cards
tmpf=$( mktemp )
[ -z "$tmpf" ] && tmpf=/tmp/borkenbämpfong
sort -u "${PROC}" | grep $GREPOPT -i HDMI -m 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}" <<HEREDOC
defaults.pcm.!card $card
defaults.ctl.!card $card

defaults.pcm.!device $device
defaults.ctl.!device $device

HEREDOC