From a8d430407686fd2da11d79db0ceccbb02335d131 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Fri, 23 May 2025 22:06:38 +0200 Subject: [PATCH] better ssh status and commandline error checking --- pulseaudio-tcp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pulseaudio-tcp b/pulseaudio-tcp index 1f52279..3fbdb7c 100644 --- a/pulseaudio-tcp +++ b/pulseaudio-tcp @@ -71,7 +71,7 @@ debug() { } _ssh() { - if ssh -S "$USER"-pulseaudio "$remote_user"@"$remote_ip" "$@" ; then + if ssh -o PasswordAuthentication=no -S "$USER"-pulseaudio "$remote_user"@"$remote_ip" "$@" ; then return 0 else error "SSH remote_ip=$remote_ip failed." @@ -79,6 +79,15 @@ _ssh() { fi } +_scp() { + if scp -o PasswordAuthentication=no -q "$1" "$2" ; then + return 0 + else + error "SCP $1 $2 failed" + return 1 + fi +} + question_yesno() { question=$* @@ -204,7 +213,7 @@ EOF # Check if SSH port forwarding is running check_pa_ssh() { for pid in $(pidof ssh) ; do - if grep -Fq "$USER"-pulseaudio /proc/"$pid"/cmdline && grep -Fq -e -L /proc/"$pid"/cmdline ; then + if grep -Fbq "$USER"-pulseaudio /proc/"$pid"/cmdline && grep -Fbq -e -L /proc/"$pid"/cmdline ; then return 0 fi done @@ -256,7 +265,7 @@ do_status() { # Acquire PulseAudio cookie from remote host sync_pa_cookie() { - if scp -q "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then + if _scp "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then debug "Synced PulseAudio cookie from remote host $remote_ip." return 0 else @@ -267,7 +276,11 @@ sync_pa_cookie() { # Establish SSH port forwarding to PulseAudio TCP server on remote host establish_ssh_portforward() { - _ssh -fNT -L 127.0.0.1:4713:127.0.0.1:4713 + if check_pa_ssh ; then + debug "Not establishing SSH forwarding (already running)" + else + _ssh -fNT -L 127.0.0.1:4713:127.0.0.1:4713 + fi } # Enable PulseAudio TCP tunnel server on remote host @@ -433,6 +446,8 @@ do_stop() { ## # Arguments +operation= + for arg in "$@" ; do case "$arg" in --debug) @@ -444,9 +459,14 @@ for arg in "$@" ; do --help) help_cmdline=true ;; - *) + start|stop|restart|setup|status) + [[ -z $operation ]] || { error "Multiple operations are not supported." ; exit 1 ; } operation=$arg ;; + *) + error "Unsupported argument (try \"--help\")" + exit 1 + ;; esac done