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() {
cat >&2 <<EOF
# Usage:
\`$0 [OPTIONS] OPERATION\`
# Options:
# pulseaudio-tcp - Connect to remote PulseAudio/Pipewire Server
## Usage:
\`$0 [OPTION ...] OPERATION ...\`
## Options:
* \`--debug\`: Enable additional debug output for start and stop operations.
* \`--no-gui\`: Do not display GUI dialogs, use terminal for input and output.
* \`--cookie COOKIE\`: Pass Pulseaudio cookie as option value instead of copying
from remote_host. Expects value to be Base64-encoded.
# Operations:
## Operations:
* \`setup\`: Interactively gather settings.
* \`start\`: Start redirection to remote host.
* \`stop\`: Stop redirection to remote host.
* \`restart\`: Stop and then start redirection.
* \`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
}
@ -76,7 +81,7 @@ debug() {
}
_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
else
error "SSH remote_ip=$remote_ip failed."
@ -470,7 +475,7 @@ do_stop() {
##
# Arguments
operation=
operations=()
cookie=
no_more_options=false
# shellcheck disable=SC2034
@ -501,8 +506,7 @@ while [[ $# -gt 0 ]] ; do
help_cmdline=true
;;
start|stop|restart|setup|status)
[[ -z $operation ]] || { gui=false error "Multiple operations are not supported." ; exit 1 ; }
operation=$arg
operations+=("$arg")
;;
*)
gui=false error "Unsupported argument (try \"--help\")"
@ -514,6 +518,16 @@ done
##
# 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=$config_dir/config.inc.sh
@ -546,45 +560,46 @@ fi
##
# Main Program
rv=0
for operation in "${operations[@]}" ; do
rv=0
if test "$operation" = setup ; then
info "Entering setup mode ..."
else
if ! test -e "$config" ; then
error "Configfile $config does not exist (use \"$0 setup\" first)."
rv=1
elif ! test -r "$config" ; then
error "Configfile $config is not readable."
rv=1
elif ! test -f "$config" ; then
error "Configfile $config is not a regular file."
rv=1
else
. "$config"
if [[ "$operation" != setup ]] ; then
if ! test -e "$config" ; then
error "Configfile $config does not exist (use \"$0 setup\" first)."
rv=1
elif ! test -r "$config" ; then
error "Configfile $config is not readable."
rv=1
elif ! test -f "$config" ; then
error "Configfile $config is not a regular file."
rv=1
else
. "$config"
if [[ -z $remote_ip ]] ; then
error "\"remote_ip=<IP address>\" not set in configfile $config."
rv=1
elif [[ -z $remote_user ]] ; then
error "\"remote_user=<username>\" not set in configfile $config."
rv=1
if [[ -z $remote_ip ]] ; then
error "\"remote_ip=<IP address>\" not set in configfile $config."
rv=1
elif [[ -z $remote_user ]] ; then
error "\"remote_user=<username>\" 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"