Skip to content

Commit

Permalink
Add script to download and install Backblaze CLI tool (#1748)
Browse files Browse the repository at this point in the history
Related tiny-pilot/tinypilot-pro#1231
Related tiny-pilot/tinypilot-pro#1229

While working on tiny-pilot/tinypilot-pro#1246,
we needed to install the Backblaze CLI tool yet again. This PR moves the
download and installation of `b2` to a dedicated script.

Notes:
1. We've also updated the CircleCI image to the latest version because
[it comes pre-installed with the `wget`
command](https://codeapprove.com/pr/tiny-pilot/tinypilot-pro/1246#thread-b6949a01-6558-4619-a0ff-47ddb4dc9597).

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1748"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
  • Loading branch information
jdeanwallace authored Mar 8, 2024
1 parent 7b36179 commit 8266bdd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
16 changes: 4 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ jobs:
command: ./bundler/verify-bundle
upload_bundle:
docker:
- image: cimg/base:2020.01
- image: cimg/base:2024.02
environment:
UPLOAD_PREFIX: community
steps:
- checkout
- attach_workspace:
at: ./
- run:
Expand All @@ -237,17 +238,8 @@ jobs:
name: Create LATEST file
command: cd dist && ls tinypilot*.tgz | tee LATEST
- run:
name: Download Backblaze CLI tool
command: |
sudo apt-get update && sudo apt-get install -y wget
wget https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v3.4.0/b2-linux --output-document=./b2
chmod +x ./b2
./b2 version
- run:
name: Authorize Backblaze CLI tool
command: |
set -u
./b2 authorize-account "${BACKBLAZE_KEY_ID}" "${BACKBLAZE_KEY}"
name: Setup Backblaze CLI tool
command: ./bundler/setup-b2-linux
- run:
name: Upload bundle to Backblaze
command: |
Expand Down
40 changes: 40 additions & 0 deletions bundler/setup-b2-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# Setup and configure the Backblaze CLI tool for a Linux based system.
#
# This includes the download, installation, and account authorization.

# Exit script on first failure.
set -e

# Determine if there are any account credentials available.
if [[ -n "${BACKBLAZE_KEY_ID}" ]] && [[ -n "${BACKBLAZE_KEY}" ]]; then
readonly HAS_CREDENTIALS='true'
else
readonly HAS_CREDENTIALS='false'
fi

# Exit on unset variable.
set -u

# Download and install the Backblaze CLI tool, if it doesn't already exist.
if [[ ! -f ./b2 ]]; then
readonly VERSION='3.4.0'
wget \
"https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v${VERSION}/b2-linux" \
--output-document ./b2 \
--no-verbose
chmod +x ./b2
fi

# Print current version.
./b2 version

# Authorize the Backblaze account, if account credentials are available.
if "${HAS_CREDENTIALS}"; then
./b2 authorize-account "${BACKBLAZE_KEY_ID}" "${BACKBLAZE_KEY}"
else
echo 'No Backblaze account credentials were found.'
echo 'Manually authorize your account using the following command:'
echo ' ./b2 authorize-account'
fi

0 comments on commit 8266bdd

Please sign in to comment.