You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2010-2012 OpenWrt.org
  3. START=99
  4. LIST_SEP="
  5. "
  6. append_params() {
  7. local p; local v; local s="$1"; shift
  8. for p in $*; do
  9. config_get v "$s" "$p"
  10. IFS="$LIST_SEP"
  11. for v in $v; do
  12. [ -n "$v" ] && (
  13. echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_file
  14. )
  15. done
  16. unset IFS
  17. done
  18. }
  19. append_params_quotes() {
  20. local p; local v; local s="$1"; shift
  21. for p in $*; do
  22. config_get v "$s" "$p"
  23. IFS="$LIST_SEP"
  24. for v in $v; do
  25. [ -n "$v" ] && (
  26. echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_file; \
  27. echo "\": \""$v"\"," >> $config_file
  28. )
  29. done
  30. unset IFS
  31. done
  32. }
  33. section_enabled() {
  34. config_get_bool enabled "$1" 'enabled' 0
  35. [ $enabled -gt 0 ]
  36. }
  37. start_instance() {
  38. local s="$1"
  39. local user
  40. section_enabled "$section" || return 1
  41. config_get config_dir "$s" 'config_dir' '/var/etc/transmission'
  42. config_get user "$s" 'user'
  43. config_file="$config_dir/settings.json"
  44. [ -d $config_dir ] || {
  45. mkdir -m 0755 -p "$config_dir"
  46. touch $config_file
  47. [ -z "$user" ] || chown -R $user $config_dir
  48. }
  49. echo "{" > $config_file
  50. append_params "$s" \
  51. alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
  52. alt_speed_time_enabled alt_speed_time_end alt_speed_up blocklist_enabled \
  53. cache_size_mb download_queue_enabled download_queue_size \
  54. dht_enabled encryption idle_seeding_limit idle_seeding_limit_enabled \
  55. incomplete_dir_enabled lazy_bitfield_enabled lpd_enabled message_level \
  56. peer_limit_global peer_limit_per_torrent peer_port \
  57. peer_port_random_high peer_port_random_low peer_port_random_on_start \
  58. pex_enabled port_forwarding_enabled preallocation prefetch_enabled \
  59. ratio_limit ratio_limit_enabled rename_partial_files rpc_authentication_required \
  60. rpc_enabled rpc_port rpc_whitelist_enabled queue_stalled_enabled \
  61. queue_stalled_minutes scrape_paused_torrents_enabled script_torrent_done_enabled \
  62. seed_queue_enabled seed_queue_size \
  63. speed_limit_down speed_limit_down_enabled speed_limit_up \
  64. speed_limit_up_enabled start_added_torrents trash_original_torrent_files \
  65. umask upload_slots_per_torrent utp_enabled scrape_paused_torrents \
  66. watch_dir_enabled
  67. append_params_quotes "$s" \
  68. blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
  69. peer_congestion_algorithm peer_socket_tos rpc_bind_address rpc_password rpc_url \
  70. rpc_username rpc_whitelist script_torrent_done_filename watch_dir
  71. echo "\""invalid-key"\": false" >> $config_file
  72. echo "}" >> $config_file
  73. SERVICE_UID="$user" \
  74. service_start /usr/bin/transmission-daemon -g $config_dir
  75. }
  76. stop_instance() {
  77. local s="$1"
  78. local user
  79. section_enabled "$section" || return 1
  80. config_get user "$s" 'user'
  81. SERVICE_UID="$user" \
  82. service_stop /usr/bin/transmission-daemon
  83. }
  84. start() {
  85. config_load 'transmission'
  86. config_foreach start_instance 'transmission'
  87. }
  88. stop() {
  89. config_load 'transmission'
  90. config_foreach stop_instance 'transmission'
  91. }