|
@ -1,77 +1,134 @@ |
|
|
#!/bin/sh /etc/rc.common |
|
|
#!/bin/sh /etc/rc.common |
|
|
|
|
|
# Copyright (C) 2015 OpenWrt.org |
|
|
|
|
|
|
|
|
NAME='shairport-sync' |
|
|
|
|
|
START=99 |
|
|
START=99 |
|
|
|
|
|
|
|
|
USE_PROCD=1 |
|
|
USE_PROCD=1 |
|
|
|
|
|
|
|
|
append_arg() { |
|
|
|
|
|
|
|
|
append_num() { |
|
|
local cfg="$1" |
|
|
local cfg="$1" |
|
|
local var="$2" |
|
|
|
|
|
local opt="$3" |
|
|
|
|
|
local def="$4" |
|
|
|
|
|
|
|
|
local file="$2" |
|
|
|
|
|
local var="$3" |
|
|
|
|
|
local opt="$4" |
|
|
|
|
|
local def="$5" |
|
|
local val |
|
|
local val |
|
|
|
|
|
|
|
|
config_get val "$cfg" "$var" |
|
|
config_get val "$cfg" "$var" |
|
|
[ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" |
|
|
|
|
|
|
|
|
[ -n "$val" -o -n "$def" ] && echo -e "\t$opt = ${val:-$def};" >> $file |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
append_bool() { |
|
|
|
|
|
|
|
|
append_str() { |
|
|
local cfg="$1" |
|
|
local cfg="$1" |
|
|
local var="$2" |
|
|
|
|
|
local opt="$3" |
|
|
|
|
|
local def="$4" |
|
|
|
|
|
|
|
|
local file="$2" |
|
|
|
|
|
local var="$3" |
|
|
|
|
|
local opt="$4" |
|
|
|
|
|
local def="$5" |
|
|
local val |
|
|
local val |
|
|
|
|
|
|
|
|
config_get_bool val "$cfg" "$var" "$def" |
|
|
|
|
|
[ "$val" = 1 ] && procd_append_param command "$opt" |
|
|
|
|
|
|
|
|
config_get val "$cfg" "$var" |
|
|
|
|
|
[ -n "$val" -o -n "$def" ] && echo -e "\t$opt = \"${val:-$def}\";" >> $file |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
start_shairport_service() { |
|
|
|
|
|
|
|
|
start_instance() { |
|
|
local cfg=$1 |
|
|
local cfg=$1 |
|
|
local stuffing |
|
|
|
|
|
local device |
|
|
|
|
|
|
|
|
local conf_custom conf_file aux |
|
|
|
|
|
|
|
|
|
|
|
config_get_bool aux "$cfg" 'disabled' '0' |
|
|
|
|
|
[ "$aux" = 1 ] && return 1 |
|
|
|
|
|
|
|
|
|
|
|
config_get_bool conf_custom "$cfg" 'conf_custom' '0' |
|
|
|
|
|
config_get conf_file "$cfg" "conf_file" |
|
|
|
|
|
if [ $conf_custom -ne 1 ] && [ ! -n "$conf_file" ]; then |
|
|
|
|
|
mkdir -p /var/etc |
|
|
|
|
|
conf_file="/var/etc/shairport-sync-${cfg}.conf" |
|
|
|
|
|
|
|
|
|
|
|
echo -e "// Automatically generated from UCI config\n" > $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# General |
|
|
|
|
|
echo -e "general =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_str "$cfg" "$conf_file" name "name" |
|
|
|
|
|
append_str "$cfg" "$conf_file" password "password" |
|
|
|
|
|
append_str "$cfg" "$conf_file" interpolation "interpolation" |
|
|
|
|
|
append_str "$cfg" "$conf_file" output_backend "output_backend" |
|
|
|
|
|
append_str "$cfg" "$conf_file" mdns_backend "mdns_backend" |
|
|
|
|
|
append_num "$cfg" "$conf_file" port "port" |
|
|
|
|
|
append_num "$cfg" "$conf_file" udp_port_base "udp_port_base" |
|
|
|
|
|
append_num "$cfg" "$conf_file" udp_port_range "udp_port_range" |
|
|
|
|
|
append_str "$cfg" "$conf_file" statistics "statistics" |
|
|
|
|
|
append_num "$cfg" "$conf_file" drift "drift" |
|
|
|
|
|
append_num "$cfg" "$conf_file" resync_threshold "resync_threshold" |
|
|
|
|
|
append_num "$cfg" "$conf_file" log_verbosity "log_verbosity" |
|
|
|
|
|
append_str "$cfg" "$conf_file" ignore_volume_control "ignore_volume_control" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# Latencies |
|
|
|
|
|
echo -e "latencies =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_num "$cfg" "$conf_file" latencies_default "default" |
|
|
|
|
|
append_num "$cfg" "$conf_file" latencies_itunes "itunes" |
|
|
|
|
|
append_num "$cfg" "$conf_file" latencies_airplay "airplay" |
|
|
|
|
|
append_num "$cfg" "$conf_file" latencies_forked_daapd "forkedDaapd" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# Metadata |
|
|
|
|
|
echo -e "metadata =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_str "$cfg" "$conf_file" metadata_enabled "enabled" |
|
|
|
|
|
append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art" |
|
|
|
|
|
append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# Session control |
|
|
|
|
|
echo -e "sessioncontrol =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins" |
|
|
|
|
|
append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends" |
|
|
|
|
|
append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion" |
|
|
|
|
|
append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption" |
|
|
|
|
|
append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# Alsa audio back end |
|
|
|
|
|
echo -e "alsa =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_str "$cfg" "$conf_file" alsa_output_device "output_device" |
|
|
|
|
|
append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name" |
|
|
|
|
|
append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device" |
|
|
|
|
|
append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset" |
|
|
|
|
|
append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# Pipe audio back end |
|
|
|
|
|
echo -e "pipe =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_str "$cfg" "$conf_file" pipe_name "name" |
|
|
|
|
|
append_num "$cfg" "$conf_file" pipe_latency_offset "audio_backend_latency_offset" |
|
|
|
|
|
append_num "$cfg" "$conf_file" pipe_buffer_length "audio_backend_buffer_desired_length" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
|
|
|
|
|
|
# Stdout audio back end |
|
|
|
|
|
echo -e "stdout =" >> $conf_file |
|
|
|
|
|
echo -e "{" >> $conf_file |
|
|
|
|
|
append_num "$cfg" "$conf_file" stdout_latency_offset "audio_backend_latency_offset" |
|
|
|
|
|
append_num "$cfg" "$conf_file" stdout_buffer_length "audio_backend_buffer_desired_length" |
|
|
|
|
|
echo -e "};\n" >> $conf_file |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
procd_open_instance |
|
|
procd_open_instance |
|
|
|
|
|
|
|
|
procd_set_param command /usr/bin/$NAME |
|
|
|
|
|
|
|
|
|
|
|
append_arg "$cfg" name "-a" |
|
|
|
|
|
append_arg "$cfg" port "-p" |
|
|
|
|
|
append_arg "$cfg" airplaylatency "-A" |
|
|
|
|
|
append_arg "$cfg" ituneslatency "-i" |
|
|
|
|
|
|
|
|
|
|
|
config_get stuffing "$cfg" stuffing "" |
|
|
|
|
|
|
|
|
|
|
|
if [ -n "$stuffing" ] ; then |
|
|
|
|
|
case "x$stuffing" in |
|
|
|
|
|
( "xbasic" ) procd_append_param command -S basic ;; |
|
|
|
|
|
( "xsoxr" ) procd_append_param command -S soxr ;; |
|
|
|
|
|
( * ) logger "bad argument for -S option -- should be \"basic\" or \"soxr\"" ;; |
|
|
|
|
|
esac |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
append_arg "$cfg" beforeaction "-B" |
|
|
|
|
|
append_arg "$cfg" afteraction "-E" |
|
|
|
|
|
append_bool "$cfg" awaitactioncompletion "-w" |
|
|
|
|
|
|
|
|
|
|
|
config_get device "$cfg" device "" |
|
|
|
|
|
if [ -n "$device" ] ; then |
|
|
|
|
|
procd_append_param command "--" |
|
|
|
|
|
append_arg "$cfg" device "-d" |
|
|
|
|
|
append_arg "$cfg" devicetype "-t" |
|
|
|
|
|
append_arg "$cfg" volumecontrolname "-c" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
procd_set_param command /usr/bin/shairport-sync |
|
|
|
|
|
procd_append_param command -c $conf_file |
|
|
|
|
|
|
|
|
|
|
|
config_get_bool aux "$cfg" 'respawn' '0' |
|
|
|
|
|
[ "$aux" = 1 ] && procd_set_param respawn |
|
|
|
|
|
|
|
|
procd_close_instance |
|
|
procd_close_instance |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
service_triggers() { |
|
|
|
|
|
procd_add_reload_trigger $NAME |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
service_triggers() { |
|
|
|
|
|
procd_add_reload_trigger "shairport-sync" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
start_service() { |
|
|
start_service() { |
|
|
config_load $NAME |
|
|
|
|
|
# Just a single instance |
|
|
|
|
|
start_shairport_service "main" |
|
|
|
|
|
|
|
|
config_load shairport-sync |
|
|
|
|
|
config_foreach start_instance shairport-sync |
|
|
} |
|
|
} |