@ -4,18 +4,17 @@
START=99
START=99
USE_PROCD=1
USE_PROCD=1
LIST_SEP="
LIST_SEP="
"
"
append_params() {
append_params() {
local p; local v; local s="$1"; shift
local p; local v; local s="$1"; shift
for p in $* ; do
for p in "$@" ; do
config_get v "$s" "$p"
config_get v "$s" "$p"
IFS="$LIST_SEP"
IFS="$LIST_SEP"
for v in $v; do
for v in $v; do
[ -n "$v" ] && (
[ -n "$v" ] && (
echo "\"" $p" \": " $v" ," | sed -e 's|_|-|g' >> $config_file
echo "\"$p\": $v," | sed -e 's|_|-|g' >> $config_file
)
)
done
done
unset IFS
unset IFS
@ -24,13 +23,13 @@ append_params() {
append_params_quotes() {
append_params_quotes() {
local p; local v; local s="$1"; shift
local p; local v; local s="$1"; shift
for p in $* ; do
for p in "$@" ; do
config_get v "$s" "$p"
config_get v "$s" "$p"
IFS="$LIST_SEP"
IFS="$LIST_SEP"
for v in $v; do
for v in $v; do
[ -n "$v" ] && (
[ -n "$v" ] && (
echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_file; \
echo "\": \"" $v" \"," >> $config_file
echo -n "\"$p " | sed -e 's|/|\\/|g;s|_|-|g' >> $config_file; \
echo "\": \"$v\"," >> $config_file
)
)
done
done
unset IFS
unset IFS
@ -38,7 +37,7 @@ append_params_quotes() {
}
}
section_enabled() {
section_enabled() {
config_get_bool enabled "$1" ' enabled' 0
config_get_bool enabled "$1" enabled 0
[ $enabled -gt 0 ]
[ $enabled -gt 0 ]
}
}
@ -49,7 +48,7 @@ transmission() {
local user
local user
local download_dir config_dir
local download_dir config_dir
local mem_percentage
local mem_percentage
local config_overwrite nice ionice_flags
local nice
local cmdline
local cmdline
section_enabled "$section" || return 1
section_enabled "$section" || return 1
@ -58,10 +57,7 @@ transmission() {
config_get user "$cfg" 'user'
config_get user "$cfg" 'user'
config_get download_dir "$cfg" 'download_dir' '/var/etc/transmission'
config_get download_dir "$cfg" 'download_dir' '/var/etc/transmission'
config_get mem_percentage "$cfg" 'mem_percentage' '50'
config_get mem_percentage "$cfg" 'mem_percentage' '50'
config_get config_overwrite "$cfg" config_overwrite 1
config_get nice "$cfg" nice 0
config_get nice "$cfg" nice 0
config_get ionice_flags "$cfg" ionice_flags ''
which ionice > /dev/null || ionice_flags=''
local MEM=$(sed -ne 's!^MemTotal:[[:space:]]*\([0-9]*\) kB$!\1!p' /proc/meminfo)
local MEM=$(sed -ne 's!^MemTotal:[[:space:]]*\([0-9]*\) kB$!\1!p' /proc/meminfo)
if test "$MEM" -gt 1;then
if test "$MEM" -gt 1;then
@ -70,52 +66,51 @@ transmission() {
config_file="$config_dir/settings.json"
config_file="$config_dir/settings.json"
[ -d $config_dir ] || {
[ -d $config_dir ] || {
mkdir -m 0755 -p "$config_dir"
mkdir -p $config_dir
chmod 0755 $config_dir
touch $config_file
touch $config_file
[ -z "$user" ] || chown -R $user $config_dir
[ -z "$user" ] || chown -R " $user:$user" $config_dir
}
}
[ "$config_overwrite" == 0 ] || {
echo "{" > $config_file
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_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 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_whitelist script_torrent_done_filename watch_dir
echo "\""invalid-key"\": false" >> $config_file
echo "}" >> $config_file
}
cmdline="/usr/bin/transmission-daemon -g $config_dir -f"
[ "$ionice_flags" ] && cmdline="ionice $ionice_flags $cmdline"
echo "{" > $config_file
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_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 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_whitelist script_torrent_done_filename watch_dir
echo "\"invalid-key\": false" >> $config_file
echo "}" >> $config_file
cmdline="transmission-daemon -g $config_dir -f"
procd_open_instance
procd_open_instance
procd_set_param command $cmdline
procd_set_param command $cmdline
procd_set_param env CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
procd_set_param env TR_CURL_SSL_VERIFY=1
procd_set_param user $user
procd_set_param group $user
procd_set_param nice $nice
procd_set_param respawn retry=60
procd_set_param respawn retry=60
procd_set_param user "$user"
procd_set_param group "$user"
procd_set_param nice "$nice"
if test -z "$USE";then
if test -z $USE; then
procd_set_param limits core="0 0"
procd_set_param limits core="0 0"
else
else
procd_set_param limits core="0 0" as="$USE $USE"
procd_set_param limits core="0 0" as="$USE $USE"