-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdriveadmin.sh
executable file
·97 lines (86 loc) · 1.93 KB
/
gdriveadmin.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /bin/bash
# script: gdriveadmin.sh
# add and or remove an old version of a google drive file
# Stéphane Plaisance - VIB-NC June-06-2018 v1.0
# visit our Git: https://github.com/Nucleomics-VIB
# correct typos 2018/08/18; v1.1.1
# add retry 2019/04/02; v1.2
# requirements:
# gdrive https://github.com/prasmussen/gdrive
# gdrive about => connection established
#version="1.1.2, 2019_01_23"
version="1.2, 2019_04_02"
# custom functions to retry and fail after 5 retries
function fail {
echo $1 >&2
exit 1
}
function retry {
local n=1
local max=5
local delay=15
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}
# list all files on drive
echo "# the current files on your drive are:"
retry gdrive list
echo
# ask which file to rollout
read -p "Paste one of the UUID for processing " uuid
echo
echo "# ${uuid} has the following revisions:"
retry gdrive revision list ${uuid}
echo
# add new version
read -p "Do you have a new revision to upload (y/n)? " answer
echo
case ${answer:0:1} in
y|Y )
read -p "path to the new file: " path
retry gdrive update ${uuid} ${path}
echo
retry gdrive revision list ${uuid}
;;
* )
echo Ok
;;
esac
echo
# remove old version
read -p "Do you wish to delete a revision (y/n)? " answer
echo
case ${answer:0:1} in
y|Y )
read -p "uuid of the version to delete: " deluuid
retry gdrive revision delete ${uuid} ${deluuid}
echo
retry gdrive revision list ${uuid}
;;
* )
echo Ok
;;
esac
echo
# add a new file
read -p "Do you wish to add a file (y/n)? " answer
echo
case ${answer:0:1} in
y|Y )
read -p "path to the new file: " path
retry gdrive upload ${path}
echo
;;
* )
echo Ok
;;
esac