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.

78 lines
1.5 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
  26. procd_open_instance
  27. procd_set_param command /usr/bin/shairport
  28. append_arg "$cfg" bname "-a" "AirPort"
  29. append_arg "$cfg" log "-l"
  30. append_arg "$cfg" initbuf "-b" "256"
  31. append_arg "$cfg" port "-p" "5002"
  32. append_arg "$cfg" password "-k"
  33. append_arg "$cfg" mdns "-m"
  34. append_arg "$cfg" cmd_start "-B"
  35. append_arg "$cfg" cmd_stop "-E"
  36. append_bool "$cfg" cmd_wait "-w"
  37. append_arg "$cfg" audio_output "-o"
  38. config_get ao "$cfg" audio_output ""
  39. if [ "$ao" = "alsa" ]; then
  40. config_get dev "$cfg" output_dev ""
  41. if [ -n "$dev" ]; then
  42. procd_append_param command "--"
  43. append_arg "$cfg" output_dev "-d"
  44. append_arg "$cfg" mixer_dev "-m"
  45. append_arg "$cfg" mixer_type "-t"
  46. append_arg "$cfg" mixer_control "-c"
  47. append_arg "$cfg" mixer_index "-i"
  48. fi
  49. fi
  50. procd_close_instance
  51. }
  52. service_triggers() {
  53. procd_add_reload_trigger "shairport"
  54. }
  55. start_service() {
  56. config_load shairport
  57. config_foreach start_instance shairport
  58. }
  59. stop_service() {
  60. # FIXME: workaround until procd supports custom signal
  61. killall -SIGINT shairport
  62. }