lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

shairport-sync.init (5192B)


      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 		append_str "$cfg" "$conf_file" playback_mode "playback_mode"
     64 		echo -e "};\n" >> $conf_file
     65 
     66 		# Metadata
     67 		echo -e "metadata =" >> $conf_file
     68 		echo -e "{" >> $conf_file
     69 		append_str "$cfg" "$conf_file" metadata_enabled "enabled"
     70 		append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art"
     71 		append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name"
     72 		append_num "$cfg" "$conf_file" metadata_pipe_timeout "pipe_timeout"
     73 		append_str "$cfg" "$conf_file" metadata_socket_address "socket_address"
     74 		append_num "$cfg" "$conf_file" metadata_socket_port "socket_port"
     75 		append_num "$cfg" "$conf_file" metadata_socket_msglength "socket_msglength"
     76 		echo -e "};\n" >> $conf_file
     77 
     78 		# Session control
     79 		echo -e "sessioncontrol =" >> $conf_file
     80 		echo -e "{" >> $conf_file
     81 		append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins"
     82 		append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends"
     83 		append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion"
     84 		append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption"
     85 		append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout"
     86 		echo -e "};\n" >> $conf_file
     87 
     88 		# Alsa audio back end
     89 		echo -e "alsa =" >> $conf_file
     90 		echo -e "{" >> $conf_file
     91 		append_str "$cfg" "$conf_file" alsa_output_device "output_device"
     92 		append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name"
     93 		append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device"
     94 		append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset"
     95 		append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length"
     96 		append_str "$cfg" "$conf_file" alsa_disable_synchronization "disable_synchronization"
     97 		append_num "$cfg" "$conf_file" alsa_period_size "period_size"
     98 		append_num "$cfg" "$conf_file" alsa_buffer_size "buffer_size"
     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 
    116 		# AO audio back end
    117 		echo -e "ao =" >> $conf_file
    118 		echo -e "{" >> $conf_file
    119 		append_num "$cfg" "$conf_file" ao_latency_offset "audio_backend_latency_offset"
    120 		append_num "$cfg" "$conf_file" ao_buffer_length "audio_backend_buffer_desired_length"
    121 		echo -e "};\n" >> $conf_file
    122 	fi
    123 
    124 	procd_open_instance
    125 
    126 	procd_set_param command /usr/bin/shairport-sync
    127 	procd_append_param command -c $conf_file
    128 
    129 	config_get_bool aux "$cfg" 'respawn' '0'
    130 	[ "$aux" = 1 ] && procd_set_param respawn
    131 
    132 	procd_close_instance
    133 }
    134 
    135 service_triggers() {
    136 	procd_add_reload_trigger "shairport-sync"
    137 }
    138 
    139 start_service() {
    140 	config_load shairport-sync
    141 	config_foreach start_instance shairport-sync
    142 }