-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdrive
executable file
·116 lines (94 loc) · 2.57 KB
/
gdrive
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
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# use with: gdrive push/pull to copy files
# gdrive push/pull sync to synchronize (be careful)
# gdrive push/pull check to check differences
#
local=/home/vport/Chem/doutorado/projects
remote=Drive:/Chem/doutorado/projects
#
# The script will sync either the current folder or all drive.
# If the current folder is a subfolder of the drive, the current
# folder will be sync. Otherwise, the complete drive will be sync.
#
# Default flags
#
flags="-v --update"
#
# Check if directory is a Drive subfolder
#
current_dir=`pwd`"/"
echo "Current dir: $current_dir"
#
# File containing base files to ignore
#
ignore_base=`dirname $0`"/GdriveIgnoreBase.txt"
echo "Ignoring files listed in: $ignore_base"
if [[ "$current_dir" == "$local"* ]] ; then
echo "Current dir is a drive subfolder"
len_local=${#local}
len_current=${#current_dir}
target=$remote${current_dir:$len_local:$len_current}
current_local=$current_dir
current_remote=$target
else
current_local=$local
current_remote=$remote
echo "Current dir is NOT a $remote subfolder. Quitting."
exit
fi
#
# Ignore files listed in .gdriveignore files of all subfolders
#
ignore_files=`find "$current_dir" -name .gdriveignore`
igTMP=`pwd`/.gdriveignoreTMP
echo "# $ignore_base" > "$igTMP"
cat $ignore_base >> "$igTMP"
echo "# This file:" >> "$igTMP"
echo ".gdriveignoreTMP" >> "$igTMP"
if [[ $ignore_files ]]; then
echo "Found .gdriveignore files."
for file in "$ignore_files" ; do
echo "# $file" >> "$igTMP"
dir=${file#"$current_dir"}
dir=${dir%".gdriveignore"}
list=`cat $file`
for str in "$list" ; do
n=`echo -n "$str" | wc -m`
if [[ $n -ne 0 ]]; then
echo "$dir$str" >> "$igTMP"
fi
done
done
else
echo "No .gdriveignore files found"
fi
gdrive_ignore="$igTMP"
echo "Excluding files on $gdrive_ignore from sync "
flags="$flags --exclude-from \"$gdrive_ignore\" "
# Push or pull
if [[ "$1" == "push" ]] ; then
type="copy"
source="$current_local"
destination="$current_remote"
elif [[ "$1" == "pull" ]] ; then
type="copy"
source="$current_remote"
destination="$current_local"
else
echo "ERROR: First argument must be 'push', 'pull'"
exit
fi
# Sync, check
if [[ "$2" == "sync" ]] ; then
type="sync"
elif [[ "$2" == "check" ]] ; then
type="check"
elif [[ "$2" > " " ]] ; then
echo "ERROR: Second argument, if any, must be 'sync', 'check'"
exit
fi
echo "RUN: $type \"$source\" to \"$destination\""
run="rclone $type $flags \"$source\" \"$destination\""
echo "Command: $run"
eval $run