2010-01-30 13:52:09 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
|
|
|
|
START=99
|
|
|
|
BIN=/usr/bin/transmission-daemon
|
|
|
|
SSD=start-stop-daemon
|
|
|
|
|
|
|
|
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" ] && (
|
2010-02-16 16:59:07 +00:00
|
|
|
echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_dir/settings.json
|
2010-01-30 13:52:09 +00:00
|
|
|
)
|
|
|
|
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" ] && (
|
2010-11-23 16:02:15 +00:00
|
|
|
echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_dir/settings.json; \
|
|
|
|
echo "\": \""$v"\"," >> $config_dir/settings.json
|
2010-01-30 13:52:09 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
start_service() {
|
|
|
|
local s="$1"
|
2010-10-04 17:47:40 +00:00
|
|
|
local enabled=0
|
2010-07-04 20:58:53 +00:00
|
|
|
local run_as_usr='root'
|
2011-03-10 05:58:02 +00:00
|
|
|
local open_file_limit=0
|
2011-11-13 06:45:40 +00:00
|
|
|
local ulimit_files=$(ulimit -n)
|
2010-01-30 13:52:09 +00:00
|
|
|
|
|
|
|
# disabled?
|
2010-10-04 17:47:40 +00:00
|
|
|
config_get_bool enabled "$s" enabled 0
|
2011-09-30 18:35:20 +00:00
|
|
|
[ "$enabled" = 0 ] && return 0
|
2010-05-25 19:53:25 +00:00
|
|
|
config_get config_dir "$s" config_dir '/tmp/transmission'
|
2010-01-30 13:52:09 +00:00
|
|
|
mkdir -p "$config_dir"
|
2010-10-04 17:47:40 +00:00
|
|
|
config_get run_as_usr "$s" run_daemon_as_user 'root'
|
2010-01-30 13:52:09 +00:00
|
|
|
|
|
|
|
echo "{" > $config_dir/settings.json
|
|
|
|
|
|
|
|
append_params "$s" \
|
|
|
|
alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
|
2010-10-04 17:47:40 +00:00
|
|
|
alt_speed_time_enabled alt_speed_time_end alt_speed_up blocklist_enabled \
|
2011-09-21 15:19:21 +00:00
|
|
|
cache_size_mb download_queue_enabled download_queue_size \
|
|
|
|
dht_enabled encryption idle_seeding_limit idle_seeding_limit_enabled \
|
2010-05-25 19:53:25 +00:00
|
|
|
incomplete_dir_enabled lazy_bitfield_enabled lpd_enabled message_level \
|
2010-01-30 13:52:09 +00:00
|
|
|
open_file_limit peer_limit_global peer_limit_per_torrent peer_port \
|
|
|
|
peer_port_random_high peer_port_random_low peer_port_random_on_start \
|
2011-02-06 15:41:24 +00:00
|
|
|
peer_socket_tos pex_enabled port_forwarding_enabled preallocation prefetch_enabled \
|
2010-11-14 18:42:54 +00:00
|
|
|
ratio_limit ratio_limit_enabled rename_partial_files rpc_authentication_required \
|
2011-09-21 15:19:21 +00:00
|
|
|
rpc_enabled rpc_port rpc_whitelist_enabled queue_stalled_enabled \
|
2011-09-22 18:57:44 +00:00
|
|
|
queue_stalled_minutes scrape_paused_torrents_enabled script_torrent_done_enabled \
|
2011-09-21 15:19:21 +00:00
|
|
|
seed_queue_enabled seed_queue_size \
|
2010-05-25 19:53:25 +00:00
|
|
|
speed_limit_down speed_limit_down_enabled speed_limit_up \
|
|
|
|
speed_limit_up_enabled start_added_torrents trash_original_torrent_files \
|
2011-05-27 18:55:37 +00:00
|
|
|
umask upload_slots_per_torrent utp_enabled scrape_paused_torrents \
|
|
|
|
watch_dir_enabled
|
2010-01-30 13:52:09 +00:00
|
|
|
|
|
|
|
append_params_quotes "$s" \
|
2010-11-14 18:42:54 +00:00
|
|
|
blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
|
2011-02-14 17:41:06 +00:00
|
|
|
peer_congestion_algorithm rpc_bind_address rpc_password rpc_url \
|
2010-05-25 19:53:25 +00:00
|
|
|
rpc_username rpc_whitelist script_torrent_done_filename watch_dir
|
2010-01-30 13:52:09 +00:00
|
|
|
|
2010-02-16 16:59:07 +00:00
|
|
|
echo "\""invalid-key"\": false" >> $config_dir/settings.json
|
2010-01-30 13:52:09 +00:00
|
|
|
echo "}" >> $config_dir/settings.json
|
2011-02-06 19:13:35 +00:00
|
|
|
|
|
|
|
chown -R $run_as_usr $config_dir
|
|
|
|
|
2011-05-17 05:14:39 +00:00
|
|
|
config_get open_file_limit "$s" open_file_limit 32
|
2011-11-13 06:45:40 +00:00
|
|
|
open_limit_files=$(($open_file_limit + 8))
|
2011-03-10 05:58:02 +00:00
|
|
|
|
|
|
|
if [ ${open_file_limit} -gt ${ulimit_files} ]; then
|
|
|
|
ulimit -n $open_limit_files
|
|
|
|
fi
|
|
|
|
|
2010-07-04 20:58:53 +00:00
|
|
|
eval "$SSD -c $run_as_usr -q -b -x $BIN -S -- -g $config_dir"
|
2010-01-30 13:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
config_load transmission
|
|
|
|
config_foreach start_service transmission
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2011-02-14 17:41:06 +00:00
|
|
|
service_kill $(basename $BIN)
|
2010-01-30 13:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
|
|
|
stop; sleep 5; start
|
|
|
|
}
|