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.

97 lines
2.1 KiB

10 years ago
10 years ago
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2010 OpenWrt.org
  3. START=50
  4. SERVICE_USE_PID=1
  5. SERVICE_PID_FILE=/var/run/minidlna/minidlna.pid
  6. MINIDLNA_CONFIG_FILE="/tmp/minidlna.conf"
  7. minidlna_cfg_append() {
  8. echo "$1" >> "$MINIDLNA_CONFIG_FILE"
  9. }
  10. minidlna_cfg_addbool() {
  11. local cfg="$1"
  12. local key="$2"
  13. local def="$3"
  14. local val
  15. config_get_bool val "$cfg" "$key" "$def"
  16. [ "$val" -gt 0 ] && val="yes" || val="no"
  17. minidlna_cfg_append "$key=$val"
  18. }
  19. minidlna_cfg_addstr() {
  20. local cfg="$1"
  21. local key="$2"
  22. local def="$3"
  23. local val
  24. config_get val "$cfg" "$key" "$def"
  25. [ -n "$val" ] && minidlna_cfg_append "$key=$val"
  26. }
  27. minidlna_cfg_add_media_dir() {
  28. local val=$1
  29. minidlna_cfg_append "media_dir=$val"
  30. }
  31. minidlna_create_config() {
  32. local cfg=$1
  33. local port
  34. local interface
  35. config_get port $cfg port
  36. config_get interface $cfg interface
  37. [ -z "$interface" -o -t "$port" ] && return 1
  38. echo "# this file is generated automatically, don't edit" > "$MINIDLNA_CONFIG_FILE"
  39. minidlna_cfg_append "port=$port"
  40. minidlna_cfg_append "network_interface=$interface"
  41. minidlna_cfg_addstr $cfg friendly_name
  42. minidlna_cfg_addstr $cfg db_dir
  43. minidlna_cfg_addstr $cfg log_dir
  44. minidlna_cfg_addbool $cfg inotify '1'
  45. minidlna_cfg_addbool $cfg enable_tivo '0'
  46. minidlna_cfg_addbool $cfg strict_dlna '0'
  47. minidlna_cfg_addstr $cfg album_art_names
  48. minidlna_cfg_addstr $cfg presentation_url
  49. minidlna_cfg_addstr $cfg notify_interval '900'
  50. minidlna_cfg_addstr $cfg serial '12345678'
  51. minidlna_cfg_addstr $cfg model_number '1'
  52. minidlna_cfg_addstr $cfg minissdpsocket
  53. minidlna_cfg_addstr $cfg root_container '.'
  54. config_list_foreach "$cfg" "media_dir" minidlna_cfg_add_media_dir
  55. return 0
  56. }
  57. start() {
  58. local enabled
  59. local db_dir
  60. local log_dir
  61. config_load 'minidlna'
  62. config_get_bool enabled config 'enabled' '0'
  63. [ "$enabled" -gt 0 ] || return 1
  64. minidlna_create_config config || return 1
  65. config_get db_dir config 'db_dir' '/var/run/minidlna'
  66. config_get log_dir config 'log_dir' '/var/log'
  67. mkdir -m 0755 -p $db_dir
  68. mkdir -m 0755 -p $log_dir
  69. service_start /usr/bin/minidlna -f "$MINIDLNA_CONFIG_FILE"
  70. }
  71. stop() {
  72. service_stop /usr/bin/minidlna
  73. }