better ssh status and commandline error checking

This commit is contained in:
Tilman Kranz 2025-05-23 22:06:38 +02:00
parent 4fb3a469d0
commit a8d4304076

View file

@ -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