aboutsummaryrefslogtreecommitdiff
blob: f68c3f6e51b0a01a937ab4435b38c91d35e75d5e (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
#!/sbin/runscript
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-p2p/transmission/files/transmission-daemon.initd.2,v 1.1 2009/06/20 12:55:37 ssuominen Exp $

# Read options from conf.d file, or set sensible defaults
allowed=${allowed:-127.0.0.1}
blocklist=${blocklist:-no}
watch_dir=${watch_dir:-}
config_dir=${config_dir:-/var/transmission/config}
port=${port:-9091}
auth=${auth:-no}
username=${username:-}
password=${password:-}
download_dir=${download_dir:=/var/transmission/downloads}
peerport=${peerport:-51413}
portmap=${portmap:-no}
peerlimit_global=${peerlimit_global:-240}
peerlimit_torrent=${peerlimit_torrent:-60}
encryption=${encryption:-preferred}
bind_address_ipv4=${bind_address_ipv4:-}
bind_address_ipv6=${bind_address_ipv6:-}
rpc_bind_address=${rpc_bind_address:-}

# Misc options
pidfile=${pidfile:-/var/run/transmission.pid}
logfile=${logfile:-}
runas_user=${runas_user:-}


# Convert settings into stuff that transmission-daemon can grok as arguments
allowed_opt="--allowed ${allowed}"

blocklist_opt="--no-blocklist"
if [ "x${blocklist}" = "xyes" ]; then
	blocklist_opt="--blocklist"
fi

watch_dir_opt="--no-watch-dir"
if [ -n "${watch_dir}" ]; then
	watch_dir_opt="--watch-dir ${watch_dir}"
fi

config_dir_opt="--config-dir ${config_dir}"

port_opt="--port ${port}"

auth_opt="--no-auth"
username_opt=""
password_opt=""
if [ "x${auth}" = "xyes" ]; then
	auth_opt="--auth"
	# Set username and password also
	username_opt="--username ${username}"
	password_opt="--password ${password}"
fi

download_dir_opt="--download-dir ${download_dir}"

peerport_opt="--peerport ${peerport}"

portmap_opt="--no-portmap"
if [ "x${portmap}" = "xyes" ]; then
	portmap_opt="--portmap"
fi

peerlimit_global_opt="--peerlimit-global ${peerlimit_global}"

peerlimit_torrent_opt="--peerlimit-torrent ${peerlimit_torrent}"

case "${encryption}" in
	'required') encryption_opt="--encryption-required" ;;
	'tolerated') encryption_opt="--encryption-tolerated" ;;
	*) encryption_opt="--encryption-preferred" ;;
esac

bind_address_ipv4_opt=""
if [ -n "${bind_address_ipv4}" ]; then
	bind_address_ipv4_opt="--bind-address-ipv4 ${bind_address_ipv4}"
fi

bind_address_ipv6_opt=""
if [ -n "${bind_address_ipv6}" ]; then
	bind_address_ipv6_opt="--bind-address-ipv6 ${bind_address_ipv6}"
fi

rpc_bind_address_opt=""
if [ -n "${rpc_bind_address}" ]; then
	rpc_bind_address_opt="--rpc-bind-address ${rpc_bind_address}"
fi

# Note: works only on systems with sys-apps/openrc
logfile_opt=""
if [ -n "${logfile}" ]; then
	logfile_opt="--stdout ${logfile} --stderr ${logfile}"
fi

# Note: works only on systems with sys-apps/openrc
# This could be done in baselayout-1 with --chuid, but since
#   openrc detection is vague at best (b.g.o #270646), just ignore it.
runas_user_opt=""
if [ -n "${runas_user}" ]; then
	runas_user_opt="--user ${runas_user}"
fi

# Actual init script stuff below this line

opts="start stop"
description="Transmission is a fast, easy and free bittorrent client"
description_start="Start transmission-daemon server and web interface"
description_stop="Stop transmission-daemon server and web interface"

depend() {
	need net
}

start() {
	ebegin "Starting transmission daemon"
	start-stop-daemon --start --quiet --background --make-pidfile \
		--pidfile ${pidfile} ${runas_user_opt} \
		${logfile_opt} --exec \
		/usr/bin/transmission-daemon -- --foreground ${allowed_opt} \
		${blocklist_opt} ${watch_dir_opt} ${config_dir_opt} ${port_opt} \
		${auth_opt} ${username_opt} ${password_opt} ${download_dir_opt} \
		${peerport_opt} ${portmap_opt} ${peerlimit_global_opt} \
		${peerlimit_torrent_opt} ${encryption_opt} \
		${bind_address_ipv4_opt} ${bind_address_ipv6_opt} ${rpc_bind_address_opt}
	eend $?
}

stop() {
	ebegin "Stopping transmission daemon"
	start-stop-daemon --stop --quiet --retry TERM/45/QUIT/15 \
		--pidfile ${pidfile}
	eend $?
}