From bd8d23b6fde2aea625a25bd4c85c7a0aea92d28a Mon Sep 17 00:00:00 2001 From: Alexander Dumanskiy Date: Thu, 18 May 2023 19:26:32 +0200 Subject: [PATCH] Added an optional environment variable S3_SERVER support --- README.md | 4 +++- s3simple | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6031cea..e46582c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ possible, but it is not implemented here. 1. Download the [s3simple](s3simple) script somewhere. 2. Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` and optionally -`AWS_SESSION_TOKEN` environment variables. +`AWS_SESSION_TOKEN` and `S3_SERVER` environment variables. 3. Run `s3simple` with a method, an `s3://` url and, optionally, a local filename. @@ -32,6 +32,8 @@ For example: export AWS_SECRET_ACCESS_KEY=zzzz # optionally provide a temporary session token export AWS_SESSION_TOKEN=wwww... + # optionally provide an S3 server address + export S3_SERVER=http://my-s3.example.com:9000 # get a file ./s3simple get s3://mybucket/myfile.txt myfile.txt diff --git a/s3simple b/s3simple index b468860..b13646e 100755 --- a/s3simple +++ b/s3simple @@ -72,7 +72,12 @@ s3simple() { local bucket="${path%%/*}" local key="${path#*/}" - curl "${args[@]}" -s -f -H "Date: ${date}" -H "Authorization: ${authorization}" "https://${bucket}.s3.amazonaws.com/${key}" + local url="https://${bucket}.s3.amazonaws.com" + if [ -n "${S3_SERVER-}" ]; then + url="${S3_SERVER}/${bucket}" + fi + + curl "${args[@]}" -s -f -H "Date: ${date}" -H "Authorization: ${authorization}" "${url}/${key}" } s3simple "$@"