forked from rangle/augury
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3-upload.sh
executable file
·53 lines (40 loc) · 1.38 KB
/
s3-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
#!/bin/bash -e
#
# Push the latest build to batarangle s3 bucket
echo "Start"
# bucket name
bucket=batarangle.io
dateValue=$(date -u +'%Y%m%dT%H%M%SZ')
# filename generated using circleci
file="augury-$CIRCLE_BUILD_NUM.crx"
resource="/${bucket}/${file}"
contentType="application/x-compressed-tar"
# create signed token
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
# fetch aws credentials from env variables
s3Key=$AWS_ACCESS_KEY_ID
s3Secret=$AWS_SECRET_ACCESS_KEY
# create hmac signature
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
# curl request to put the file
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
http://${bucket}.s3.amazonaws.com/${file}
file="download.html"
resource="/${bucket}/${file}"
contentType="text/html"
# create signed token
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
# create hmac signature
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
# curl request to put the file
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
http://${bucket}.s3.amazonaws.com/${file}
echo "Finish"