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.

99 lines
2.2 KiB

11 years ago
11 years ago
11 years ago
11 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_addstr $cfg log_level 'error'
  45. minidlna_cfg_addbool $cfg inotify '1'
  46. minidlna_cfg_addbool $cfg enable_tivo '0'
  47. minidlna_cfg_addbool $cfg wide_links '0'
  48. minidlna_cfg_addbool $cfg strict_dlna '0'
  49. minidlna_cfg_addstr $cfg album_art_names
  50. minidlna_cfg_addstr $cfg presentation_url
  51. minidlna_cfg_addstr $cfg notify_interval '900'
  52. minidlna_cfg_addstr $cfg serial '12345678'
  53. minidlna_cfg_addstr $cfg model_number '1'
  54. minidlna_cfg_addstr $cfg minissdpsocket
  55. minidlna_cfg_addstr $cfg root_container '.'
  56. config_list_foreach "$cfg" "media_dir" minidlna_cfg_add_media_dir
  57. return 0
  58. }
  59. start() {
  60. local enabled
  61. local db_dir
  62. local log_dir
  63. config_load 'minidlna'
  64. config_get_bool enabled config 'enabled' '0'
  65. [ "$enabled" -gt 0 ] || return 1
  66. minidlna_create_config config || return 1
  67. config_get db_dir config 'db_dir' '/var/run/minidlna'
  68. config_get log_dir config 'log_dir' '/var/log'
  69. mkdir -m 0755 -p $db_dir
  70. mkdir -m 0755 -p $log_dir
  71. service_start /usr/bin/minidlna -f "$MINIDLNA_CONFIG_FILE"
  72. }
  73. stop() {
  74. service_stop /usr/bin/minidlna
  75. }