-
Notifications
You must be signed in to change notification settings - Fork 2
/
box.sh
executable file
·156 lines (154 loc) · 2.83 KB
/
box.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#Get script name
BASEDIR="`dirname $0`"
#Import config data
. $BASEDIR/config.sh
#include function.sh
. $BASEDIR/function.sh
#Check if there is at least one parameter
if [ "$1" == "" ];
then
usage
exit 1
fi
#Check if API Key exist in config.sh
check_api
while [ "$1" != "" ]; do
case $1 in
-f | --file ) shift
if [ "$1" != "" ];
then
filename=$1
else
echo -e "\nError, no file specified for uploading, use -f filename\n"
exit 1
fi
;;
-a | --auth ) auth=1
;;
-l | --list ) #shift
#folder_id=$1
list_folder=1
;;
-u | --upload ) upload_file=1
;;
-h | --help ) usage
exit
;;
--force ) force=1
;;
-d | --directory ) shift
if [ "$1" != "" ];
then
folder_id=$1
else
folder_id=0
fi
;;
-s | --silent ) silent=1
;;
* ) usage
exit 1
esac
shift
done
if [ "$auth" == "1" ];
then
if [ "$TOKEN" != "" ];
then
if [ "$force" == "1" ];
then
if [ "$silent" != 1 ];
then
echo -e "\nForcing new authentification."
fi
get_ticket
display_auth_url
get_token
update_conf
if [ "$silent" != 1 ];
then
echo -e "\nDone, check config.sh\n"
fi
exit 0
else
if [ "$silent" != 1 ];
then
echo -e "\nError, already authorized. Use --force to force new auth.\n"
fi
exit 1
fi
fi
if [ "$silent" != 1 ];
then
echo -e "\nAuthentification started ...\n"
fi
get_ticket
display_auth_url
get_token
update_conf
if [ "$silent" != 1 ];
then
echo -e "Done, check config.sh\n"
fi
fi
if [ "$list_folder" == "1" ];
then
if [ "$folder_id" == "" ];
then
folder_id=0
if [ "$silent" != 1 ];
then
echo -e "\nNo folder ID specified, listing root folder :\n"
fi
get_list
if [ "$silent" != 1 ];
then
echo ""
fi
exit 0
else
if [ "$silent" != 1 ];
then
echo -e "\nListing folder with ID $folder_id :\n"
fi
get_list
if [ "$silent" != 1 ];
then
echo ""
fi
exit 0
fi
exit 0
fi
if [ "$upload_file" == "1" ];
then
if [ "$filename" != "" ];
then
if [ "$folder_id" == "" ];
then
folder_id=0
if [ "$silent" != 1 ];
then
echo -e "\nNo folder ID specified, choosing root folder for uploading file $filename.\n"
fi
upload
echo ""
exit 0
else
if [ "$silent" != 1 ];
then
echo -e "\nUploading file $filename to folder ID $folder_id.\n"
fi
upload
echo ""
exit 0
fi
else
if [ "$silent" != 1 ];
then
echo -e "\nError, no file specified. Use -f filename to specify the file to upload.\n"
fi
exit 1
fi
fi