From 546e167bfd2a8aafadb5c56cc5b429e14f3094af Mon Sep 17 00:00:00 2001 From: surtur Date: Sun, 10 May 2020 10:36:39 +0200 Subject: [PATCH] b2 uploader enhancements --- bin/b2-ul_me | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/b2-ul_me b/bin/b2-ul_me index f09ed17..74904d4 100644 --- a/bin/b2-ul_me +++ b/bin/b2-ul_me @@ -2,18 +2,18 @@ echo "** backblaze b2 custom uploader **" -export FILE_TO_UPLOAD=/run/cache/archives/$(ls /run/cache/archives | head -1) -export FILE_TO_UPLOAD=${1} -export MIME_TYPE=${2} -export B2_KEY_ID=${3} -export B2_KEY=${4} -export B2_BUCKET_ID=${5} -export B2_TOKEN=${6} -export SHA1_OF_FILE=$(openssl dgst -sha1 $FILE_TO_UPLOAD | awk '{print $2;}') +FILE_TO_UPLOAD=${1} +MIME_TYPE=${2} +B2_KEY_ID=${3} +B2_KEY=${4} +SHA1_OF_FILE=$(openssl dgst -sha1 $FILE_TO_UPLOAD | awk '{print $2;}') -export apiUrl=$(curl -s 'https://api.backblazeb2.com/b2api/v2/b2_authorize_account' -u "$B2_KEY_ID:$B2_KEY" | python -c "import sys, json; print (json.load(sys.stdin)['apiUrl'])") +b2_authorize_account=$(curl -s 'https://api.backblazeb2.com/b2api/v2/b2_authorize_account' -u "$B2_KEY_ID:$B2_KEY" +apiUrl=$(echo $b2_authorize_account | python -c "import sys, json; print (json.load(sys.stdin)['apiUrl'])") +B2_TOKEN=$(echo $b2_authorize_account | python -c "import sys, json; print (json.load(sys.stdin)['authorizationToken'])") +B2_BUCKET_ID=$(echo $b2_authorize_account | python -c "import sys, json; print (json.load(sys.stdin)['bucketId'])") -export UPLOAD_URL=$(curl -s -H 'Authorization:$B2_TOKEN' -d '{"bucketId":"$B2_BUCKET_ID"}' $apiUrl/b2api/v2/b2_get_upload_url | python -c "import sys, json; print (json.load(sys.stdin)['uploadUrl'])") +UPLOAD_URL=$(curl -s -H "Authorization:$B2_TOKEN" -d '{"bucketId":"$B2_BUCKET_ID"}' $apiUrl/b2api/v2/b2_get_upload_url | python -c "import sys, json; print (json.load(sys.stdin)['uploadUrl'])") curl -s -H "Authorization:$B2_TOKEN" -H "X-Bz-File-Name:$FILE_TO_UPLOAD" -H "Content-Type:$MIME_TYPE" -H "X-Bz-Content-Sha1:$SHA1_OF_FILE" -H "X-Bz-Info-Author:${DRONE_COMMIT_AUTHOR}" --data-binary "@$FILE_TO_UPLOAD" $UPLOAD_URL