-
Notifications
You must be signed in to change notification settings - Fork 28
/
rclone
executable file
·103 lines (82 loc) · 2.56 KB
/
rclone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh /etc/rc.common
# Copyright (C) 2019 ElonH <[email protected]>
USE_PROCD=1
START=95
STOP=10
APP=rclone
CONFIGURATION=rclone
_info() {
logger -p daemon.info -t "$APP" "$*"
}
_err() {
logger -p daemon.err -t "$APP" "$*"
}
init_config() {
config_load "${CONFIGURATION}"
# Create rclone dirs
local config_path
local config_dir
local log_path
local log_dir
config_get config_path config config_path
config_get log_path log path
config_dir=${config_path%/*}
[ -d "$config_dir" ] || mkdir -p "$config_dir" 2>/dev/null
[ -f "$config_path" ] || touch "$config_path"
[ -d "/lib/upgrade/keep.d" ] || mkdir -p /lib/upgrade/keep.d/luci-app-rclone 2>/dev/null
echo "$config_path" > /lib/upgrade/keep.d/luci-app-rclone
log_dir=${log_path%/*}
[ -d "$log_dir" ] || mkdir -p "$log_dir" 2>/dev/null && echo /dev/null > "$log_path"
}
start_service() {
init_config
local enabled
local config_path
local addr_type
local port
local username
local password
local proxy_enable
local proxy_addr
local log_path
config_get enabled global enabled
config_get config_path config config_path
config_get addr_type config addr_type
config_get port config port
config_get username config username
config_get password config password
config_get proxy_enable proxy enabled
config_get proxy_addr proxy proxy_addr
config_get log_path log path
if [[ "${addr_type}" == "local" ]]; then
addr="$(uci get network.loopback.ipaddr)"
elif [[ "${addr_type}" == "lan" ]]; then
addr="$(uci get network.lan.ipaddr)"
elif [[ "${addr_type}" == "all" ]]; then
addr=""
fi
[ "$enabled" == "1" ] || { _info "Instance \"rclone\" disabled."; return 1; }
_info "Instance \"rclone\" start."
procd_open_instance
procd_set_param command /usr/bin/$APP rcd -vv
procd_append_param command "--rc-addr=$addr:$port"
procd_append_param command "--rc-user=$username" "--rc-pass=$password"
procd_append_param command "--config=$config_path"
procd_append_param command "--rc-allow-origin=*"
procd_append_param command "--log-file=${log_path}"
if [[ "${proxy_enable}" == "1" ]]; then
procd_set_param env all_proxy="$proxy_addr" https_proxy="$proxy_addr" http_proxy="$proxy_addr"
procd_append_param env ALL_PROXY="$proxy_addr" HTTPS_PROXY="$proxy_addr" HTTP_PROXY="$proxy_addr"
fi
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param file /etc/config/rclone
# procd_set_param pidfile /var/run/rclone.pid
procd_set_param user rclone
procd_set_param group rclone
procd_set_param respawn retry=60
procd_close_instance
}
service_triggers() {
procd_add_reload_trigger "rclone"
}