vips: moved to github
[openwrt.org/packages.git] / multimedia / minidlna.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh /etc/rc.common
# Copyright (C) 2010 OpenWrt.org

START=50

SERVICE_USE_PID=1

MINIDLNA_CONFIG_FILE="/tmp/minidlna.conf"

minidlna_cfg_append() {
	echo "$1" >> "$MINIDLNA_CONFIG_FILE"
}

minidlna_cfg_addbool() {
	local cfg="$1"
	local key="$2"
	local def="$3"
	local val

	config_get_bool val "$cfg" "$key" "$def"
	[ "$val" -gt 0 ] && val="yes" || val="no"
	minidlna_cfg_append "$key=$val"
}

minidlna_cfg_addstr() {
	local cfg="$1"
	local key="$2"
	local def="$3"
	local val

	config_get val "$cfg" "$key" "$def"
	[ -n "$val" ] && minidlna_cfg_append "$key=$val"
}

minidlna_cfg_add_media_dir() {
	local val=$1

	minidlna_cfg_append "media_dir=$val"
}

minidlna_create_config() {
	local cfg=$1
	local port
	local interface

	config_get port $cfg port
	config_get interface $cfg interface

	[ -z "$interface" -o -t "$port" ] && return 1

	echo "# this file is generated automatically, don't edit" > "$MINIDLNA_CONFIG_FILE"

	minidlna_cfg_append "port=$port"
	minidlna_cfg_append "network_interface=$interface"

	minidlna_cfg_addstr $cfg friendly_name
	minidlna_cfg_addstr $cfg db_dir
	minidlna_cfg_addstr $cfg log_dir
	minidlna_cfg_addbool $cfg inotify '1'
	minidlna_cfg_addbool $cfg enable_tivo '0'
	minidlna_cfg_addbool $cfg strict_dlna '0'
	minidlna_cfg_addstr $cfg album_art_names
	minidlna_cfg_addstr $cfg presentation_url
	minidlna_cfg_addstr $cfg notify_interval '900'
	minidlna_cfg_addstr $cfg serial '12345678'
	minidlna_cfg_addstr $cfg model_number '1'
	minidlna_cfg_addstr $cfg minissdpsocket
	minidlna_cfg_addstr $cfg root_container '.'
	config_list_foreach "$cfg" "media_dir" minidlna_cfg_add_media_dir

	return 0
}

start() {
	local enabled
	local db_dir
	local log_dir

	config_load 'minidlna'
	config_get_bool enabled config 'enabled' '0'

	[ "$enabled" -gt 0 ] || return 1

	minidlna_create_config config || return 1
	
	config_get db_dir config 'db_dir' '/var/run/minidlna'
	config_get log_dir config 'log_dir' '/var/log'

	mkdir -m 0755 -p $db_dir
	mkdir -m 0755 -p $log_dir
	service_start /usr/bin/minidlna -f "$MINIDLNA_CONFIG_FILE"
}

stop() {
	service_stop /usr/bin/minidlna
}

comments