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.

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