|
@@ -0,0 +1,82 @@
|
|
|
+
|
|
|
+
|
|
|
+host="oss-cn-shanghai.aliyuncs.com"
|
|
|
+inner_host="oss-cn-shanghai-internal.aliyuncs.com"
|
|
|
+bucket="third-part-tool"
|
|
|
+Id="LTAI4FdrT3HsfdR5edBVN7ws"
|
|
|
+Key="yroxrpm46DzTyzHrLBZzS3MRNIicP6"
|
|
|
+
|
|
|
+method=$1
|
|
|
+
|
|
|
+source=$2
|
|
|
+
|
|
|
+dest=$3
|
|
|
+
|
|
|
+osshost=$bucket.$inner_host
|
|
|
+
|
|
|
+
|
|
|
+if test -z "$method"
|
|
|
+then
|
|
|
+ method=GET
|
|
|
+fi
|
|
|
+
|
|
|
+if [ "${method}"x = "get"x ] || [ "${method}"x = "GET"x ]
|
|
|
+then
|
|
|
+ method=GET
|
|
|
+elif [ "${method}"x = "put"x ] || [ "${method}"x = "PUT"x ]
|
|
|
+then
|
|
|
+ method=PUT
|
|
|
+else
|
|
|
+ method=GET
|
|
|
+fi
|
|
|
+
|
|
|
+
|
|
|
+if test -z "$dest"
|
|
|
+then
|
|
|
+ dest=$source
|
|
|
+fi
|
|
|
+
|
|
|
+echo "method:"$method
|
|
|
+echo "source:"$source
|
|
|
+echo "dest:"$dest
|
|
|
+
|
|
|
+
|
|
|
+if test -z "$method" || test -z "$source" || test -z "$dest"
|
|
|
+then
|
|
|
+ echo $0 put localfile objectname
|
|
|
+ echo $0 get objectname localfile
|
|
|
+ exit -1
|
|
|
+fi
|
|
|
+
|
|
|
+if [ "${method}"x = "PUT"x ]
|
|
|
+then
|
|
|
+ resource="/${bucket}/${dest}"
|
|
|
+ contentType=`file -ib ${source} |awk -F ";" '{print $1}'`
|
|
|
+ dateValue="`TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'`"
|
|
|
+ stringToSign="${method}\n\n${contentType}\n${dateValue}\n${resource}"
|
|
|
+ signature=`echo -en $stringToSign | openssl sha1 -hmac ${Key} -binary | base64`
|
|
|
+ echo $stringToSign
|
|
|
+ echo $signature
|
|
|
+ url=http://${osshost}/${dest}
|
|
|
+ echo "upload ${source} to ${url}"
|
|
|
+ curl -i -q -X PUT -T "${source}" \
|
|
|
+ -H "Host: ${osshost}" \
|
|
|
+ -H "Date: ${dateValue}" \
|
|
|
+ -H "Content-Type: ${contentType}" \
|
|
|
+ -H "Authorization: OSS ${Id}:${signature}" \
|
|
|
+ ${url}
|
|
|
+else
|
|
|
+ resource="/${bucket}/${source}"
|
|
|
+ contentType=""
|
|
|
+ dateValue="`TZ=GMT date +'%a, %d %b %Y %H:%M:%S GMT'`"
|
|
|
+ stringToSign="${method}\n\n${contentType}\n${dateValue}\n${resource}"
|
|
|
+ signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${Key} -binary | base64`
|
|
|
+ url=http://${osshost}/${source}
|
|
|
+ echo "download ${url} to ${dest}"
|
|
|
+ curl --create-dirs \
|
|
|
+ -H "Host: ${osshost}" \
|
|
|
+ -H "Date: ${dateValue}" \
|
|
|
+ -H "Content-Type: ${contentType}" \
|
|
|
+ -H "Authorization: OSS ${Id}:${signature}" \
|
|
|
+ ${url} -o ${dest}
|
|
|
+fi
|