improved main program structure; checks for dependencies
This commit is contained in:
parent
4e82cfe6d5
commit
dea6a2ec1b
126
pulseaudio-tcp
126
pulseaudio-tcp
@ -26,37 +26,6 @@ operation=$1
|
|||||||
config_dir="$HOME"/.config/pulseaudio-tcp
|
config_dir="$HOME"/.config/pulseaudio-tcp
|
||||||
config="$config_dir"/config.inc.sh
|
config="$config_dir"/config.inc.sh
|
||||||
|
|
||||||
if test "$operation" = setup ; then
|
|
||||||
echo "Entering setup mode ..."
|
|
||||||
else
|
|
||||||
test -e "$config" || {
|
|
||||||
echo "ERROR: Configfile $config does not exist (use \"$0 setup\" first)." >&2 ;
|
|
||||||
exit 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
test -r "$config" || {
|
|
||||||
echo "ERROR: Configfile $config is not readable." >&2 ;
|
|
||||||
exit 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
test -f "$config" || {
|
|
||||||
echo "ERROR: Configfile $config is not a regular file." >&2 ;
|
|
||||||
exit 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
. "$config"
|
|
||||||
|
|
||||||
test -n "$remote_ip" || {
|
|
||||||
echo "ERROR: \"remote_ip=<IP address>\" not set in configfile $config." >&2 ;
|
|
||||||
exit 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
test -n "$remote_user" || {
|
|
||||||
echo "ERROR: \"remote_user=<username>\" not set in configfile $config." >&2 ;
|
|
||||||
exit 1 ;
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
@ -179,7 +148,7 @@ do_status() {
|
|||||||
|
|
||||||
# Acquire PulseAudio cookie from remote host
|
# Acquire PulseAudio cookie from remote host
|
||||||
sync_pa_cookie() {
|
sync_pa_cookie() {
|
||||||
if scp -q "$remote_user"@"$remote_ip":.config/pulse/cookie .config/pulse/cookie ; then
|
if scp -q "$remote_user"@"$remote_ip":.config/pulse/cookie ~/.config/pulse/cookie ; then
|
||||||
echo "INFO: Synced PulseAudio cookie from remote_ip=$remote_ip." >&2
|
echo "INFO: Synced PulseAudio cookie from remote_ip=$remote_ip." >&2
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -302,30 +271,77 @@ do_stop() {
|
|||||||
##
|
##
|
||||||
# Main Program
|
# Main Program
|
||||||
|
|
||||||
case "$operation" in
|
rv=0
|
||||||
""|-h|--help)
|
|
||||||
cat << EOF
|
if test "$operation" = setup ; then
|
||||||
|
echo "Entering setup mode ..."
|
||||||
|
else
|
||||||
|
if ! test -e "$config" ; then
|
||||||
|
echo "ERROR: Configfile $config does not exist (use \"$0 setup\" first)." >&2
|
||||||
|
rv=1
|
||||||
|
elif ! test -r "$config" ; then
|
||||||
|
echo "ERROR: Configfile $config is not readable." >&2
|
||||||
|
rv=1
|
||||||
|
elif ! test -f "$config" ; then
|
||||||
|
echo "ERROR: Configfile $config is not a regular file." >&2
|
||||||
|
rv=1
|
||||||
|
else
|
||||||
|
. "$config"
|
||||||
|
|
||||||
|
if test -z "$remote_ip" ; then
|
||||||
|
echo "ERROR: \"remote_ip=<IP address>\" not set in configfile $config." >&2
|
||||||
|
rv=1
|
||||||
|
elif test -z "$remote_user" ; then
|
||||||
|
echo "ERROR: \"remote_user=<username>\" not set in configfile $config." >&2
|
||||||
|
rv=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$(which jq)" ; then
|
||||||
|
echo "ERROR: Required executable \"jq\" not found." >&2
|
||||||
|
rv=1
|
||||||
|
elif test -z "$(which pactl)" ; then
|
||||||
|
echo "ERROR: Required executable \"pactl\" not found." >&2
|
||||||
|
rv=1
|
||||||
|
elif test -z "$(which ssh)" ; then
|
||||||
|
echo "ERROR: Required executable \"ssh\" not found." >&2
|
||||||
|
rv=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$rv" -ne 0 ; then
|
||||||
|
echo "ERROR: Preliminary checks failed, skipping operation." >&2
|
||||||
|
else
|
||||||
|
case "$operation" in
|
||||||
|
""|-h|--help)
|
||||||
|
cat << EOF
|
||||||
Setup and run encrypted connection to remote PulseAudio/Pipewire server
|
Setup and run encrypted connection to remote PulseAudio/Pipewire server
|
||||||
Usage: $0 setup|start|stop|status
|
Usage: $0 setup|start|stop|status
|
||||||
EOF
|
EOF
|
||||||
exit 0
|
rv=0
|
||||||
;;
|
;;
|
||||||
setup)
|
setup)
|
||||||
do_setup || exit 1
|
do_setup
|
||||||
;;
|
rv=$?
|
||||||
start)
|
;;
|
||||||
do_start || exit 1
|
start)
|
||||||
;;
|
do_start
|
||||||
stop)
|
rv=$?
|
||||||
do_stop || exit 1
|
;;
|
||||||
;;
|
stop)
|
||||||
status)
|
do_stop
|
||||||
do_status
|
rv=$?
|
||||||
exit $?
|
;;
|
||||||
;;
|
status)
|
||||||
*)
|
do_status
|
||||||
echo "ERROR: Usage: $0 setup|start|stop|status" >&2
|
rv=$?
|
||||||
exit 1
|
;;
|
||||||
;;
|
*)
|
||||||
esac
|
echo "ERROR: Usage: $0 setup|start|stop|status" >&2
|
||||||
|
rv=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$rv"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user