From 67cbc09f43c7f5b437787b43565b71723e2b36b3 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 25 May 2025 05:59:24 +0200 Subject: [PATCH 01/10] imporved option parsing and GUI detection --- pulseaudio-tcp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index 3fbdb7c..79bcbb3 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -44,7 +44,7 @@ log() { if [[ -t 1 ]] && $gui && [[ -n $(type -p zenity) ]] ; then case "$level" in - ERROR) + ERROR|WARNING) zenity --error --text="$msg" ;; *) @@ -58,6 +58,10 @@ error() { log ERROR "$@" } +warning() { + log WARNING "$@" +} + info() { log INFO "$@" } @@ -447,9 +451,16 @@ do_stop() { # Arguments operation= +no_more_options=false for arg in "$@" ; do case "$arg" in + --) + no_more_options=true + ;; + --*) + "$no_more_options" && { gui=false error "Option arguments may not preceed non-option arguments." ; exit 1 ; } + ;;& --debug) debug_cmdline=true ;; @@ -460,11 +471,11 @@ for arg in "$@" ; do help_cmdline=true ;; start|stop|restart|setup|status) - [[ -z $operation ]] || { error "Multiple operations are not supported." ; exit 1 ; } + [[ -z $operation ]] || { gui=false error "Multiple operations are not supported." ; exit 1 ; } operation=$arg ;; *) - error "Unsupported argument (try \"--help\")" + gui=false error "Unsupported argument (try \"--help\")" exit 1 ;; esac @@ -489,6 +500,12 @@ fi if [[ $gui_cmdline = false ]] ; then gui=false +elif [[ -z $(type -p zenity) ]] ; then + gui=false + warning "Disabling GUI support, because command \"zenity\" was not found." +elif ! [[ -v DISPLAY ]] && ! [[ -v XDG_SESSION_TYPE ]] ; then + gui=false + warning "Disabling GUI support, because neither \"DISPLAY\" not \"XDG_SESSION_TYPE\ is set." else gui=true fi @@ -523,7 +540,6 @@ else fi required_cmds=( jq pactl ssh ) - "$gui" && required_cmds+=( zenity ) for exe in "${required_cmds[@]}" ; do if [[ -z $(type -p "$exe") ]] ; then From 43f4bd632b38080fefd8ba58c20edaa06014f26d Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 25 May 2025 06:10:11 +0200 Subject: [PATCH 02/10] bugfix in determining XDG_SESSION_TYPE --- pulseaudio-tcp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index 79bcbb3..fbf82a4 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -506,6 +506,9 @@ elif [[ -z $(type -p zenity) ]] ; then elif ! [[ -v DISPLAY ]] && ! [[ -v XDG_SESSION_TYPE ]] ; then gui=false warning "Disabling GUI support, because neither \"DISPLAY\" not \"XDG_SESSION_TYPE\ is set." +elif [[ $XDG_SESSION_TYPE = tty ]] ; then + gui=false + warning "Disabling GUI support, because \"XDG_SESSION_TYPE\ is set to \"tty\"." else gui=true fi From d93979c5275f841e8f7cf65c88a7cb80bf00e7c3 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 25 May 2025 06:15:14 +0200 Subject: [PATCH 03/10] correct completion option name to "--no-gui" --- pulseaudio-tcp.bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index 522b513..8d8568a 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -8,7 +8,7 @@ _pulseaudio_tcp_completions() { options \ word - options=( "--debug" "--help" "--nogui" ) + options=( "--debug" "--help" "--no-gui" ) commands=( "start" "stop" "status" "setup" "restart" ) cur=${COMP_WORDS[COMP_CWORD]} From 6c9e822ccf945f3f28aee0404cefebffeef007d2 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 25 May 2025 06:47:35 +0200 Subject: [PATCH 04/10] update completion --- pulseaudio-tcp.bash_completion | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index 8d8568a..4ee07f3 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -8,18 +8,24 @@ _pulseaudio_tcp_completions() { options \ word - options=( "--debug" "--help" "--no-gui" ) + options=( "--debug" "--help" "--no-gui" "--" ) commands=( "start" "stop" "status" "setup" "restart" ) cur=${COMP_WORDS[COMP_CWORD]} + more_options=true for word in "${COMP_WORDS[@]}" ; do [[ $word = "$cur" ]] && continue + [[ $word = -- ]] && more_options=false options=("${options[@]/$word}") commands=("${commands[@]/$word}") done - option_list="${options[*]}" + if "$more_options" ; then + option_list="${options[*]}" + else + option_list="" + fi printf -v command_pattern "%s|" "${commands[@]}" command_pattern="(${command_pattern%?})" From 01dffe289ab110b46966b9a0adec3d9c05e56c24 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 25 May 2025 06:54:07 +0200 Subject: [PATCH 05/10] corrections to behavior of --debug option --- pulseaudio-tcp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index fbf82a4..6be38e4 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -68,8 +68,6 @@ info() { debug() { if "$debug" ; then - log DEBUG "$@" - else gui=false log DEBUG "$@" fi } @@ -237,17 +235,23 @@ do_status() { if ! _ssh pactl list modules | grep -Fq "Name: module-native-protocol-tcp" ; then errors+=("PulseAudio module \"module-native-protocol-tcp\" is not loaded on remote host $remote_ip.") rv=1 + else + debug "PulseAudio module \"module-native-protocol-tcp\" is loaded on remote host $remote_ip." fi if "$outbound" ; then if ! pactl list modules | grep -Fq "Name: module-tunnel-sink" ; then errors+=("PulseAudio module \"module-tunnel-sink\" is not loaded.") rv=1 + else + debug "PulseAudio module \"module-tunnel-sink\" is loaded." fi if ! pactl get-default-sink | grep -Fq "tunnel-sink.tcp:127.0.0.1" ; then errors+=("\"tunnel-sink.tcp:127.0.0.1\" is not the default PulseAudio sink.") rv=1 + else + debug "\"tunnel-sink.tcp:127.0.0.1\" is the default PulseAudio sink." fi fi @@ -255,6 +259,8 @@ do_status() { if ! pactl list modules | grep -Fq "Name: module-tunnel-source" ; then errors+=("PulseAudio module \"module-tunnel-source\" is not loaded.") rv=1 + else + debug "PulseAudio module \"module-tunnel-source\" is loaded." fi fi From e32fb0a9d25aa841f54412e0996841e2d7702504 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 1 Jun 2025 00:40:30 +0200 Subject: [PATCH 06/10] implement --commit option for stating PA cookie directly --- pulseaudio-tcp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index 6be38e4..3566d5d 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -24,8 +24,10 @@ usage() { cat >&2 < ~/.config/pulse/cookie + elif _scp "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then debug "Synced PulseAudio cookie from remote host $remote_ip." return 0 else @@ -457,9 +465,15 @@ do_stop() { # Arguments operation= +cookie= no_more_options=false +# shellcheck disable=SC2034 + +while [[ $# -gt 0 ]] ; do + arg=$1 + shift + echo "DEBUG: parsing arg=$arg .." >&2 -for arg in "$@" ; do case "$arg" in --) no_more_options=true @@ -467,6 +481,11 @@ for arg in "$@" ; do --*) "$no_more_options" && { gui=false error "Option arguments may not preceed non-option arguments." ; exit 1 ; } ;;& + --cookie) + [[ $# -eq 0 ]] && { gui=false error "Missing argument for option \"--cookie\"" ; exit 1 ; } + cookie=$1 + shift + ;; --debug) debug_cmdline=true ;; From 4c7b600c689fbbd1d9aab76e3423494a5b36c7dd Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 1 Jun 2025 03:48:32 +0200 Subject: [PATCH 07/10] remove debug output; option --cookie expects Base64 value --- pulseaudio-tcp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index 3566d5d..ffd432a 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -22,18 +22,19 @@ usage() { cat >&2 < ~/.config/pulse/cookie + if echo "$cookie" | base64 -d > ~/.config/pulse/cookie ; then + debug "Using PulseAudio cookie value as passed on the command line ..." + return 0 + else + error "Decoding Base64 value of option --cookie failed." + return 1 + fi elif _scp "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then debug "Synced PulseAudio cookie from remote host $remote_ip." return 0 @@ -472,7 +478,6 @@ no_more_options=false while [[ $# -gt 0 ]] ; do arg=$1 shift - echo "DEBUG: parsing arg=$arg .." >&2 case "$arg" in --) From f78ae9d1837db968e19a0ce2722cc0b61dfe6aea Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 1 Jun 2025 05:46:52 +0200 Subject: [PATCH 08/10] exclude vim swapfiles --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d57cb1d..38db181 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ debian/debhelper-build-stamp debian/files debian/pulseaudio-tcp.substvars debian/pulseaudio-tcp +*.sw* From f08b857aff537870e7e4eccfa81f6f15891ff9e5 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 1 Jun 2025 15:37:56 +0200 Subject: [PATCH 09/10] support for multiple commands (WIP) --- pulseaudio-tcp | 101 +++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index ffd432a..de5cce3 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -22,19 +22,24 @@ usage() { cat >&2 <\" not set in configfile $config." - rv=1 - elif [[ -z $remote_user ]] ; then - error "\"remote_user=\" not set in configfile $config." - rv=1 + if [[ -z $remote_ip ]] ; then + error "\"remote_ip=\" not set in configfile $config." + rv=1 + elif [[ -z $remote_user ]] ; then + error "\"remote_user=\" not set in configfile $config." + rv=1 + fi fi + + required_cmds=( jq pactl ssh ) + + for exe in "${required_cmds[@]}" ; do + if [[ -z $(type -p "$exe") ]] ; then + error "Required executable \"$exe\" not found." + rv=1 + fi + done fi - required_cmds=( jq pactl ssh ) + if [[ $rv -ne 0 ]] ; then + error "Preliminary checks failed, skipping operation." + break + fi - for exe in "${required_cmds[@]}" ; do - if [[ -z $(type -p "$exe") ]] ; then - error "Required executable \"$exe\" not found." - rv=1 - fi - done -fi - -if [[ $rv -ne 0 ]] ; then - error "Preliminary checks failed, skipping operation." -else case "$operation" in setup) do_setup @@ -612,6 +627,8 @@ else rv=1 ;; esac -fi + + [[ $rv -ne 0 ]] && break +done exit "$rv" From 03e3953eb8a2a33f8422476439fbb058084fb146 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 1 Jun 2025 15:43:26 +0200 Subject: [PATCH 10/10] completion supports multiple commands --- pulseaudio-tcp.bash_completion | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pulseaudio-tcp.bash_completion b/pulseaudio-tcp.bash_completion index 4ee07f3..962aea1 100644 --- a/pulseaudio-tcp.bash_completion +++ b/pulseaudio-tcp.bash_completion @@ -1,7 +1,6 @@ _pulseaudio_tcp_completions() { local \ command_list \ - command_pattern \ commands \ cur \ option_list \ @@ -21,20 +20,8 @@ _pulseaudio_tcp_completions() { commands=("${commands[@]/$word}") done - if "$more_options" ; then - option_list="${options[*]}" - else - option_list="" - fi - - printf -v command_pattern "%s|" "${commands[@]}" - command_pattern="(${command_pattern%?})" - - if [[ ${COMP_WORDS[*]} =~ $command_pattern ]] ; then - command_list="" - else - command_list="${commands[*]}" - fi + "$more_options" && option_list="${options[*]}" + command_list="${commands[*]}" mapfile -t COMPREPLY < <( compgen -W "$option_list $command_list" -- "$cur")