Skip to content

Instantly share code, notes, and snippets.

@aaronmehar
Created February 9, 2018 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronmehar/c2e3e2a9a11fb716af8881fd47db60c4 to your computer and use it in GitHub Desktop.
Save aaronmehar/c2e3e2a9a11fb716af8881fd47db60c4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
show_help() {
echo "Usage: s3get OPTIONS"
echo "-r region"
echo "-b bucket"
echo "-f filename"
exit 0
}
if [ $# -eq 0 ]
then
show_help
exit 1
fi
while getopts r:b:f:a:s:h option
do
case "${option}" in
r) REGION=${OPTARG};;
b) BUCKET=${OPTARG};;
f) TSFILE=${OPTARG};;
h) show_help
esac
done
echo -n 'Enter AWS ACCESS KEY: '
read -s ACCESS;echo
echo -n 'Enter AWS SECRET KEY: '
read -s SECRET;echo
if [ -z $REGION ] || [ -z $BUCKET ] || [ -z $TSFILE ] || [ -z $ACCESS ] || [ -z $SECRET ]; then
show_help
fi
if ! hash openssl 2>/dev/null; then fail "openssl not installed"; fi
if ! hash curl 2>/dev/null; then fail "curl not installed"; fi
contentType="text/html; charset=UTF-8"
date="$(date -u +'%a, %d %b %Y %H:%M:%S GMT')"
resource="/${BUCKET}/${TSFILE}"
string="GET\n\n${contentType}\n\nx-amz-date:${date}\n${resource}"
signature=$(echo -en ${string} | openssl sha1 -hmac "${SECRET}" -binary | base64)
curl -H "x-amz-date: ${date}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${ACCESS}:${signature}" \
"https://s3-${REGION}.amazonaws.com${resource}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment