support for multiple commands (WIP)

This commit is contained in:
Tilman Kranz 2025-06-01 15:37:56 +02:00
parent f78ae9d183
commit f08b857aff

View file

@ -22,19 +22,24 @@
usage() { usage() {
cat >&2 <<EOF cat >&2 <<EOF
# Usage: # pulseaudio-tcp - Connect to remote PulseAudio/Pipewire Server
\`$0 [OPTIONS] OPERATION\` ## Usage:
# Options: \`$0 [OPTION ...] OPERATION ...\`
## Options:
* \`--debug\`: Enable additional debug output for start and stop operations. * \`--debug\`: Enable additional debug output for start and stop operations.
* \`--no-gui\`: Do not display GUI dialogs, use terminal for input and output. * \`--no-gui\`: Do not display GUI dialogs, use terminal for input and output.
* \`--cookie COOKIE\`: Pass Pulseaudio cookie as option value instead of copying * \`--cookie COOKIE\`: Pass Pulseaudio cookie as option value instead of copying
from remote_host. Expects value to be Base64-encoded. from remote_host. Expects value to be Base64-encoded.
# Operations: ## Operations:
* \`setup\`: Interactively gather settings. * \`setup\`: Interactively gather settings.
* \`start\`: Start redirection to remote host. * \`start\`: Start redirection to remote host.
* \`stop\`: Stop redirection to remote host. * \`stop\`: Stop redirection to remote host.
* \`restart\`: Stop and then start redirection. * \`restart\`: Stop and then start redirection.
* \`status\`: Check if redirection is set up and enabled. * \`status\`: Check if redirection is set up and enabled.
## Environment Variables:
* \`PULSEAUDIO_TCP_SSH_ADDARGS\`:
If set, specifies additional commandline arguments for calls to \`ssh\`.
Example: \`PULSEAUDIO_TCP_SSH_ADDARGS=-v pulseaudio-tcp --no-gui start\`
EOF EOF
} }
@ -76,7 +81,7 @@ debug() {
} }
_ssh() { _ssh() {
if ssh -o PasswordAuthentication=no -S "$USER"-pulseaudio "$remote_user"@"$remote_ip" "$@" ; then if ssh "${_ssh_arguments[@]}" -S "$USER"-pulseaudio "$remote_user"@"$remote_ip" "$@" ; then
return 0 return 0
else else
error "SSH remote_ip=$remote_ip failed." error "SSH remote_ip=$remote_ip failed."
@ -470,7 +475,7 @@ do_stop() {
## ##
# Arguments # Arguments
operation= operations=()
cookie= cookie=
no_more_options=false no_more_options=false
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -501,8 +506,7 @@ while [[ $# -gt 0 ]] ; do
help_cmdline=true help_cmdline=true
;; ;;
start|stop|restart|setup|status) start|stop|restart|setup|status)
[[ -z $operation ]] || { gui=false error "Multiple operations are not supported." ; exit 1 ; } operations+=("$arg")
operation=$arg
;; ;;
*) *)
gui=false error "Unsupported argument (try \"--help\")" gui=false error "Unsupported argument (try \"--help\")"
@ -514,6 +518,16 @@ done
## ##
# Configuration # Configuration
_ssh_arguments=(
-o
PasswordAuthentication=no
)
if [[ -n $PULSEAUDIO_TCP_SSH_ADDARGS ]] ; then
read -r -a _ssh_additional_arguments <<< "$PULSEAUDIO_TCP_SSH_ADDARGS"
_ssh_arguments+=("${_ssh_additional_arguments[@]}")
fi
config_dir="$HOME"/.config/pulseaudio-tcp config_dir="$HOME"/.config/pulseaudio-tcp
config=$config_dir/config.inc.sh config=$config_dir/config.inc.sh
@ -546,11 +560,10 @@ fi
## ##
# Main Program # Main Program
for operation in "${operations[@]}" ; do
rv=0 rv=0
if test "$operation" = setup ; then if [[ "$operation" != setup ]] ; then
info "Entering setup mode ..."
else
if ! test -e "$config" ; then if ! test -e "$config" ; then
error "Configfile $config does not exist (use \"$0 setup\" first)." error "Configfile $config does not exist (use \"$0 setup\" first)."
rv=1 rv=1
@ -584,7 +597,9 @@ fi
if [[ $rv -ne 0 ]] ; then if [[ $rv -ne 0 ]] ; then
error "Preliminary checks failed, skipping operation." error "Preliminary checks failed, skipping operation."
else break
fi
case "$operation" in case "$operation" in
setup) setup)
do_setup do_setup
@ -612,6 +627,8 @@ else
rv=1 rv=1
;; ;;
esac esac
fi
[[ $rv -ne 0 ]] && break
done
exit "$rv" exit "$rv"