source: packages/multimedia/minidlna/files/minidlna.init @ 31211

Last change on this file since 31211 was 31211, checked in by juhosg, 5 years ago

packages/minidlna: add uci configuration support

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