Skip to content

Instantly share code, notes, and snippets.

@timdream
Created July 30, 2021 07:19
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 timdream/b5086479f9222490b9e79a8a57257d15 to your computer and use it in GitHub Desktop.
Save timdream/b5086479f9222490b9e79a8a57257d15 to your computer and use it in GitHub Desktop.
B2 key for `rclone sync`
#!/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