Last active
October 26, 2016 12:59
-
-
Save mulatinho/cf148b96248ad5d1d49e8fd84c982454 to your computer and use it in GitHub Desktop.
upload files to S3 using shell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# amazon s3 upload file code | |
# written by Alexandre Mulatinho < alex @ mulatinho . net > | |
# Wed Oct 26 09:30:54 BRT 2016 | |
# use -> ./s3upload.sh hostAmazon yourBucketName yourFilename | |
[ ! "$3" ] && echo "use: $0 <host> <bucket> <file>" && exit 1 | |
dateNow="`TZ=Africa/Bumako date "+%a, %0e %b %Y %T %z"`" | |
host="$1" | |
fileName="$3" | |
urlFileName="/$2/$fileName" | |
echo list files: | |
ls -l $fileName | |
fileMD5=`openssl dgst -md5 -binary "$fileName" | base64` | |
stringToSign="PUT\n$fileMD5\napplication/octet-stream\n$dateNow\nx-amz-acl:public-read\n$urlFileName" | |
trysignature=`echo -en $stringToSign | openssl sha1 -hmac ${AWS_SECRET_ACCESS_KEY} -binary` | |
signature=`echo -en $stringToSign | openssl sha1 -hmac ${AWS_SECRET_ACCESS_KEY} -binary | base64` | |
authorization="AWS ${AWS_ACCESS_KEY_ID}:${signature}" | |
echo sending ${fileName}... | |
curl -v -L -X PUT -T "$fileName" \ | |
-H "Host: ${host}" \ | |
-H "Date: ${dateNow}" \ | |
-H "x-amz-acl: public-read" \ | |
-H "Content-Type: application/octet-stream" \ | |
-H "Content-MD5: ${fileMD5}" \ | |
-H "Authorization: $authorization" \ | |
https://${host}${urlFileName} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment