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.

96 lines
2.1 KiB

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