blob: 896cee18faaef9ee2f6858dad2ef25407b0a1cdf (
plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2015 OpenWrt.org
START=99
STOP=10
USE_PROCD=1
PROG="/usr/bin/transmission-daemon"
LIST_SEP="
"
append_params() {
local p; local v; local s="$1"; shift
IFS="$LIST_SEP"
for p in "$@"; do
config_get v "$s" "$p"
for v in $v; do
[ -n "$v" ] && echo "\"$p\": $v," | sed -e 's|_|-|g'
done
done
unset IFS
}
append_params_quotes() {
local p; local v; local s="$1"; shift
IFS="$LIST_SEP"
for p in "$@"; do
config_get v "$s" "$p"
for v in $v; do
[ -n "$v" ] && {
printf "\"%s" "$p" | sed -e 's|/|\\/|g;s|_|-|g'; \
echo "\": \"$v\","
}
done
done
unset IFS
}
transmission() {
local cfg="$1"
local enabled
config_get_bool enabled "$cfg" enabled 0
[ "$enabled" -gt 0 ] || {
echo "Transmission not enabled. Please enable in /etc/config/transmission"
logger -t "transmission" -p "daemon.info" "Transmission not enabled. Please enable in /etc/config/transmission"
return 1
}
local config_dir
config_get config_dir "$cfg" 'config_dir' '/var/etc/transmission'
local user
config_get user "$cfg" 'user'
local group
config_get group "$cfg" 'group'
local download_dir
config_get download_dir "$cfg" 'download_dir' '/var/etc/transmission'
local incomplete_dir
config_get incomplete_dir "$cfg" 'incomplete_dir' '/var/etc/transmission'
local incomplete_dir_enabled
config_get_bool incomplete_dir_enabled "$cfg" 'incomplete_dir_enabled' 0
local watch_dir
config_get watch_dir "$cfg" 'watch_dir' '/var/etc/transmission'
local watch_dir_enabled
config_get_bool watch_dir_enabled "$cfg" 'watch_dir_enabled' 0
local mem_percentage
config_get mem_percentage "$cfg" 'mem_percentage' '50'
local config_overwrite
config_get_bool config_overwrite "$cfg" config_overwrite 1
local nice
config_get nice "$cfg" nice 0
local web_home
config_get web_home "$cfg" 'web_home'
local ca_bundle
config_get_bool ca_bundle "$cfg" ca_bundle 1
[ "$ca_bundle" -gt 0 ] && ca_bundle_file="/etc/ssl/certs/ca-certificates.crt"
local seccomp_path
local MEM
MEM=$(sed -ne 's!^MemTotal:[[:space:]]*\([0-9]*\) kB$!\1!p' /proc/meminfo)
local USE
[ "$MEM" -gt 1 ] && USE=$((MEM * mem_percentage * 10))
config_file="$config_dir/settings.json"
[ -d "$config_dir" ] || {
mkdir -p "$config_dir"
chmod 0755 "$config_dir"
touch "$config_file"
mkdir -p "$config_dir/resume"
mkdir -p "$config_dir/torrents"
mkdir -p "$config_dir/blocklists"
[ -e "$config_dir/stats.json" ] || touch "$config_dir/stats.json"
[ -z "$user" ] || chown -R "$user:$group" "$config_dir"
}
[ -d "$download_dir" ] || {
mkdir -p "$download_dir"
chmod 0755 "$download_dir"
[ -z "$user" ] || chown -R "$user:$group" "$download_dir"
}
[ "$incomplete_dir_enabled" = "0" ] || [ -d "$incomplete_dir" ] || {
mkdir -p "$incomplete_dir"
chmod 0755 "$incomplete_dir"
[ -z "$user" ] || chown -R "$user:$group" "$incomplete_dir"
}
[ "$config_overwrite" = 0 ] || {
echo "{"
append_params "$cfg" \
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_id_ttl_hours 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 \
watch_dir_enabled rpc_host_whitelist_enabled
append_params_quotes "$cfg" \
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_host_whitelist rpc_whitelist script_torrent_done_filename watch_dir
echo "\"invalid-key\": false"
echo "}"
} > "$config_file"
procd_open_instance
procd_set_param command "$PROG"
procd_append_param command -f -g "$config_dir"
procd_set_param user "$user"
procd_set_param group "$group"
procd_set_param nice "$nice"
procd_set_param stderr 1
procd_set_param respawn
seccomp_path="/etc/seccomp/transmission-daemon.json"
if [ -f "$seccomp_path" ]; then
procd_set_param seccomp "$seccomp_path"
fi
if [ -z "$USE" ]; then
procd_set_param limits core="0 0"
else
procd_set_param limits core="0 0" as="$USE $USE"
logger -t transmission "Starting with $USE virt mem"
fi
[ -d "$web_home" ] && procd_append_param env TRANSMISSION_WEB_HOME="$web_home"
[ "$ca_bundle" -gt 0 ] && procd_append_param env CURL_CA_BUNDLE="$ca_bundle_file"
procd_add_jail transmission log
procd_add_jail_mount "$config_file"
procd_add_jail_mount_rw "$config_dir/resume"
procd_add_jail_mount_rw "$config_dir/torrents"
procd_add_jail_mount_rw "$config_dir/blocklists"
procd_add_jail_mount_rw "$config_dir/stats.json"
procd_add_jail_mount_rw "$download_dir"
[ "$incomplete_dir_enabled" = "1" ] && procd_add_jail_mount_rw "$incomplete_dir"
[ "$watch_dir_enabled" = "1" ] && procd_add_jail_mount_rw "$watch_dir"
web_home="${web_home:-/usr/share/transmission/public_html}"
[ -d "$web_home" ] && procd_add_jail_mount "$web_home"
[ -f "$ca_bundle_file" ] && procd_add_jail_mount "$ca_bundle_file"
procd_close_instance
}
start_service() {
config_load 'transmission'
config_foreach transmission 'transmission'
}
reload_service() {
procd_send_signal "$PROG"
}
transmission_mount_triggers() {
local cfg="$1"
local enabled
config_get_bool enabled "$cfg" enabled 0
[ "$enabled" -gt 0 ] || return 0
local config_dir download_dir incomplete_dir incomplete_dir_enabled \
watch_dir watch_dir_enabled web_home service_dirs
config_get config_dir "$cfg" 'config_dir' '/var/etc/transmission'
config_get download_dir "$cfg" 'download_dir' '/var/etc/transmission'
config_get_bool incomplete_dir_enabled "$cfg" 'incomplete_dir_enabled' 0
config_get incomplete_dir "$cfg" 'incomplete_dir' '/var/etc/transmission'
config_get_bool watch_dir_enabled "$cfg" 'watch_dir_enabled' 0
config_get watch_dir "$cfg" 'watch_dir' '/var/etc/transmission'
config_get web_home "$cfg" 'web_home'
service_dirs="$config_dir $download_dir $web_home"
[ "$incomplete_dir_enabled" = "0" ] || service_dirs="$service_dirs $incomplete_dir"
[ "$watch_dir_enabled" = "0" ] || service_dirs="$service_dirs $watch_dir"
procd_add_restart_mount_trigger $service_dirs
}
service_triggers() {
procd_add_reload_trigger 'transmission'
config_load 'transmission'
config_foreach transmission_mount_triggers 'transmission'
}
|