Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ The files are automatically given a timestamp suffix to avoid naming conflicts.
3. Upload a file

```sh
shells3 image.png
shells3 image.png somedoc.txt
```
Upload a file in a specific folder with [specific permissions](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl)
```sh
shells3 -p folder/in/bucket/ -a private image.png somedoc.txt
```

## Compatibility and dependencies
Expand Down
43 changes: 33 additions & 10 deletions shells3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ elif [ -f "$HOME/$config_file" ]; then
source "$HOME/$config_file"
fi

function show_help {
echo -e "Usage: shells3 [OPTION]... [FILE]..."
echo -e "Send FILEs to the configured S3 bucket\n"

echo -e "\tOPTIONS:"
echo -e "\t-p\tpath[default: '/'], where you want the file to be saved in the bucket."
echo -e "\t-a\tacl[default: 'public-read'], ACL for all the files. CF: https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl.\n"
echo "More info: https://github.com/matiaskorhonen/shells3"
}

OPTIND=1 # Reset in case getopts has been used previously in the shell.
aws_path="/"
acl_string="public-read"

while getopts "h?a:p:" opt; do
case "$opt" in
h|\?)
show_help
exit 1
;;
a) acl_string=$OPTARG
;;
p) aws_path=$OPTARG
;;

esac
done

shift $((OPTIND-1))

[ "$1" = "--" ] && shift
# SHELLS3_BUCKET=""
# SHELLS3_AWS_ACCESS_KEY_ID=""
# SHELLS3_AWS_SECRET_ACCESS_KEY=""
Expand Down Expand Up @@ -53,9 +84,8 @@ function putS3
content_type="application/octet-stream"
fi

aws_path="/"
date=$(date +"%a, %d %b %Y %T %z")
acl="x-amz-acl:public-read"
acl="x-amz-acl:$acl_string"
cache_control="public, max-age=315360000"

string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$aws_path$filename"
Expand All @@ -79,14 +109,7 @@ function putS3
}

if [[ $# -eq 0 || "$1" == "--help" || "$1" == "-h" ]] ; then
cat <<EOS
ShellS3

Usage: shells3 [file ...]

More info: https://github.com/matiaskorhonen/shells3
EOS

show_help
exit 1
fi

Expand Down