#!/usr/bin/env bash set -o errexit set -o nounset if (( $# != 1 )); then echo "Usage: $0 " >&2 exit 1 fi INPUT_PATH="$1" BZCLI_PATH="/Applications/Backblaze.app/Contents/MacOS/bzcli" # If Backblaze isn't installed, we can assume this device isn't backed # up with Backblaze and no-op this operation. if [ ! -x "$BZCLI_PATH" ]; then exit 0 fi # Resolve relative paths to absolute paths. if [[ "$INPUT_PATH" = /* ]]; then TARGET_DIR="$INPUT_PATH" else TARGET_DIR="$PWD/$INPUT_PATH" fi # Create a temporary JSON file with the following structure: # # { # "settings": { # "bzdirfilter_add": [ # { # "dir": "/Users/alexwlchan/repos/chives/.venv/", # "whichfiles": "none" # } # ] # } # } # TEMP_JSON=$(mktemp) trap 'rm -f "$TEMP_JSON"' EXIT if ! jq -n \ --arg dir "$TARGET_DIR" \ '{settings: {bzdirfilter_add: [{dir: $dir, whichfiles: "none"}]}}' \ > "$TEMP_JSON"; then echo "Error: Failed to generate temporary JSON configuration." >&2 exit 1 fi echo "Applying Backblaze exclusion for: $TARGET_DIR" if ! "$BZCLI_PATH" configure -j "$TEMP_JSON"; then echo "Error: bzcli configuration failed." >&2 exit 1 fi