forked from cyrillef/forge.commandline-curl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forge
executable file
·138 lines (134 loc) · 4.48 KB
/
forge
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
#
# Copyright (c) 2016 Autodesk, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# by Cyrille Fauvel
# Autodesk Forge Partner Development
# Septemeber 2016
#
#!/bin/bash
ROOT="`dirname \"$0\"`" # Relative
export ROOT="`( cd \"$ROOT\" && pwd )`" # Absolutized and normalized
[[ -f ./scripts/_tools ]] && source ./scripts/_tools
#[[ -f ./scripts/_config ]] && source ./scripts/_config
function usage () {
echo '
forge command [arg]
2legged
- get an application access token (2 legged)
buckets [-s [-a <startAt>] [-l <limit>] [-r <region>]]
- list local buckets
-s / --server : list buckets on the server
-a / --startAt <startAt> : where to start in the list [string, default: none]
-l / --limit <limit> : how many to return [integer, default: 10]
-r / --region <region> : US or EMEA [string, default: US]
bucket [<Name>]
- set or get the current bucket
bucketCreate <Name> [<Type>]
- create a new bucket,
default Type is transient, values can be
transient/temporary/persistent
-r / --region <region> : US or EMEA [string, default: US]
bucketCheck [<Name>]
- check bucket validity, outputs the expiration
date/time for this bucket
if no parameter use the current bucket
bucketItems [<Name>] [-a <startAt>] [-l <limit>]
- list items in a given bucket
if no parameter use the current bucket
-a / --startAt <startAt> : where to start in the list [string, default: none]
-l / --limit <limit> : how many to return [integer, default: 10]
bucketDelete [<Name>]
- delete a given bucket
if no parameter delete the current bucket
upload <File>
- upload a file in the current bucket
resumable <File> <Pieces>
- upload a file in multiple pieces (i.e. resumables)
download <FileKey> <OutputFile>
- download the file from OSS
objectDetails <FileKey>
- file information
translate <FileKey>
- translate the file for viewing
translateProgress <FileKey>
- file translation progress
manifest <FileKey>
- urn manifest
metadata <FileKey>
- urn metadata
thumbnail <FileKey>
- get thumbnail
deleteManifest <FileKey>
- delete the manifest and all its translated output files (derivatives).
deleteFile <FileKey>
- delete the source file from the bucket
html <FileKey> <OutputFile>
- generate default html page
'
}
case "$1" in
"help" | "usage" | "-h" | "--help" | "")
usage
exit
;;
"bucket")
if [ "$2" == "" ]; then
echo -n "Current bucket is: "
[[ -f $ROOT/data/bucket ]] && cat $ROOT/data/bucket
[[ ! -f $ROOT/data/bucket ]] && echo "<not defined>"
exit
fi
bucket=$(bucketName $2)
if [ "$bucket" != "" ]; then
echo $bucket > $ROOT/data/bucket
else
echo "Error: missing bucket name or invalid name!"
exit
fi
;;
"buckets")
if [ "$2" != "-s" ] && [ "$2" != "--server" ]; then
regex="(.*)\.bucket\.json"
ll=$(ls $ROOT/data/*.bucket.json)
for l in $ll; do
lb=$(basename $l)
[[ $lb =~ $regex ]]
name="${BASH_REMATCH[1]}"
echo $name
done
exit
fi
cmd=$1
shift
shift # -s / -- server
$ROOT/scripts/${cmd} "$@"
;;
# "2legged")
# "bucketCreate") "bucketCheck") "bucketItems") "bucketDelete")
# "upload") "resumable") "objectDetails")
# "translate") "translateProgress") "manifest") "metadata") "thumbnail")
# "deleteManifest") "deleteMetadata") "html")
*)
cmd=$1
shift
$ROOT/scripts/${cmd} "$@"
;;
esac