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.

135 lines
4.5 KiB

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