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.

105 lines
2.4 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2010 OpenWrt.org
  3. START=81
  4. PROG=/usr/sbin/minidlnad
  5. USE_PROCD=1
  6. MINIDLNA_CONFIG_FILE="/var/etc/minidlna.conf"
  7. minidlna_cfg_addbool() {
  8. local cfg="$1"
  9. local key="$2"
  10. local def="$3"
  11. local val
  12. config_get_bool val "$cfg" "$key" "$def"
  13. [ "$val" -gt 0 ] && val="yes" || val="no"
  14. echo "$key=$val"
  15. }
  16. minidlna_cfg_addstr() {
  17. local cfg="$1"
  18. local key="$2"
  19. local def="$3"
  20. local val
  21. config_get val "$cfg" "$key" "$def"
  22. [ -n "$val" ] && echo "$key=$val"
  23. }
  24. minidlna_cfg_add_media_dir() {
  25. local val=$1
  26. echo "media_dir=$val"
  27. }
  28. minidlna_create_config() {
  29. local cfg=$1
  30. local port
  31. local interface
  32. config_get port "$cfg" port
  33. config_get interface "$cfg" interface
  34. { [ -z "$interface" ] || [ -t "$port" ]; } && return 1
  35. mkdir -p /var/etc
  36. echo "# this file is generated automatically, don't edit"
  37. echo "port=$port"
  38. echo "network_interface=$interface"
  39. minidlna_cfg_addstr "$cfg" friendly_name
  40. minidlna_cfg_addstr "$cfg" user
  41. minidlna_cfg_addstr "$cfg" db_dir
  42. minidlna_cfg_addstr "$cfg" log_level 'error'
  43. minidlna_cfg_addbool "$cfg" inotify '1'
  44. minidlna_cfg_addbool "$cfg" enable_tivo '0'
  45. minidlna_cfg_addbool "$cfg" wide_links '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. minidlna_cfg_addstr "$cfg" uuid '019f9a56-ff60-44c0-9edc-eae88d09fa05'
  55. config_list_foreach "$cfg" "media_dir" minidlna_cfg_add_media_dir
  56. return 0
  57. } > "$MINIDLNA_CONFIG_FILE"
  58. start_service() {
  59. local enabled
  60. local db_dir
  61. local user
  62. local val
  63. config_load 'minidlna'
  64. config_get_bool enabled config 'enabled' '0'
  65. [ "$enabled" -gt 0 ] || return 1
  66. config_get val "config" uuid
  67. [ "$val" = '' ] && uci set minidlna.config.uuid="$(cat /proc/sys/kernel/random/uuid)" && uci commit
  68. minidlna_create_config config || return 1
  69. config_get db_dir config 'db_dir' '/var/run/minidlna'
  70. config_get user config 'user' 'minidlna'
  71. [ -d "$db_dir" ] || {
  72. mkdir -m 755 -p "$db_dir"
  73. chown -R "$user":"$user" "$db_dir"
  74. }
  75. procd_open_instance
  76. procd_set_param command "$PROG"
  77. procd_append_param command -S -f "$MINIDLNA_CONFIG_FILE"
  78. procd_set_param stdout 1
  79. procd_set_param stderr 1
  80. procd_set_param respawn
  81. procd_close_instance
  82. }