-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-cloud
More file actions
executable file
·92 lines (76 loc) · 2.08 KB
/
sync-cloud
File metadata and controls
executable file
·92 lines (76 loc) · 2.08 KB
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
#! /usr/bin/env bash
BASEDIR=$(dirname $0); cd $BASEDIR
. ./env-vars
_require_var CLOUD_HOME
_require_var CLOUD_REMOTE_SOURCES
__usage_page() {
echo "Synchronize local files from cloud providers."
echo ;
echo "Usage: $(basename $0) [<option>]*"
echo "Option:"
echo " -f: Pull data from cloud"
echo " -p: Push data to cloud"
echo " -s: Apply Rclone sync"
echo " -t: Test run"
echo " -h: Displays this help message"
exit 0
}
_cloud_home=$( _trim_trailing_separator "$CLOUD_HOME" )
_sync_flag=0
_push_flag=0
_options="-P"
while getopts "fpsth" opt; do
case "$opt" in
f)
_sync_op="Pull"
;;
p)
_sync_op="Push"
;;
s)
_sync_flag=1
;;
t)
_options="--dry-run"
;;
h)
__usage_page
;;
esac
done
_sync_ops=( "Pull" "Push" )
if [ -z "$_sync_op" ]; then
echo "Select an operation:"
for _idx in "${!_sync_ops[@]}"; do
_op="${_sync_ops[$_idx]}"
echo "$((_idx+1))) $_op"
done
read -p "operation-index> " _op_index
if [ -z "$_op_index" ]; then
echo "Invalid operation index"
_stopped
fi
_sync_op="${_sync_ops[$((_op_index-1))]}"
fi
if [ "$_sync_op" = "Push" ]; then
_push_flag=1
fi
for _src in "${CLOUD_REMOTE_SOURCES[@]}"; do
_config=$( cut -d : -f 1 <<< "$_src" )
_path=$( cut -d : -f 2 <<< "$_src" )
_path=$( _trim_separator "$_path" )
if [ $_push_flag -eq 1 ]; then
echo "Pushing changes to '$_config:$_path'"
rclone copy "$_options" "$_cloud_home/$_config/$_path" $_config:$_path
if [ $_sync_flag -eq 1 ]; then
rclone sync "$_options" "$_cloud_home/$_config/$_path" $_config:$_path
fi
else
echo "Pulling changes from '$_config:$_path'"
rclone copy "$_options" $_config:$_path "$_cloud_home/$_config/$_path"
if [ $_sync_flag -eq 1 ]; then
rclone sync "$_options" $_config:$_path "$_cloud_home/$_config/$_path"
fi
fi
done
_completed