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.

104 lines
2.4 KiB

11 years ago
11 years ago
11 years ago
11 years ago
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="/var/etc/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. mkdir -p /var/etc
  39. echo "# this file is generated automatically, don't edit" > "$MINIDLNA_CONFIG_FILE"
  40. minidlna_cfg_append "port=$port"
  41. minidlna_cfg_append "network_interface=$interface"
  42. minidlna_cfg_addstr "$cfg" friendly_name
  43. minidlna_cfg_addstr "$cfg" user
  44. minidlna_cfg_addstr "$cfg" db_dir
  45. minidlna_cfg_addstr "$cfg" log_dir
  46. minidlna_cfg_addstr "$cfg" log_level 'error'
  47. minidlna_cfg_addbool "$cfg" inotify '1'
  48. minidlna_cfg_addbool "$cfg" enable_tivo '0'
  49. minidlna_cfg_addbool "$cfg" wide_links '0'
  50. minidlna_cfg_addbool "$cfg" strict_dlna '0'
  51. minidlna_cfg_addstr "$cfg" album_art_names
  52. minidlna_cfg_addstr "$cfg" presentation_url
  53. minidlna_cfg_addstr "$cfg" notify_interval '900'
  54. minidlna_cfg_addstr "$cfg" serial '12345678'
  55. minidlna_cfg_addstr "$cfg" model_number '1'
  56. minidlna_cfg_addstr "$cfg" minissdpsocket
  57. minidlna_cfg_addstr "$cfg" root_container '.'
  58. minidlna_cfg_addstr "$cfg" uuid '019f9a56-ff60-44c0-9edc-eae88d09fa05'
  59. config_list_foreach "$cfg" "media_dir" minidlna_cfg_add_media_dir
  60. return 0
  61. }
  62. start() {
  63. local enabled
  64. local db_dir
  65. local log_dir
  66. local user
  67. config_load 'minidlna'
  68. config_get_bool enabled config 'enabled' '0'
  69. [ "$enabled" -gt 0 ] || return 1
  70. minidlna_create_config config || return 1
  71. config_get db_dir config 'db_dir' '/var/run/minidlna'
  72. config_get log_dir config 'log_dir' '/var/log/minidlna'
  73. config_get user config 'user' 'root'
  74. mkdir -m 0755 -p "$db_dir" "$log_dir"
  75. chown -R "$user" "$db_dir" "$log_dir"
  76. service_start /usr/bin/minidlna -f "$MINIDLNA_CONFIG_FILE"
  77. }
  78. stop() {
  79. service_stop /usr/bin/minidlna
  80. }