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.

101 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2019 Elon Huang <elonhhuang@gmail.com>
  3. USE_PROCD=1
  4. START=95
  5. STOP=10
  6. APP="rclone"
  7. CONFIGURATION="rclone"
  8. _info() {
  9. logger -p daemon.info -t "$APP" "$*"
  10. }
  11. _err() {
  12. logger -p daemon.err -t "$APP" "$*"
  13. }
  14. start_service() {
  15. config_load "${CONFIGURATION}"
  16. local enabled
  17. config_get_bool enabled global enabled
  18. if [ "$enabled" -ne "1" ]; then
  19. _info 'Instance "rclone" is disabled.'
  20. return 1
  21. else
  22. _info 'Instance "rclone" is starting.'
  23. fi
  24. local config_path log_path
  25. local addr addr_type port
  26. local username password
  27. local proxy_enable proxy_addr
  28. config_get config_path config config_path
  29. config_get log_path log path
  30. config_get addr_type config addr_type
  31. config_get port config port
  32. config_get username config username
  33. config_get password config password
  34. config_get_bool proxy_enable proxy enabled
  35. config_get proxy_addr proxy proxy_addr
  36. if [ "${addr_type}" = "local" ]; then
  37. addr="$(uci get network.loopback.ipaddr | cut -d' ' -f1)"
  38. elif [ "${addr_type}" = "lan" ]; then
  39. addr="$(uci get network.lan.ipaddr | cut -d' ' -f1)"
  40. else
  41. addr=""
  42. fi
  43. addr="${addr%/*}"
  44. local config_dir="${config_path%/*}"
  45. [ -d "$config_dir" ] || mkdir -p "$config_dir"
  46. touch "${config_path}"
  47. chown rclone "${config_path}"
  48. [ -d "/lib/upgrade/keep.d" ] || mkdir -p "/lib/upgrade/keep.d/"
  49. echo "$config_path" > "/lib/upgrade/keep.d/luci-app-rclone"
  50. local log_dir="${log_path%/*}"
  51. [ -d "$log_dir" ] || mkdir -p "$log_dir"
  52. chown -R rclone:rclone "$log_dir"
  53. procd_open_instance
  54. procd_set_param command /usr/bin/$APP rcd -vv
  55. procd_append_param command "--rc-addr=$addr:$port"
  56. procd_append_param command "--rc-user=$username" "--rc-pass=$password"
  57. procd_append_param command "--config=$config_path"
  58. procd_append_param command "--rc-allow-origin=*"
  59. procd_append_param command "--log-file=${log_path}"
  60. if [ "${proxy_enable}" -eq "1" ]; then
  61. procd_set_param env all_proxy="$proxy_addr" https_proxy="$proxy_addr" http_proxy="$proxy_addr"
  62. procd_append_param env ALL_PROXY="$proxy_addr" HTTPS_PROXY="$proxy_addr" HTTP_PROXY="$proxy_addr"
  63. fi
  64. procd_set_param stdout 1
  65. procd_set_param stderr 1
  66. # procd_set_param pidfile /var/run/rclone.pid
  67. procd_set_param respawn
  68. procd_set_param user rclone
  69. procd_set_param group rclone
  70. procd_close_instance
  71. }
  72. reload_service() {
  73. stop
  74. start
  75. }
  76. service_triggers() {
  77. procd_add_reload_trigger "rclone"
  78. }