-
Notifications
You must be signed in to change notification settings - Fork 16
/
rclone.sh
executable file
·80 lines (68 loc) · 2.62 KB
/
rclone.sh
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
#!/usr/bin/env bash
# Get the env variables so crond has them
# Create the environment file for crond
printenv | sed 's/^\([a-zA-Z0-9_]*\)=\(.*\)$/export \1="\2"/g' | grep -E "^export RCLONE" > /cron/rclone.env
source /cron/rclone.env
# Possibly convert docker secrets marked variables.
#source /env_secrets.sh
function check (){
# Send the payload to the API
if [[ -z $RCLONE_CROND_HEALTHCHECK_URL ]]; then
echo "INFO: A health check has not been set. Not using health check services"
else
echo "OK: sending message to Healthcheck API..."
POST=$(curl -s -S "${RCLONE_CROND_HEALTHCHECK_URL}");
# Check if the message posted to the API. It should return "ok". Anything other than "ok" indicates an issue
if test "${POST}" != OK; then echo "ERROR: The check to the API failed (${POST})" && return 1; else echo "OK: Message successfully sent to the health check"; fi
fi
}
function rclone_copy () {
(
flock -n 200 || exit 1
sync_command="rclone copy ${RCLONE_CROND_SOURCE_PATH} ${RCLONE_CROND_DESTINATION_PATH}"
if [ "${RCLONE_SYNC_COMMAND}" ]; then
sync_command="${RCLONE_SYNC_COMMAND}"
else
if [[ -z "${RCLONE_CROND_SOURCE_PATH}" ]] || [[ -z "${RCLONE_CROND_DESTINATION_PATH}" ]]; then
echo "Error: A RCLONE PATH environment variable was not set or passed to the container. Please review your RCLONE source/destination paths."
exit 1
fi
fi
echo "Executing => ${sync_command}"
eval "${sync_command}" || send
) 200>/run/rclone.lock
}
function rclone_move () {
(
flock -n 200 || exit 1
sync_command="rclone move ${RCLONE_CROND_SOURCE_PATH} ${RCLONE_CROND_DESTINATION_PATH}"
if [ "${RCLONE_SYNC_COMMAND}" ]; then
sync_command="${RCLONE_SYNC_COMMAND}"
else
if [[ -z "${RCLONE_CROND_SOURCE_PATH}" ]] || [[ -z "${RCLONE_CROND_DESTINATION_PATH}" ]]; then
echo "Error: A RCLONE PATH environment variable was not set or passed to the container. Please review your RCLONE source/destination paths."
exit 1
fi
fi
echo "Executing => ${sync_command}"
eval "${sync_command}" || send
) 200>/run/rclone.lock
}
function foldersize {
if [[ -z "${RCLONE_CROND_SOURCE_PATH}" ]] || [[ -z "${RCLONE_CROND_SOURCE_SIZE}" ]]; then
echo "INFO: A local folder path and/or size has not been set. Not using folder monitor"
else
SIZE=$(/usr/bin/du -s ${RCLONE_CROND_SOURCE_PATH} | /usr/bin/awk '{print $1}')
MBSIZE=$((SIZE / 1024))
echo "${RCLONE_CROND_SOURCE_PATH} is $MBSIZE MB"
if [[ ${MBSIZE} -gt $(( ${RCLONE_CROND_SOURCE_SIZE} )) ]]; then
rclone_move
fi
fi
}
function run() {
check "$@"
rclone_copy
foldersize
}
"$@"