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.

137 lines
4.7 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" 'disabled' '0'
  29. [ "$aux" = 1 ] && 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. echo -e "};\n" >> $conf_file
  55. # Metadata
  56. echo -e "metadata =" >> $conf_file
  57. echo -e "{" >> $conf_file
  58. append_str "$cfg" "$conf_file" metadata_enabled "enabled"
  59. append_str "$cfg" "$conf_file" metadata_cover_art "include_cover_art"
  60. append_str "$cfg" "$conf_file" metadata_pipe_name "pipe_name"
  61. echo -e "};\n" >> $conf_file
  62. # Session control
  63. echo -e "sessioncontrol =" >> $conf_file
  64. echo -e "{" >> $conf_file
  65. append_str "$cfg" "$conf_file" sesctl_run_before_play_begins "run_this_before_play_begins"
  66. append_str "$cfg" "$conf_file" sesctl_run_after_play_ends "run_this_after_play_ends"
  67. append_str "$cfg" "$conf_file" sesctl_wait_for_completion "wait_for_completion"
  68. append_str "$cfg" "$conf_file" sesctl_session_interruption "allow_session_interruption"
  69. append_num "$cfg" "$conf_file" sesctl_session_timeout "session_timeout"
  70. echo -e "};\n" >> $conf_file
  71. # Alsa audio back end
  72. echo -e "alsa =" >> $conf_file
  73. echo -e "{" >> $conf_file
  74. append_str "$cfg" "$conf_file" alsa_output_device "output_device"
  75. append_str "$cfg" "$conf_file" alsa_mixer_control_name "mixer_control_name"
  76. append_str "$cfg" "$conf_file" alsa_mixer_device "mixer_device"
  77. append_num "$cfg" "$conf_file" alsa_latency_offset "audio_backend_latency_offset"
  78. append_num "$cfg" "$conf_file" alsa_buffer_length "audio_backend_buffer_desired_length"
  79. append_str "$cfg" "$conf_file" alsa_disable_synchronization "disable_synchronization"
  80. append_num "$cfg" "$conf_file" alsa_period_size "period_size"
  81. append_num "$cfg" "$conf_file" alsa_buffer_size "buffer_size"
  82. echo -e "};\n" >> $conf_file
  83. # Pipe audio back end
  84. echo -e "pipe =" >> $conf_file
  85. echo -e "{" >> $conf_file
  86. append_str "$cfg" "$conf_file" pipe_name "name"
  87. append_num "$cfg" "$conf_file" pipe_latency_offset "audio_backend_latency_offset"
  88. append_num "$cfg" "$conf_file" pipe_buffer_length "audio_backend_buffer_desired_length"
  89. echo -e "};\n" >> $conf_file
  90. # Stdout audio back end
  91. echo -e "stdout =" >> $conf_file
  92. echo -e "{" >> $conf_file
  93. append_num "$cfg" "$conf_file" stdout_latency_offset "audio_backend_latency_offset"
  94. append_num "$cfg" "$conf_file" stdout_buffer_length "audio_backend_buffer_desired_length"
  95. echo -e "};\n" >> $conf_file
  96. # AO audio back end
  97. echo -e "ao =" >> $conf_file
  98. echo -e "{" >> $conf_file
  99. append_num "$cfg" "$conf_file" ao_latency_offset "audio_backend_latency_offset"
  100. append_num "$cfg" "$conf_file" ao_buffer_length "audio_backend_buffer_desired_length"
  101. echo -e "};\n" >> $conf_file
  102. fi
  103. procd_open_instance
  104. procd_set_param command /usr/bin/shairport-sync
  105. procd_append_param command -c $conf_file
  106. config_get_bool aux "$cfg" 'respawn' '0'
  107. [ "$aux" = 1 ] && procd_set_param respawn
  108. procd_close_instance
  109. }
  110. service_triggers() {
  111. procd_add_reload_trigger "shairport-sync"
  112. }
  113. start_service() {
  114. config_load shairport-sync
  115. config_foreach start_instance shairport-sync
  116. }