From 6c9e822ccf945f3f28aee0404cefebffeef007d2 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 25 May 2025 06:47:35 +0200 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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")