summaryrefslogtreecommitdiff
path: root/configs/talkingparabola/airootfs/usr/bin/pick-a-card
blob: 10f2f795c2083a1f8ead36b81e3b1ebe55556092 (plain)
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
55
56
57
#!/bin/bash
#
# SPDX-License-Identifier: GPL-3.0-or-later

# If there are multiple usable sound cards, prompt the user to choose one,
# using auditory feedback.
# This script is released under the GNU General Public License.

# shellcheck disable=SC1091
source /usr/share/livecd-sound/functions

nwords() {
	echo $#
}

is_numeric() {
	local str=$1
	expr "$str" : '[[:digit:]]\+$' > /dev/null 2>&1
}

set_default_card() {
	local card=$1
	sed -e "s/%card%/$card/g" < /usr/share/livecd-sound/asound.conf.in \
	    > /etc/asound.conf
}

play_on_card() {
	local card=$1 file=$2
	aplay "-Dplughw:$card,0" "$file"
}

set -f
usable_cards="$(list_non_pcsp_cards)"
num_usable_cards=$(nwords "$usable_cards")

if [ "$num_usable_cards" -eq 1 ]; then
	exit 0
fi

for card in $usable_cards; do
	if ! is_numeric "$card"; then
		continue
	fi
	play_on_card "$card" /usr/share/livecd-sound/sounds/pick-a-card.wav&
done
wait
sleep 1
for card in $usable_cards; do
	if ! is_numeric "$card"; then
		continue
	fi
	play_on_card "$card" /usr/share/livecd-sound/sounds/beep.wav
	if read -rt 10; then
		set_default_card "$card"
		break
	fi
done