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.

98 lines
2.1 KiB

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