triggerhappy: moved to github
[openwrt.org/packages.git] / net / transmission.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2012 OpenWrt.org

START=99

LIST_SEP="
"

append_params() {
	local p; local v; local s="$1"; shift
	for p in $*; do
		config_get v "$s" "$p"
		IFS="$LIST_SEP"
		for v in $v; do
			[ -n "$v" ] && (
				echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_file
			)
		done
		unset IFS
	done
}

append_params_quotes() {
	local p; local v; local s="$1"; shift
	for p in $*; do
		config_get v "$s" "$p"
		IFS="$LIST_SEP"
		for v in $v; do
			[ -n "$v" ] && (
				echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_file; \
				echo "\": \""$v"\"," >> $config_file
			)
		done
		unset IFS
	done
}

section_enabled() {
	config_get_bool enabled "$1" 'enabled' 0
	[ $enabled -gt 0 ]
}

start_instance() {
	local s="$1"
	local user

	section_enabled "$section" || return 1

	config_get config_dir "$s" 'config_dir' '/var/etc/transmission'
	config_get user "$s" 'user'

	config_file="$config_dir/settings.json"
	[ -d $config_dir ] || {
		mkdir -m 0755 -p "$config_dir"
		touch $config_file
		[ -z "$user" ] || chown -R $user $config_dir
	}

	echo "{" > $config_file

	append_params "$s" \
		alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
		alt_speed_time_enabled alt_speed_time_end alt_speed_up blocklist_enabled \
		cache_size_mb download_queue_enabled download_queue_size \
		dht_enabled encryption idle_seeding_limit idle_seeding_limit_enabled \
		incomplete_dir_enabled lazy_bitfield_enabled lpd_enabled message_level \
		peer_limit_global peer_limit_per_torrent peer_port \
		peer_port_random_high peer_port_random_low peer_port_random_on_start \
		pex_enabled port_forwarding_enabled preallocation prefetch_enabled \
		ratio_limit ratio_limit_enabled rename_partial_files rpc_authentication_required \
		rpc_enabled rpc_port rpc_whitelist_enabled queue_stalled_enabled \
		queue_stalled_minutes scrape_paused_torrents_enabled script_torrent_done_enabled \
		seed_queue_enabled seed_queue_size \
		speed_limit_down speed_limit_down_enabled speed_limit_up \
		speed_limit_up_enabled start_added_torrents trash_original_torrent_files \
		umask upload_slots_per_torrent utp_enabled scrape_paused_torrents \
		watch_dir_enabled

	append_params_quotes "$s" \
		blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
		peer_congestion_algorithm peer_socket_tos rpc_bind_address rpc_password rpc_url \
		rpc_username rpc_whitelist script_torrent_done_filename watch_dir

	echo "\""invalid-key"\": false" >> $config_file
	echo "}" >> $config_file

	SERVICE_UID="$user" \
	service_start /usr/bin/transmission-daemon -g $config_dir
}

stop_instance() {
	local s="$1"
	local user

	section_enabled "$section" || return 1

	config_get user "$s" 'user'

	SERVICE_UID="$user" \
	service_stop /usr/bin/transmission-daemon
}

start() {
	config_load 'transmission'
	config_foreach start_instance 'transmission'
}

stop() {
	config_load 'transmission'
	config_foreach stop_instance 'transmission'
}

comments