Skip to content

Instantly share code, notes, and snippets.

@kassi
Created June 24, 2025 07:52
Show Gist options
  • Save kassi/d9761a14d9b377aecc81bb228158c472 to your computer and use it in GitHub Desktop.
Save kassi/d9761a14d9b377aecc81bb228158c472 to your computer and use it in GitHub Desktop.
1password@beta homebrew alternative installation/update script
#!/bin/bash
set -e
CLI_URL="https://app-updates.agilebits.com/product_history/CLI2"
# Fetch the latest version of 1Password CLI (on stable or beta channel)
get_latest_cli_version() {
conditional_path="/beta/"
if [ "$1" == "non_beta" ]; then
conditional_path="!/beta/"
fi
# This long command parses the HTML page at "CLI_URL" and finds the latest CLI version
# based on the release channel we're looking for (stable or beta).
#
# The ideal call (i.e. 'curl https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/Y -s | jq -r .version')
# doesn't retrieve the latest CLI version on a channel basis.
# If the latest release is stable and we want the latest beta, this command will return the stable still.
OP_CLI_VERSION="$(curl -s $CLI_URL | gawk -v RS='<h3>|</h3>' 'NR % 2 == 0 {gsub(/[[:blank:]]+/, ""); gsub(/<span[^>]*>|<\/span>|[\r\n]+/, ""); gsub(/&nbsp;.*$/, ""); if (!'"$1"' && '"$conditional_path"'){print; '"$1"'=1;}}')"
}
get_current_cli_version() {
# This command retrieves the currently installed version of the 1Password CLI.
if command -v op &>/dev/null; then
op --version
else
echo "0.0.0"
fi
}
get_latest_cli_version beta
if [ "$OP_CLI_VERSION" == "$(get_current_cli_version)" ]; then
echo "Latest 1Password CLI version is already installed: $OP_CLI_VERSION"
exit 0
fi
echo "Installing 1Password CLI version $OP_CLI_VERSION"
curl -sSfLo /tmp/op.pkg "https://cache.agilebits.com/dist/1P/op2/pkg/v${OP_CLI_VERSION}/op_apple_universal_v${OP_CLI_VERSION}.pkg"
sudo installer -pkg /tmp/op.pkg -target / || {
echo "Failed to install 1Password CLI version $OP_CLI_VERSION"
rm -f /tmp/op.pkg
exit 1
}
rm -rf /tmp/op.pkg
@kassi
Copy link
Author

kassi commented Jun 24, 2025

Why

Because Homebrew installation of the beta version doesn't always install the latest beta version due to their interpretation of "latest version" (see Homebrew/homebrew-cask#207869 (comment) and Homebrew/homebrew-cask#214051 (comment)).
And because I want the beta version, at least as long as the terraform plugin isn't merged into stable.

What

The main content of the script is taken from https://github.com/1Password/install-cli-action/blob/main/install-cli.sh 1password cli github action.

How

As part of a personal system_update script (which I run frequently) I run this command after some brew upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment