summaryrefslogtreecommitdiffstats
path: root/remote/modules/alsa/data/opt/openslx/scripts/alsa-default_card
blob: 4edfcdd5171eb2f50c296c714f91c8ccd7221529 (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
#!/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}" <<HEREDOC
pcm.!default {
	type hw
	card $CARD
}
ctl.!default {
	type hw
	card $CARD
}
timer.!default {
	type hw
	card $CARD
}
HEREDOC