-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdropbox.bash
69 lines (62 loc) · 1.23 KB
/
dropbox.bash
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
DB_CURL_OPT="-s"
function db_err {
>&2 echo "$@"
}
function db_token {
if test -z "$DB_TOKEN"
then
db_err "DropBox: No PB token"
return 255
fi
return 0
}
function db_resp_bool {
cat "$1" | sed -n 's/.*"'"$2"'":\([^,{}]*\).*/\1/p'
}
function db_resp {
cat "$1" | sed -n 's/.*"'"$2"'":"\([^"]*\)".*/\1/p'
}
function db_check_msg {
TMP="$1"
test -f $TMP || exit -1
ACTIVE=$(db_resp_bool $TMP active)
if [ "$ACTIVE" == "true" ]
then
DB_LAST=$(db_resp $TMP iden)
else
db_err "Something went wrong"
>&2 cat $TMP
db_err "--------------------"
fi
export DB_LAST
}
function db_file {
db_token || return 255
FILE="$1"
BASE="$(basename $FILE)"
test -z "$FILE" && return 255
test -z "$BASE" && return 255
if ! test -f "$FILE"
then
db_err "File doesn't exist: $FILE"
return 255
fi
shift
if test -z "$1"
then
DBPATH="/$BASE"
else
DBPATH="$1"
fi
TMP=$(mktemp)
curl $DB_CURL_OPT \
--header "Authorization: Bearer $DB_TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"$DBPATH\", \"mode\": \"overwrite\"}" \
--header "Content-Type: application/octet-stream" \
--request POST \
--data-binary "@$FILE" \
https://content.dropboxapi.com/2/files/upload >$TMP 2>&1
# db_check_msg $TMP || exit -1
cat $TMP
rm $TMP
}