1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010-2011 OpenWrt.org
10 local p; local v; local s="$1"; shift
12 config_get v "$s" "$p"
16 echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_file
23 append_params_quotes() {
24 local p; local v; local s="$1"; shift
26 config_get v "$s" "$p"
30 echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_file; \
31 echo "\": \""$v"\"," >> $config_file
39 config_get_bool enabled "$1" 'enabled' 0
46 local open_file_limit=0
47 local ulimit_files=$(ulimit -n)
49 section_enabled "$section" || return 1
51 config_get config_dir "$s" 'config_dir' '/var/etc/transmission'
52 config_get user "$s" 'user'
54 config_file="$config_dir/settings.json"
55 [ -d $config_dir ] || {
56 mkdir -m 0755 -p "$config_dir"
58 [ -z "$user" ] || chown -R $user $config_dir
61 echo "{" > $config_file
64 alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
65 alt_speed_time_enabled alt_speed_time_end alt_speed_up blocklist_enabled \
66 cache_size_mb download_queue_enabled download_queue_size \
67 dht_enabled encryption idle_seeding_limit idle_seeding_limit_enabled \
68 incomplete_dir_enabled lazy_bitfield_enabled lpd_enabled message_level \
69 open_file_limit peer_limit_global peer_limit_per_torrent peer_port \
70 peer_port_random_high peer_port_random_low peer_port_random_on_start \
71 peer_socket_tos pex_enabled port_forwarding_enabled preallocation prefetch_enabled \
72 ratio_limit ratio_limit_enabled rename_partial_files rpc_authentication_required \
73 rpc_enabled rpc_port rpc_whitelist_enabled queue_stalled_enabled \
74 queue_stalled_minutes scrape_paused_torrents_enabled script_torrent_done_enabled \
75 seed_queue_enabled seed_queue_size \
76 speed_limit_down speed_limit_down_enabled speed_limit_up \
77 speed_limit_up_enabled start_added_torrents trash_original_torrent_files \
78 umask upload_slots_per_torrent utp_enabled scrape_paused_torrents \
81 append_params_quotes "$s" \
82 blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
83 peer_congestion_algorithm rpc_bind_address rpc_password rpc_url \
84 rpc_username rpc_whitelist script_torrent_done_filename watch_dir
86 echo "\""invalid-key"\": false" >> $config_file
87 echo "}" >> $config_file
89 config_get open_file_limit "$s" 'open_file_limit' 32
90 open_limit_files=$(($open_file_limit + 8))
92 if [ ${open_file_limit} -gt ${ulimit_files} ]; then
93 ulimit -n $open_limit_files
97 service_start /usr/bin/transmission-daemon -g $config_dir
104 section_enabled "$section" || return 1
106 config_get user "$s" 'user'
108 SERVICE_UID="$user" \
109 service_stop /usr/bin/transmission-daemon
113 config_load 'transmission'
114 config_foreach start_instance 'transmission'
118 config_load 'transmission'
119 config_foreach stop_instance 'transmission'