You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.1 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015-2016 OpenWrt.org
  3. START=99
  4. USE_PROCD=1
  5. append_num() {
  6. local cfg="$1"
  7. local file="$2"
  8. local var="$3"
  9. local opt="$4"
  10. local def="$5"
  11. local val
  12. config_get val "$cfg" "$var"
  13. [ -n "$val" -o -n "$def" ] && echo -e "\t$opt = ${val:-$def};" >> $file
  14. }
  15. append_str() {
  16. local cfg="$1"
  17. local file="$2"
  18. local var="$3"
  19. local opt="$4"
  20. local def="$5"
  21. local val
  22. config_get val "$cfg" "$var"
  23. [ -n "$val" -o -n "$def" ] && echo -e "\t$opt = \"${val:-$def}\";" >> $file
  24. }
  25. start_instance() {
  26. local cfg=$1
  27. local conf_custom conf_file aux
  28. config_get_bool aux "$cfg" 'enabled' '0'
  29. [ "$aux" = 0 ] && return 1
  30. config_get_bool conf_custom "$cfg" 'conf_custom' '0'
  31. config_get conf_file "$cfg" "conf_file"
  32. if [ $conf_custom -ne 1 ] && [ ! -n "$conf_file" ]; then
  33. mkdir -p /var/etc
  34. conf_file="/var/etc/shairport-sync-${cfg}.conf"
  35. echo -e "// Automatically generated from UCI config\n" > $conf_file
  36. # General
  37. echo -e "general =" >> $conf_file
  38. echo -e "{" >> $conf_file
  39. append_str "$cfg" "$conf_file" name "name"
  40. append_str "$cfg" "$conf_file" password "password"
  41. append_str "$cfg" "$conf_file" interpolation "interpolation"
  42. append_str "$cfg" "$conf_file" output_backend "output_backend"
  43. append_str "$cfg" "$conf_file" mdns_backend "mdns_backend"
  44. append_num "$cfg" "$conf_file" port "port"
  45. append_num "$cfg" "$conf_file" udp_port_base "udp_port_base"
  46. append_num "$cfg" "$conf_file" udp_port_range "udp_port_range"
  47. append_str "$cfg" "$conf_file" statistics "statistics"
  48. append_num "$cfg" "$conf_file" drift "drift"
  49. append_num "$cfg" "$conf_file" resync_threshold "resync_threshold"
  50. append_num "$cfg" "$conf_file" log_verbosity "log_verbosity"
  51. append_str "$cfg" "$conf_file" ignore_volume_control "ignore_volume_control"
  52. append_num "$cfg" "$conf_file" volume_range_db "volume_range_db"
  53. append_str "$cfg" "$conf_file" regtype "regtype"
  54. append_str "$cfg" "$conf_file" playback_mode "playback_mode"
  55. echo -e "};\n" >> $conf_file
  56. # Metadata
  57. echo -e "metadata =" >> $conf_file
  58. echo -e "{" >> $conf_file
  59. append_str "$cfg" "$conf_file" metadata_enabled "enabled"
  60. append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art"
  61. append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name"
  62. append_num "$cfg" "$conf_file" metadata_pipe_timeout "pipe_timeout"
  63. append_str "$cfg" "$conf_file" metadata_socket_address "socket_address"
  64. append_num "$cfg" "$conf_file" metadata_socket_port "socket_port"
  65. append_num "$cfg" "$conf_file" metadata_socket_msglength "socket_msglength"
  66. echo -e "};\n" >> $conf_file
  67. # Session control
  68. echo -e "sessioncontrol =" >> $conf_file
  69. echo -e "{" >> $conf_file
  70. append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins"
  71. append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends"
  72. append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion"
  73. append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption"
  74. append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout"
  75. echo -e "};\n" >> $conf_file
  76. # Alsa audio back end
  77. echo -e "alsa =" >> $conf_file
  78. echo -e "{" >> $conf_file
  79. append_str "$cfg" "$conf_file" alsa_output_device "output_device"
  80. append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name"
  81. append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device"
  82. append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset"
  83. append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length"
  84. append_str "$cfg" "$conf_file" alsa_disable_synchronization "disable_synchronization"
  85. append_num "$cfg" "$conf_file" alsa_period_size "period_size"
  86. append_num "$cfg" "$conf_file" alsa_buffer_size "buffer_size"
  87. echo -e "};\n" >> $conf_file
  88. # Pipe audio back end
  89. echo -e "pipe =" >> $conf_file
  90. echo -e "{" >> $conf_file
  91. append_str "$cfg" "$conf_file" pipe_name "name"
  92. append_num "$cfg" "$conf_file" pipe_latency_offset "audio_backend_latency_offset"
  93. append_num "$cfg" "$conf_file" pipe_buffer_length "audio_backend_buffer_desired_length"
  94. echo -e "};\n" >> $conf_file
  95. # Stdout audio back end
  96. echo -e "stdout =" >> $conf_file
  97. echo -e "{" >> $conf_file
  98. append_num "$cfg" "$conf_file" stdout_latency_offset "audio_backend_latency_offset"
  99. append_num "$cfg" "$conf_file" stdout_buffer_length "audio_backend_buffer_desired_length"
  100. echo -e "};\n" >> $conf_file
  101. # AO audio back end
  102. echo -e "ao =" >> $conf_file
  103. echo -e "{" >> $conf_file
  104. append_num "$cfg" "$conf_file" ao_latency_offset "audio_backend_latency_offset"
  105. append_num "$cfg" "$conf_file" ao_buffer_length "audio_backend_buffer_desired_length"
  106. echo -e "};\n" >> $conf_file
  107. fi
  108. procd_open_instance
  109. procd_set_param command /usr/bin/shairport-sync
  110. procd_append_param command -c $conf_file
  111. config_get_bool aux "$cfg" 'respawn' '0'
  112. [ "$aux" = 1 ] && procd_set_param respawn
  113. procd_close_instance
  114. }
  115. service_triggers() {
  116. procd_add_reload_trigger "shairport-sync"
  117. }
  118. start_service() {
  119. config_load shairport-sync
  120. config_foreach start_instance shairport-sync
  121. }