-
Notifications
You must be signed in to change notification settings - Fork 0
/
seene-upload.sh
executable file
·99 lines (84 loc) · 2.94 KB
/
seene-upload.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
#!/bin/bash
username="$1"
password="$2"
if [ -z "$seene_token" ]
then
echo "Contact author to learn how to get your authorisation in"
exit 1
fi
if [ -z "$username" -o -z "$password" ]
then
echo "usage: $0 username password"
exit 1
fi
if ! [ -f poster.jpg ]
then
echo 'Current folder has no poster.jpg, please create it (or get from examples)'
exit 1
fi
if ! [ -f scene.oemodel ]
then
echo 'Current folder has no scene.oemodel, please create it (or get from examples)'
exit 1
fi
caption='#synthetic (Uploaded by https://github.com/neopaf/seene-uploader by @PAF)'
captured_at=$(LANG= date -u +"%Y-%m-%dT%H:%M:%SZ")
dateHeaderValue=$(LANG= date +"%a, %d %b %Y %T %z")
function api_request {
method="$1"; shift
url="$1"; shift
curl -# \
"$url" \
-X "$method" \
-H "Authorization: Seene api=$seene_token,user=$user_token" \
-H 'Accept: application/vnd.seene.co; version=3,application/json' \
"$@"
}
function amazon_upload {
dir="$1"
file="$2"
content_type="$3"
resource="/$bucket_name/$dir/$file"
stringToSign="PUT\n\n${content_type}\n${dateHeaderValue}\nx-amz-acl:public-read\nx-amz-security-token:$session_token\n${resource}"
signature=`echo -en "$stringToSign" | openssl sha1 -hmac "$secret_access_key" -binary | base64`
curl -# -X PUT -T "${file}" \
-H "Host: $bucket_name.s3.amazonaws.com" \
-H "Authorization: AWS ${access_key_id}:${signature}" \
-H "x-amz-acl: public-read" \
-H "x-amz-security-token: $session_token" \
-H "Date: ${dateHeaderValue}" \
-H "Content-Type: $content_type" \
"https://$bucket_name.s3.amazonaws.com/$dir/$file"
}
user_token='(null)'
api_request POST https://oecamera.herokuapp.com/api/users/authenticate \
--form username="$username" \
--form password="$password" > auth.json
user_token=$(cat auth.json | jq -r .api_token)
request_id=`uuidgen|tr "[A-Z]" "[a-z]"`
echo 'creating entry'
api_request POST https://oecamera.herokuapp.com/api/scenes \
--form caption="$caption" \
--form captured_at="$captured_at" \
--form filter_code=none \
--form flash_level=0 \
--form identifier="$scene_id" \
--form orientation=0 \
--form shared=0 \
--form storage_version=3 > entry.json
access_key_id=$(cat entry.json|jq -r .meta.access_key_id)
bucket_name=$(cat entry.json|jq -r .meta.bucket_name)
model_dir=$(cat entry.json|jq -r .meta.model_dir)
poster_dir=$(cat entry.json|jq -r .meta.poster_dir)
session_token=$(cat entry.json|jq -r .meta.session_token)
secret_access_key=$(cat entry.json|jq -r .meta.secret_access_key)
echo 'uploading model'
amazon_upload "$model_dir" scene.oemodel application/octet-stream
echo 'uploading image'
amazon_upload "$poster_dir" poster.jpg image/jpeg
#not to depend on above code, while debugging I comment it out often
scene_id=$(cat entry.json|jq -r .scene.identifier)
echo 'finalizing'
api_request PATCH https://oecamera.herokuapp.com/api/scenes/$scene_id \
--form finalize=1 > exit.json
cat exit.json | jq -r '[.short_url, .state, "(was uploaded but is private now)"]|join(" ")'