support for multiple commands (WIP)
This commit is contained in:
parent
f78ae9d183
commit
f08b857aff
1 changed files with 59 additions and 42 deletions
101
pulseaudio-tcp
101
pulseaudio-tcp
|
@ -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,45 +560,46 @@ fi
|
||||||
##
|
##
|
||||||
# Main Program
|
# Main Program
|
||||||
|
|
||||||
rv=0
|
for operation in "${operations[@]}" ; do
|
||||||
|
rv=0
|
||||||
|
|
||||||
if test "$operation" = setup ; then
|
if [[ "$operation" != setup ]] ; then
|
||||||
info "Entering setup mode ..."
|
if ! test -e "$config" ; then
|
||||||
else
|
error "Configfile $config does not exist (use \"$0 setup\" first)."
|
||||||
if ! test -e "$config" ; then
|
rv=1
|
||||||
error "Configfile $config does not exist (use \"$0 setup\" first)."
|
elif ! test -r "$config" ; then
|
||||||
rv=1
|
error "Configfile $config is not readable."
|
||||||
elif ! test -r "$config" ; then
|
rv=1
|
||||||
error "Configfile $config is not readable."
|
elif ! test -f "$config" ; then
|
||||||
rv=1
|
error "Configfile $config is not a regular file."
|
||||||
elif ! test -f "$config" ; then
|
rv=1
|
||||||
error "Configfile $config is not a regular file."
|
else
|
||||||
rv=1
|
. "$config"
|
||||||
else
|
|
||||||
. "$config"
|
|
||||||
|
|
||||||
if [[ -z $remote_ip ]] ; then
|
if [[ -z $remote_ip ]] ; then
|
||||||
error "\"remote_ip=<IP address>\" not set in configfile $config."
|
error "\"remote_ip=<IP address>\" not set in configfile $config."
|
||||||
rv=1
|
rv=1
|
||||||
elif [[ -z $remote_user ]] ; then
|
elif [[ -z $remote_user ]] ; then
|
||||||
error "\"remote_user=<username>\" not set in configfile $config."
|
error "\"remote_user=<username>\" not set in configfile $config."
|
||||||
rv=1
|
rv=1
|
||||||
|
fi
|
||||||
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
|
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
|
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"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue