Created
July 30, 2021 07:19
-
-
Save timdream/b5086479f9222490b9e79a8a57257d15 to your computer and use it in GitHub Desktop.
B2 key for `rclone sync`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# B2 key for `rclone sync`. Can upload/list/shadow delete but not real deletion. | |
# Adopted from https://github.com/sequentialread/password-manager#hosting-it-yourself | |
BACKBLAZE_KEY_ID="" | |
BACKBLAZE_SECRET_KEY="" | |
BUCKET_NAME="" | |
KEY_NAME="" | |
AUTH_JSON="$(curl -sS -u "$BACKBLAZE_KEY_ID:$BACKBLAZE_SECRET_KEY" \ | |
https://api.backblazeb2.com/b2api/v1/b2_authorize_account)" | |
AUTHORIZATION_TOKEN="$(echo "$AUTH_JSON" | jq -r .authorizationToken)" | |
ACCOUNT_ID="$(echo "$AUTH_JSON" | jq -r .accountId)" | |
API_URL="$(echo "$AUTH_JSON" | jq -r .apiUrl)" | |
BUCKET_ID="$(curl -sS -H "Authorization: $AUTHORIZATION_TOKEN" \ | |
"$API_URL/b2api/v2/b2_list_buckets?accountId=$ACCOUNT_ID&bucketName=$BUCKET_NAME" |\ | |
jq -r .buckets[0].bucketId)" | |
curl -X POST -H "Authorization: $AUTHORIZATION_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
"$API_URL/b2api/v2/b2_create_key" \ | |
-d '{"accountId": "'"$ACCOUNT_ID"'", "capabilities": ["listBuckets", "listFiles", "readBuckets", "readFiles", "writeFiles"], "keyName": "'"$KEY_NAME"'", "bucketId": "'"$BUCKET_ID"'"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment