From 693eaed422c402845c1537f84776e4de5b6b9364 Mon Sep 17 00:00:00 2001 From: pzmarzly Date: Fri, 23 Oct 2020 15:23:17 +0200 Subject: [PATCH 1/2] Add error handling --- mic_over_mumble | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/mic_over_mumble b/mic_over_mumble index 01ac052..5540f35 100755 --- a/mic_over_mumble +++ b/mic_over_mumble @@ -7,7 +7,6 @@ set -euo pipefail # ID = PID / process ID main () { - prepare_env set_up echo "Press Return to shut down..." read -n1 -s -r @@ -38,6 +37,7 @@ run_mumble_client_wizard () { } set_up () { + prepare_env start_mumble_server start_mumble_client change_pa_config @@ -136,20 +136,48 @@ set_default_source () { # Data fetching & parsing. get_mumble_client_paid () { - pacmd list-sink-inputs | + result=$(pacmd list-sink-inputs | grep -F -e "index: " -e "media.name = " | cut_every_second_newline | grep -F -e "Mumble" | - print_second_column + take_second_column) + + if [ -z "$result" ]; then + echo "Error: Mumble client did not connect to PulseAudio (yet?)." 2>&1 + print_how_to_restart 2>&1 + exit 1 + fi + + if [ "$(echo "$result" | wc -l)" != "1" ]; then + echo "Error: Multiple Mumble instances found." 2>&1 + print_how_to_restart 2>&1 + exit 1 + fi + + echo "$result" } get_sink_paid () { - pacmd list-sinks | + result=$(pacmd list-sinks | grep -F -e "index: " -e "name: " | cut_every_second_newline | grep -F -e "Loopback" | cut_active_device_indicator | - print_second_column + take_second_column) + + if [ -z "$result" ]; then + echo "Error: Failed to find the device the script should have added." 2>&1 + print_how_to_restart 2>&1 + exit 1 + fi + + if [ "$(echo "$result" | wc -l)" != "1" ]; then + echo "Error: Multiple virtual devices found." 2>&1 + print_how_to_restart 2>&1 + exit 1 + fi + + echo "$result" } # https://serverfault.com/a/375098/449626 @@ -157,7 +185,7 @@ cut_every_second_newline () { awk 'ORS=NR%2?" ":"\n"' } -print_second_column () { +take_second_column () { awk '{print $2}' } @@ -168,4 +196,13 @@ cut_active_device_indicator () { cut -c 5- } +# Errors + +print_how_to_restart () { + echo "Please find the reason why this happened, try fixing it" + echo "(\`pacmd list-sink-inputs\` and \`pacmd list-sinks\` may be" + echo "useful), then kill mumble and murmurd, restart PulseAudio via" + echo "\`pulseaudio -k\`, and finally, restart the script." +} + main From 4780802f52a99c1c32baeea79ba30d17abd70a69 Mon Sep 17 00:00:00 2001 From: pzmarzly Date: Wed, 11 Nov 2020 13:01:54 +0100 Subject: [PATCH 2/2] add more comments --- mic_over_mumble | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mic_over_mumble b/mic_over_mumble index 5540f35..e1a801c 100755 --- a/mic_over_mumble +++ b/mic_over_mumble @@ -1,4 +1,5 @@ #!/bin/bash +# https://github.com/pzmarzly/mic_over_mumble set -euo pipefail # To debug, uncomment the following line: # set -x @@ -52,12 +53,16 @@ shut_down () { } start_mumble_client () { - echo "Starting Mumble client..." + echo "Starting Mumble client (a window should appear in a moment)..." mumble "mumble://localhost" >/dev/null 2>&1 & MUMBLE_CLIENT_ID=$! + # FIXME: I don't remember why I thought this + # was necessary. disown # Mumble is slow to launch, and the # user may need to click on OK button. + # FIXME: probe PulseAudio server to see if + # Mumble has connected. sleep 15 }