Commit 2b186f2d authored by Ronald van Engelen's avatar Ronald van Engelen

fixed local usage

parent a1948630
......@@ -131,20 +131,16 @@ function bytes_to_si() {
function run_func() {
## run an internal function whose name is specified in $1 with
## args on the local host or remote through ssh.
## use declare -f to first print the function in the remote
## bash session, and then execute it.
func="$1"
shift
# shellcheck disable=SC2124
args="$@"
debug "$(declare -p func args)"
if [[ "${alsa_ssh_userhost}x" == "x" ]]; then
"${func} ${args}"
else
## use declare -f to first print the function in the remote
## bash session, and then execute it.
# shellcheck disable=SC2086
ssh "${alsa_ssh_userhost}" -- \
"$(declare -f ${func}); ${func} ${args}"
fi
# shellcheck disable=SC2086
ssh "${alsa_ssh_userhost}" -- \
"$(declare -f ${func}; declare -f debug); ${func} ${args}"
}
......@@ -241,10 +237,9 @@ function analyze_command_line() {
if [[ "${arg_mpd_music_dir}x" == "x" ]]; then
# shellcheck disable=SC2124
arg_single="$@"
#declare -p arg_single 1>&2
debug "$(declare -p arg_single)"
arg_mpd_music_dir="${arg_single}"
if [[ "${arg_mpd_music_dir}x" != "x" ]]; then
if [[ ! -d "${arg_mpd_music_dir}" ]]; then
display_usage_error "invalid mpd music directory \`${arg_mpd_music_dir}' specified."
else
......@@ -258,10 +253,9 @@ function analyze_command_line() {
else
display_usage_error "no mpd music directory specified."
fi
[[ ${DEBUG} ]] && \
declare -p arg_mpd_music_dir \
debug "$(declare -p arg_mpd_music_dir \
arg_mpd_host arg_mpd_port arg_mpd_password \
arg_ssh_user 1>&2
arg_ssh_user)"
fi
}
......@@ -286,27 +280,25 @@ function ret_mpdconf_commandline() {
## return the command line arguments for running mpd
alsa_ssh_userhost="${alsa_ssh_userhost:-}"
mpd_pid="$(pidof mpd | awk '{print $1}')"
debug "$(declare -p alsa_ssh_userhost mpd_pid)"
xargs -0 echo < "/proc/${mpd_pid}/cmdline"
}
function ret_mpdconf_default() {
## function
for conffile in $XDG_CONFIG_HOME/mpd/mpd.conf \
~/.mpdconf \
~/.mpd/mpd.conf \
/etc/mpd.conf; do
if [[ "${conffile}x" != "x" ]]; then
if [[ -f ${conffile} ]]; then
[[ ${DEBUG} ]] && \
printf 1>&2 "using mpd configuration file %s\n" \
"${conffile}"
echo "${conffile}"
return 0
fi
## function
mpd_conffiles=("${XDG_CONFIG_HOME}/mpd/mpd.conf"
"${HOME}/.mpdconf"
"${HOME}/.mpd/mpd.conf"
"/etc/mpd.conf")
for conffile in "${mpd_conffiles[@]}"; do
if [[ -f "${conffile}" ]]; then
debug "using mpd configuration file \`${conffile}'."
echo "${conffile}"
return 0
fi
done
printf 1>&2 "warning: no mpd configuration found.\n"
display_error "warning: no mpd configuration found."
return 1
}
......@@ -317,7 +309,7 @@ function ret_mpdconf_path() {
## the command mpd itself (including a possible path) gets
## stripped before
## all possible mpd command line arguments
mpd_args=(--no-config)
local mpd_args=(--no-config)
mpd_args+=(--no-daemon)
mpd_args+=(-v)
mpd_args+=(--verbose)
......@@ -325,24 +317,42 @@ function ret_mpdconf_path() {
## strip each command line argument from all possible arguments
## the remainder is the mpd conf file
# shellcheck disable=SC2207
mpd_real_args=($(run_func ret_mpdconf_commandline))
mpd_real_args=(
$(
if [[ "${alsa_ssh_userhost}x" == "x" ]]; then
ret_mpdconf_commandline
else
run_func ret_mpdconf_commandline
fi
)
)
mpd_rest_args=("${mpd_real_args[@]:1}")
for arg in "${mpd_args[@]}"; do
mpd_rest_args=("${mpd_rest_args[@]//${arg}}")
done
debug "$(declare -p mpd_args mpd_real_args mpd_rest_args)"
mpd_conf_file="${mpd_rest_args[0]}"
if [[ "${mpd_conf_file}x" == "x" ]]; then
## ugly hack
if [[ "${mpd_conf_file}x" == "x" ]] || [[ "${mpd_conf_file}x" == "()x" ]]; then
debug "no conffile specified on mpd command line, test default locations."
run_func ret_mpdconf_default || return 1
if [[ "${alsa_ssh_userhost}x" == "x" ]]; then
ret_mpdconf_default || return 1
else
run_func ret_mpdconf_default || return 1
fi
else
debug "$(declare -p mpd_conf_file)"
printf "%s" "${mpd_conf_file}"
fi
}
function get_mpdconf_contents() {
mpdconf_path="$1"
run_func ret_mpdconf_contents "${mpdconf_path}" || return 1
if [[ "${alsa_ssh_userhost}x" == "x" ]]; then
ret_mpdconf_contents "${mpdconf_path}" || return 1
else
run_func ret_mpdconf_contents "${mpdconf_path}" || return 1
fi
}
......@@ -352,7 +362,11 @@ function get_mpd_alsa_outputs() {
## TODO; handle multiple outputs
# while read -r line; do
# done< <(ssh ${alsa_ssh_userhost} -- "cat /ec/mpd.conf")
mpdconf_path=$(ret_mpdconf_path)
mpdconf_path="$(ret_mpdconf_path)"
if [[ "${mpdconf_path}x" == "x" ]]; then
display_error "ret_mpdconf_path returned no path"
return 1
fi
debug "$(declare -p mpdconf_path)"
#mpdconf_contents="$(get_mpdconf_contents "${mpdconf_path}")"
#declare -p mpdconf_path mpdconf_contents 1>&2
......@@ -686,8 +700,7 @@ function get_hwparams() {
## returns newline separated file contents or an error.
alsa_card_no="$1"
alsa_dev_no="$2"
[[ ! -z ${DEBUG} ]] && \
declare -p alsa_card_no alsa_dev_no 1>&2
debug "$(declare -p alsa_card_no alsa_dev_no)"
hwparams_file="/proc/asound/card${alsa_card_no}/pcm${alsa_dev_no}p/sub0/hw_params"
if [[ -f "${hwparams_file}" ]]; then
## return the contents of the file
......@@ -721,7 +734,9 @@ function ret_alsa_info() {
debug "$(declare -p mpd_host mpd_port mpc_args)"
mpc_output_re="Output[[:space:]]([0-9]+)[[:space:]]\(([^\(]+)\)"
while read -r line; do
debug "$(declare -p line)"
if [[ "${line}" =~ ${mpc_output_re} ]]; then
debug "$(declare -p BASH_REMATCH)"
mpd_outputs+=("${BASH_REMATCH[2]}")
fi
done< <(${cmd_mpc} "${mpc_args[@]}")
......@@ -736,7 +751,13 @@ function ret_alsa_info() {
else
debug "no match: $(declare -p line)"
fi
done< <(run_func get_hwparams "${alsa_card_no} ${alsa_dev_no}")
done< <(
if [[ "${alsa_ssh_userhost}x" == "x" ]]; then
get_hwparams "${alsa_card_no}" "${alsa_dev_no}"
else
run_func get_hwparams "${alsa_card_no} ${alsa_dev_no}"
fi
)
if (( ${#alsa_vals[@]} < 1 )); then
display_error "empty alsa_vals array."
return 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment