Skip to content

Instantly share code, notes, and snippets.

@ghosthamlet
Forked from chrismdp/s3.sh
Last active August 29, 2015 14:23

Revisions

  1. Chris Parsons revised this gist May 1, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions s3.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    # You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
    # This is how I upload my new Sol Trader builds (http://soltrader.net)
    # Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash

    S3KEY="my aws key"
    S3SECRET="my aws secret" # pass these in
  2. Chris Parsons revised this gist May 1, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions s3.sh
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,11 @@ function putS3
    file=$2
    aws_path=$3
    bucket='my-aws-bucket'
    date=`date +"%a, %d %b %Y %T %z"`
    date=$(date +"%a, %d %b %Y %T %z")
    acl="x-amz-acl:public-read"
    content_type='application/x-compressed-tar'
    string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$aws_path$file"
    signature=`echo -en "${string}" | openssl sha1 -hmac ${S3SECRET} -binary | base64`
    signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
    curl -X PUT -T "$path/$file" \
    -H "Host: $bucket.s3.amazonaws.com" \
    -H "Date: $date" \
    @@ -24,6 +24,6 @@ function putS3
    "https://$bucket.s3.amazonaws.com$aws_path$file"
    }

    for file in `ls "$path"`; do
    putS3 "$path" "$file" "/path/on/s3/to/files/"
    for file in "$path"/*; do
    putS3 "$path" "${file##*/}" "/path/on/s3/to/files/"
    done
  3. Chris Parsons created this gist May 1, 2015.
    29 changes: 29 additions & 0 deletions s3.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
    # This is how I upload my new Sol Trader builds (http://soltrader.net)

    S3KEY="my aws key"
    S3SECRET="my aws secret" # pass these in

    function putS3
    {
    path=$1
    file=$2
    aws_path=$3
    bucket='my-aws-bucket'
    date=`date +"%a, %d %b %Y %T %z"`
    acl="x-amz-acl:public-read"
    content_type='application/x-compressed-tar'
    string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$aws_path$file"
    signature=`echo -en "${string}" | openssl sha1 -hmac ${S3SECRET} -binary | base64`
    curl -X PUT -T "$path/$file" \
    -H "Host: $bucket.s3.amazonaws.com" \
    -H "Date: $date" \
    -H "Content-Type: $content_type" \
    -H "$acl" \
    -H "Authorization: AWS ${S3KEY}:$signature" \
    "https://$bucket.s3.amazonaws.com$aws_path$file"
    }

    for file in `ls "$path"`; do
    putS3 "$path" "$file" "/path/on/s3/to/files/"
    done