-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.sh
executable file
·73 lines (58 loc) · 1.82 KB
/
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
#!/bin/bash
host="$1"
bucket="$2"
id="$3"
key="$4"
version="$5"
osshost=$bucket.$host
echo $osshost
# check input parameters
if [ -z "$host" ]; then
echo "invalid host parameter, exit"
exit 1
elif [ -z "$bucket" ]; then
echo "invalid bucket parameter, exit"
exit 1
elif [ -z "$id" ]; then
echo "invalid id parameter, exit"
exit 1
elif [ -z "$key" ]; then
echo "invalid key parameter, exit"
exit 1
elif [ -z "$version" ]; then
echo "invalid version parameter, exit"
exit 1
fi
name="datakit-operator"
filename="datakit-operator.yaml"
source="datakit-operator.yaml"
sourceWithVersion="${name}-${version}.yaml"
dest="${name}/${source}"
destV="${name}/${sourceWithVersion}"
dateValue="`TZ=GMT env LANG=en_US.UTF-8 date +'%a, %d %b %Y %H:%M:%S GMT'`"
# 1 upload no version file
resource="/${bucket}/${dest}"
contentType=`file -ib ${filename} | awk -F ";" '{print $3}'`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
signature=`echo -en $stringToSign | openssl sha1 -hmac ${key} -binary | base64`
url=http://${osshost}/${dest}
echo "upload ${filename} to ${url}"
curl -i -q -X PUT -T "${filename}" \
-H "Host: ${osshost}" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: OSS ${id}:${signature}" \
${url}
# 2 upload has version file
resource="/${bucket}/${destV}"
contentType=`file -ib ${filename} | awk -F ";" '{print $3}'`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
signature=`echo -en $stringToSign | openssl sha1 -hmac ${key} -binary | base64`
url=http://${osshost}/${destV}
echo "upload ${filename} to ${url}"
curl -i -q -X PUT -T "${filename}" \
-H "Host: ${osshost}" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: OSS ${id}:${signature}" \
${url}