#!/usr/bin/env bash set -eu declare -r prefix_path="${HOME}/.local" declare -r temp_dir="$(mktemp -d /tmp/bitwarden-cli--XXXXXXXXX)" declare platform="" if [[ $OSTYPE = darwin* ]]; then platform="macos" elif [[ $OSTYPE = linux* ]]; then platform="linux" fi move() { local -r src="$1" local -r dest="$2" local -r dest_dir="$(dirname "$dest")" if [ ! -d "${dest_dir}" ]; then mkdir -p "${dest_dir}" fi mv "${src}" "${dest}" } cd "${temp_dir}" echo "Downloading archive..." if command -v curl >/dev/null 2>&1; then curl --progress-bar --continue-at - --output bw.zip -L "https://vault.bitwarden.com/download/?app=cli&platform=${platform}" elif command -v wget >/dev/null 2>&1; then wget -q --show-progress "https://vault.bitwarden.com/download/?app=cli&platform=${platform}" -O bw.zip fi echo "Extracting archive..." unzip -o -q bw.zip -d . echo "Setting up: bw" chmod u+x ./bw move ./bw "${prefix_path}/bin/bw" sudo ln -nsf ${prefix_path}/bin/bw "/usr/local/bin/bw" echo "Cleaning up..." rm -rf "${temp_dir}" echo "Done!"