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.

91 lines
1.8 KiB

  1. #!/bin/sh /etc/rc.common
  2. NAME=shairport
  3. START=94
  4. SERVICE_DAEMONIZE=1
  5. SERVICE_WRITE_PID=1
  6. AP_PIDDIR=/var/run
  7. AP_BIN=/usr/bin/shairport
  8. append_arg() {
  9. local cfg="$1"
  10. local var="$2"
  11. local opt="$3"
  12. local def="$4"
  13. local val
  14. config_get val "$cfg" "$var"
  15. [ -n "$val" -o -n "$def" ] && append AP_ARGS "$opt ${val:-$def}"
  16. }
  17. append_bool() {
  18. local cfg="$1"
  19. local var="$2"
  20. local opt="$3"
  21. local def="$4"
  22. local val
  23. config_get_bool val "$cfg" "$var" "$def"
  24. [ "$val" = 1 ] && append AP_ARGS "$opt"
  25. }
  26. start_instance() {
  27. AP_ARGS=""
  28. local cfg="$1"
  29. local ao dev
  30. append_arg "$cfg" bname "-a" "AirPort"
  31. append_arg "$cfg" log "-l"
  32. append_arg "$cfg" initbuf "-b" "256"
  33. append_arg "$cfg" port "-p" "5002"
  34. append_arg "$cfg" password "-k"
  35. append_arg "$cfg" mdns "-m"
  36. append_arg "$cfg" cmd_start "-B"
  37. append_arg "$cfg" cmd_stop "-E"
  38. append_bool "$cfg" cmd_wait "-w"
  39. append_arg "$cfg" audio_output "-o"
  40. config_get ao "$cfg" audio_output ""
  41. if [ "$ao" = "alsa" ]; then
  42. config_get dev "$cfg" output_device ""
  43. if [ -n "$dev" ]; then
  44. append AP_ARGS "--"
  45. append_arg "$cfg" output_device "-d"
  46. append_arg "$cfg" mixer_device "-m"
  47. append_arg "$cfg" mixer_type "-t"
  48. append_arg "$cfg" mixer-control "-c"
  49. append_arg "$cfg" mixer-index "-i"
  50. fi
  51. fi
  52. SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
  53. service_start $AP_BIN $AP_ARGS
  54. # Check if daemon is running, if not then
  55. # re-execute in foreground to display error.
  56. sleep 1 && service_check $AP_BIN || \
  57. $AP_BIN $AP_ARGS
  58. }
  59. stop_instance()
  60. {
  61. local cfg="$1"
  62. SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
  63. SERVICE_SIG_STOP="INT"
  64. service_stop $AP_BIN
  65. }
  66. start() {
  67. config_load shairport
  68. config_foreach start_instance shairport
  69. }
  70. stop() {
  71. config_load shairport
  72. config_foreach stop_instance shairport
  73. }