libmicrohttpd: build parallel
[feed/packages.git] / sound / shairport-sync / files / shairport-sync.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2015 OpenWrt.org
3
4 START=99
5 USE_PROCD=1
6
7 append_num() {
8 local cfg="$1"
9 local file="$2"
10 local var="$3"
11 local opt="$4"
12 local def="$5"
13 local val
14
15 config_get val "$cfg" "$var"
16 [ -n "$val" -o -n "$def" ] && echo -e "\t$opt = ${val:-$def};" >> $file
17 }
18 append_str() {
19 local cfg="$1"
20 local file="$2"
21 local var="$3"
22 local opt="$4"
23 local def="$5"
24 local val
25
26 config_get val "$cfg" "$var"
27 [ -n "$val" -o -n "$def" ] && echo -e "\t$opt = \"${val:-$def}\";" >> $file
28 }
29
30 start_instance() {
31 local cfg=$1
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 append_num "$cfg" "$conf_file" volume_range_db "volume_range_db"
62 echo -e "};\n" >> $conf_file
63
64 # Latencies
65 echo -e "latencies =" >> $conf_file
66 echo -e "{" >> $conf_file
67 append_num "$cfg" "$conf_file" latencies_default "default"
68 append_num "$cfg" "$conf_file" latencies_itunes "itunes"
69 append_num "$cfg" "$conf_file" latencies_airplay "airplay"
70 append_num "$cfg" "$conf_file" latencies_forked_daapd "forkedDaapd"
71 echo -e "};\n" >> $conf_file
72
73 # Metadata
74 echo -e "metadata =" >> $conf_file
75 echo -e "{" >> $conf_file
76 append_str "$cfg" "$conf_file" metadata_enabled "enabled"
77 append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art"
78 append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name"
79 echo -e "};\n" >> $conf_file
80
81 # Session control
82 echo -e "sessioncontrol =" >> $conf_file
83 echo -e "{" >> $conf_file
84 append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins"
85 append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends"
86 append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion"
87 append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption"
88 append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout"
89 echo -e "};\n" >> $conf_file
90
91 # Alsa audio back end
92 echo -e "alsa =" >> $conf_file
93 echo -e "{" >> $conf_file
94 append_str "$cfg" "$conf_file" alsa_output_device "output_device"
95 append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name"
96 append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device"
97 append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset"
98 append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length"
99 echo -e "};\n" >> $conf_file
100
101 # Pipe audio back end
102 echo -e "pipe =" >> $conf_file
103 echo -e "{" >> $conf_file
104 append_str "$cfg" "$conf_file" pipe_name "name"
105 append_num "$cfg" "$conf_file" pipe_latency_offset "audio_backend_latency_offset"
106 append_num "$cfg" "$conf_file" pipe_buffer_length "audio_backend_buffer_desired_length"
107 echo -e "};\n" >> $conf_file
108
109 # Stdout audio back end
110 echo -e "stdout =" >> $conf_file
111 echo -e "{" >> $conf_file
112 append_num "$cfg" "$conf_file" stdout_latency_offset "audio_backend_latency_offset"
113 append_num "$cfg" "$conf_file" stdout_buffer_length "audio_backend_buffer_desired_length"
114 echo -e "};\n" >> $conf_file
115 fi
116
117 procd_open_instance
118
119 procd_set_param command /usr/bin/shairport-sync
120 procd_append_param command -c $conf_file
121
122 config_get_bool aux "$cfg" 'respawn' '0'
123 [ "$aux" = 1 ] && procd_set_param respawn
124
125 procd_close_instance
126 }
127
128 service_triggers() {
129 procd_add_reload_trigger "shairport-sync"
130 }
131
132 start_service() {
133 config_load shairport-sync
134 config_foreach start_instance shairport-sync
135 }