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.

78 lines
1.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2014-2016 nanpuyue <nanpuyue@gmail.com>
  3. START=99
  4. SERVICE_WRITE_PID=1
  5. SERVICE_DAEMONIZE=1
  6. append_params() {
  7. local p; local v; local s="$1"; shift
  8. for p in $*; do
  9. config_get v "$s" "$p"
  10. [ -n "$v" ] && (
  11. p=$(echo "$p" | sed -e 's|_|-|g');
  12. echo "$p=$v" >> $config_file
  13. )
  14. done
  15. }
  16. section_enabled() {
  17. local result
  18. config_get_bool result "$1" 'enabled' 0
  19. [ $result -eq 1 ]
  20. }
  21. option_disabled() {
  22. local result
  23. config_get_bool result "$1" "$2" 1
  24. [ $result -eq 0 ]
  25. }
  26. start_instance() {
  27. local s="$1"
  28. local user
  29. section_enabled "$s" || return 1
  30. config_get config_dir "$s" 'config_dir' '/var/etc/aria2'
  31. config_get user "$s" 'user'
  32. config_file="$config_dir/aria2.conf"
  33. session_file="$config_dir/aria2.session"
  34. dht_file="$config_dir/dht.dat"
  35. [ -d "$config_dir" ] || {
  36. mkdir -m 0755 -p "$config_dir"
  37. touch "$config_file"
  38. [ -z "$user" ] || chown -R $user $config_dir
  39. }
  40. touch "$session_file"
  41. echo -e "enable-rpc=true\nrpc-allow-origin-all=true\nrpc-listen-all=true\nquiet=true" > $config_file
  42. echo -e "continue=true\ninput-file=$session_file\nsave-session=$session_file" >> $config_file
  43. option_disabled "$s" 'enable_dht' || echo "dht-file-path=$dht_file" >> $config_file
  44. append_params "$s" \
  45. file_allocation bt_enable_lpd enable_dht rpc_user rpc_passwd rpc_listen_port dir bt_tracker disk_cache \
  46. max_overall_download_limit max_overall_upload_limit max_download_limit max_upload_limit max_concurrent_downloads \
  47. max_connection_per_server min_split_size split save_session_interval follow_torrent listen_port bt_max_peers \
  48. peer_id_prefix user_agent rpc_secret
  49. config_list_foreach "$s" extra_settings append_extrasettings
  50. SERVICE_UID="$user" \
  51. service_start /usr/bin/aria2c --conf-path="$config_file"
  52. }
  53. append_extrasettings() {
  54. echo "$1" >> $config_file
  55. }
  56. start() {
  57. config_load 'aria2'
  58. config_foreach start_instance 'aria2'
  59. }
  60. stop() {
  61. service_stop /usr/bin/aria2c
  62. }