Merge pull request #2126 from lynxis/libmicrohttpd
[feed/packages.git] / sound / shairport-sync / files / shairport-sync.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2015-2016 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 append_str "$cfg" "$conf_file" regtype "regtype"
63 echo -e "};\n" >> $conf_file
64
65 # Metadata
66 echo -e "metadata =" >> $conf_file
67 echo -e "{" >> $conf_file
68 append_str "$cfg" "$conf_file" metadata_enabled "enabled"
69 append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art"
70 append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name"
71 echo -e "};\n" >> $conf_file
72
73 # Session control
74 echo -e "sessioncontrol =" >> $conf_file
75 echo -e "{" >> $conf_file
76 append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins"
77 append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends"
78 append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion"
79 append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption"
80 append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout"
81 echo -e "};\n" >> $conf_file
82
83 # Alsa audio back end
84 echo -e "alsa =" >> $conf_file
85 echo -e "{" >> $conf_file
86 append_str "$cfg" "$conf_file" alsa_output_device "output_device"
87 append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name"
88 append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device"
89 append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset"
90 append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length"
91 append_str "$cfg" "$conf_file" alsa_disable_synchronization "disable_synchronization"
92 append_num "$cfg" "$conf_file" alsa_period_size "period_size"
93 append_num "$cfg" "$conf_file" alsa_buffer_size "buffer_size"
94 echo -e "};\n" >> $conf_file
95
96 # Pipe audio back end
97 echo -e "pipe =" >> $conf_file
98 echo -e "{" >> $conf_file
99 append_str "$cfg" "$conf_file" pipe_name "name"
100 append_num "$cfg" "$conf_file" pipe_latency_offset "audio_backend_latency_offset"
101 append_num "$cfg" "$conf_file" pipe_buffer_length "audio_backend_buffer_desired_length"
102 echo -e "};\n" >> $conf_file
103
104 # Stdout audio back end
105 echo -e "stdout =" >> $conf_file
106 echo -e "{" >> $conf_file
107 append_num "$cfg" "$conf_file" stdout_latency_offset "audio_backend_latency_offset"
108 append_num "$cfg" "$conf_file" stdout_buffer_length "audio_backend_buffer_desired_length"
109 echo -e "};\n" >> $conf_file
110
111 # AO audio back end
112 echo -e "ao =" >> $conf_file
113 echo -e "{" >> $conf_file
114 append_num "$cfg" "$conf_file" ao_latency_offset "audio_backend_latency_offset"
115 append_num "$cfg" "$conf_file" ao_buffer_length "audio_backend_buffer_desired_length"
116 echo -e "};\n" >> $conf_file
117 fi
118
119 procd_open_instance
120
121 procd_set_param command /usr/bin/shairport-sync
122 procd_append_param command -c $conf_file
123
124 config_get_bool aux "$cfg" 'respawn' '0'
125 [ "$aux" = 1 ] && procd_set_param respawn
126
127 procd_close_instance
128 }
129
130 service_triggers() {
131 procd_add_reload_trigger "shairport-sync"
132 }
133
134 start_service() {
135 config_load shairport-sync
136 config_foreach start_instance shairport-sync
137 }