|
@@ -1,77 +1,134 @@
|
1
|
1
|
#!/bin/sh /etc/rc.common
|
|
2
|
+# Copyright (C) 2015 OpenWrt.org
|
2
|
3
|
|
3
|
|
-NAME='shairport-sync'
|
4
|
4
|
START=99
|
5
|
|
-
|
6
|
5
|
USE_PROCD=1
|
7
|
6
|
|
8
|
|
-append_arg() {
|
|
7
|
+append_num() {
|
9
|
8
|
local cfg="$1"
|
10
|
|
- local var="$2"
|
11
|
|
- local opt="$3"
|
12
|
|
- local def="$4"
|
|
9
|
+ local file="$2"
|
|
10
|
+ local var="$3"
|
|
11
|
+ local opt="$4"
|
|
12
|
+ local def="$5"
|
13
|
13
|
local val
|
14
|
14
|
|
15
|
15
|
config_get val "$cfg" "$var"
|
16
|
|
- [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
|
|
16
|
+ [ -n "$val" -o -n "$def" ] && echo -e "\t$opt = ${val:-$def};" >> $file
|
17
|
17
|
}
|
18
|
|
-
|
19
|
|
-append_bool() {
|
|
18
|
+append_str() {
|
20
|
19
|
local cfg="$1"
|
21
|
|
- local var="$2"
|
22
|
|
- local opt="$3"
|
23
|
|
- local def="$4"
|
|
20
|
+ local file="$2"
|
|
21
|
+ local var="$3"
|
|
22
|
+ local opt="$4"
|
|
23
|
+ local def="$5"
|
24
|
24
|
local val
|
25
|
25
|
|
26
|
|
- config_get_bool val "$cfg" "$var" "$def"
|
27
|
|
- [ "$val" = 1 ] && procd_append_param command "$opt"
|
|
26
|
+ config_get val "$cfg" "$var"
|
|
27
|
+ [ -n "$val" -o -n "$def" ] && echo -e "\t$opt = \"${val:-$def}\";" >> $file
|
28
|
28
|
}
|
29
|
29
|
|
30
|
|
-start_shairport_service() {
|
|
30
|
+start_instance() {
|
31
|
31
|
local cfg=$1
|
32
|
|
- local stuffing
|
33
|
|
- local device
|
|
32
|
+ local conf_custom conf_file aux
|
|
33
|
+
|
|
34
|
+ config_get_bool aux "$cfg" 'disabled' '0'
|
|
35
|
+ [ "$aux" = 1 ] && return 1
|
|
36
|
+
|
|
37
|
+ config_get_bool conf_custom "$cfg" 'conf_custom' '0'
|
|
38
|
+ config_get conf_file "$cfg" "conf_file"
|
|
39
|
+ if [ $conf_custom -ne 1 ] && [ ! -n "$conf_file" ]; then
|
|
40
|
+ mkdir -p /var/etc
|
|
41
|
+ conf_file="/var/etc/shairport-sync-${cfg}.conf"
|
|
42
|
+
|
|
43
|
+ echo -e "// Automatically generated from UCI config\n" > $conf_file
|
|
44
|
+
|
|
45
|
+ # General
|
|
46
|
+ echo -e "general =" >> $conf_file
|
|
47
|
+ echo -e "{" >> $conf_file
|
|
48
|
+ append_str "$cfg" "$conf_file" name "name"
|
|
49
|
+ append_str "$cfg" "$conf_file" password "password"
|
|
50
|
+ append_str "$cfg" "$conf_file" interpolation "interpolation"
|
|
51
|
+ append_str "$cfg" "$conf_file" output_backend "output_backend"
|
|
52
|
+ append_str "$cfg" "$conf_file" mdns_backend "mdns_backend"
|
|
53
|
+ append_num "$cfg" "$conf_file" port "port"
|
|
54
|
+ append_num "$cfg" "$conf_file" udp_port_base "udp_port_base"
|
|
55
|
+ append_num "$cfg" "$conf_file" udp_port_range "udp_port_range"
|
|
56
|
+ append_str "$cfg" "$conf_file" statistics "statistics"
|
|
57
|
+ append_num "$cfg" "$conf_file" drift "drift"
|
|
58
|
+ append_num "$cfg" "$conf_file" resync_threshold "resync_threshold"
|
|
59
|
+ append_num "$cfg" "$conf_file" log_verbosity "log_verbosity"
|
|
60
|
+ append_str "$cfg" "$conf_file" ignore_volume_control "ignore_volume_control"
|
|
61
|
+ echo -e "};\n" >> $conf_file
|
|
62
|
+
|
|
63
|
+ # Latencies
|
|
64
|
+ echo -e "latencies =" >> $conf_file
|
|
65
|
+ echo -e "{" >> $conf_file
|
|
66
|
+ append_num "$cfg" "$conf_file" latencies_default "default"
|
|
67
|
+ append_num "$cfg" "$conf_file" latencies_itunes "itunes"
|
|
68
|
+ append_num "$cfg" "$conf_file" latencies_airplay "airplay"
|
|
69
|
+ append_num "$cfg" "$conf_file" latencies_forked_daapd "forkedDaapd"
|
|
70
|
+ echo -e "};\n" >> $conf_file
|
|
71
|
+
|
|
72
|
+ # Metadata
|
|
73
|
+ echo -e "metadata =" >> $conf_file
|
|
74
|
+ echo -e "{" >> $conf_file
|
|
75
|
+ append_str "$cfg" "$conf_file" metadata_enabled "enabled"
|
|
76
|
+ append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art"
|
|
77
|
+ append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name"
|
|
78
|
+ echo -e "};\n" >> $conf_file
|
|
79
|
+
|
|
80
|
+ # Session control
|
|
81
|
+ echo -e "sessioncontrol =" >> $conf_file
|
|
82
|
+ echo -e "{" >> $conf_file
|
|
83
|
+ append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins"
|
|
84
|
+ append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends"
|
|
85
|
+ append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion"
|
|
86
|
+ append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption"
|
|
87
|
+ append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout"
|
|
88
|
+ echo -e "};\n" >> $conf_file
|
|
89
|
+
|
|
90
|
+ # Alsa audio back end
|
|
91
|
+ echo -e "alsa =" >> $conf_file
|
|
92
|
+ echo -e "{" >> $conf_file
|
|
93
|
+ append_str "$cfg" "$conf_file" alsa_output_device "output_device"
|
|
94
|
+ append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name"
|
|
95
|
+ append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device"
|
|
96
|
+ append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset"
|
|
97
|
+ append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length"
|
|
98
|
+ echo -e "};\n" >> $conf_file
|
|
99
|
+
|
|
100
|
+ # Pipe audio back end
|
|
101
|
+ echo -e "pipe =" >> $conf_file
|
|
102
|
+ echo -e "{" >> $conf_file
|
|
103
|
+ append_str "$cfg" "$conf_file" pipe_name "name"
|
|
104
|
+ append_num "$cfg" "$conf_file" pipe_latency_offset "audio_backend_latency_offset"
|
|
105
|
+ append_num "$cfg" "$conf_file" pipe_buffer_length "audio_backend_buffer_desired_length"
|
|
106
|
+ echo -e "};\n" >> $conf_file
|
|
107
|
+
|
|
108
|
+ # Stdout audio back end
|
|
109
|
+ echo -e "stdout =" >> $conf_file
|
|
110
|
+ echo -e "{" >> $conf_file
|
|
111
|
+ append_num "$cfg" "$conf_file" stdout_latency_offset "audio_backend_latency_offset"
|
|
112
|
+ append_num "$cfg" "$conf_file" stdout_buffer_length "audio_backend_buffer_desired_length"
|
|
113
|
+ echo -e "};\n" >> $conf_file
|
|
114
|
+ fi
|
34
|
115
|
|
35
|
116
|
procd_open_instance
|
36
|
117
|
|
37
|
|
- procd_set_param command /usr/bin/$NAME
|
38
|
|
-
|
39
|
|
- append_arg "$cfg" name "-a"
|
40
|
|
- append_arg "$cfg" port "-p"
|
41
|
|
- append_arg "$cfg" airplaylatency "-A"
|
42
|
|
- append_arg "$cfg" ituneslatency "-i"
|
43
|
|
-
|
44
|
|
- config_get stuffing "$cfg" stuffing ""
|
45
|
|
-
|
46
|
|
- if [ -n "$stuffing" ] ; then
|
47
|
|
- case "x$stuffing" in
|
48
|
|
- ( "xbasic" ) procd_append_param command -S basic ;;
|
49
|
|
- ( "xsoxr" ) procd_append_param command -S soxr ;;
|
50
|
|
- ( * ) logger "bad argument for -S option -- should be \"basic\" or \"soxr\"" ;;
|
51
|
|
- esac
|
52
|
|
- fi
|
53
|
|
-
|
54
|
|
- append_arg "$cfg" beforeaction "-B"
|
55
|
|
- append_arg "$cfg" afteraction "-E"
|
56
|
|
- append_bool "$cfg" awaitactioncompletion "-w"
|
57
|
|
-
|
58
|
|
- config_get device "$cfg" device ""
|
59
|
|
- if [ -n "$device" ] ; then
|
60
|
|
- procd_append_param command "--"
|
61
|
|
- append_arg "$cfg" device "-d"
|
62
|
|
- append_arg "$cfg" devicetype "-t"
|
63
|
|
- append_arg "$cfg" volumecontrolname "-c"
|
64
|
|
- fi
|
|
118
|
+ procd_set_param command /usr/bin/shairport-sync
|
|
119
|
+ procd_append_param command -c $conf_file
|
|
120
|
+
|
|
121
|
+ config_get_bool aux "$cfg" 'respawn' '0'
|
|
122
|
+ [ "$aux" = 1 ] && procd_set_param respawn
|
65
|
123
|
|
66
|
124
|
procd_close_instance
|
67
|
125
|
}
|
68
|
126
|
|
69
|
|
-service_triggers() {
|
70
|
|
- procd_add_reload_trigger $NAME
|
71
|
|
-}
|
|
127
|
+service_triggers() {
|
|
128
|
+ procd_add_reload_trigger "shairport-sync"
|
|
129
|
+}
|
72
|
130
|
|
73
|
131
|
start_service() {
|
74
|
|
- config_load $NAME
|
75
|
|
- # Just a single instance
|
76
|
|
- start_shairport_service "main"
|
|
132
|
+ config_load shairport-sync
|
|
133
|
+ config_foreach start_instance shairport-sync
|
77
|
134
|
}
|