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.

104 lines
2.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2013-2014 OpenWrt.org
  3. START=94
  4. USE_PROCD=1
  5. append_arg() {
  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. [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
  13. }
  14. append_bool() {
  15. local cfg="$1"
  16. local var="$2"
  17. local opt="$3"
  18. local def="$4"
  19. local val
  20. config_get_bool val "$cfg" "$var" "$def"
  21. [ "$val" = 1 ] && procd_append_param command "$opt"
  22. }
  23. start_instance() {
  24. local cfg="$1"
  25. local ao dev aux
  26. config_get_bool aux "$cfg" 'disabled' '0'
  27. [ "$aux" = 1 ] && return 1
  28. procd_open_instance
  29. procd_set_param command /usr/bin/shairport
  30. append_arg "$cfg" bname "-a" "AirPort"
  31. append_arg "$cfg" log_file "-l"
  32. append_arg "$cfg" err_file "-e"
  33. append_arg "$cfg" meta_dir "-M"
  34. append_arg "$cfg" buffer "-b"
  35. append_arg "$cfg" port "-p"
  36. append_arg "$cfg" password "-k"
  37. append_arg "$cfg" mdns "-m"
  38. append_arg "$cfg" cmd_start "-B"
  39. append_arg "$cfg" cmd_stop "-E"
  40. append_bool "$cfg" cmd_wait "-w"
  41. append_arg "$cfg" audio_output "-o"
  42. config_get ao "$cfg" audio_output ""
  43. if [ "$ao" = "alsa" ]; then
  44. config_get dev "$cfg" output_dev ""
  45. if [ -n "$dev" ]; then
  46. procd_append_param command "--"
  47. append_arg "$cfg" output_dev "-d"
  48. append_arg "$cfg" mixer_dev "-m"
  49. append_arg "$cfg" mixer_type "-t"
  50. append_arg "$cfg" mixer_control "-c"
  51. append_arg "$cfg" mixer_index "-i"
  52. fi
  53. elif [ "$ao" = "ao" ]; then
  54. config_get dev "$cfg" ao_driver ""
  55. if [ -n "$dev" ]; then
  56. procd_append_param command "--"
  57. append_arg "$cfg" ao_driver "-d"
  58. append_arg "$cfg" ao_id "-i"
  59. append_arg "$cfg" ao_name "-n"
  60. append_arg "$cfg" ao_options "-o"
  61. fi
  62. elif [ "$ao" = "pipe" ]; then
  63. config_get dev "$cfg" output_fifo ""
  64. if [ -n "$dev" ]; then
  65. procd_append_param command "--"
  66. append_arg "$cfg" output_fifo ""
  67. fi
  68. elif [ "$ao" = "pulse" ]; then
  69. config_get dev "$cfg" pulse_server ""
  70. if [ -n "$dev" ]; then
  71. procd_append_param command "--"
  72. append_arg "$cfg" pulse_server "-a"
  73. append_arg "$cfg" pulse_sink "-s"
  74. append_arg "$cfg" pulse_appname "-n"
  75. fi
  76. fi
  77. config_get_bool aux "$cfg" 'respawn' '0'
  78. [ "$aux" = 1 ] && procd_set_param respawn
  79. procd_close_instance
  80. }
  81. service_triggers() {
  82. procd_add_reload_trigger "shairport"
  83. }
  84. start_service() {
  85. config_load shairport
  86. config_foreach start_instance shairport
  87. }