Skip to content

Instantly share code, notes, and snippets.

@Torstein-Eide
Last active March 2, 2025 16:39
Show Gist options
  • Save Torstein-Eide/d291288a83eac00b3430cf58ca0e4702 to your computer and use it in GitHub Desktop.
Save Torstein-Eide/d291288a83eac00b3430cf58ca0e4702 to your computer and use it in GitHub Desktop.
install-bitwarden-CLI for linux, used with chezmoi
#!/bin/sh
# Torstein Eide
# Install Bitwarden CLI
# Exit immediately if Bitwarden CLI (bw) is already in $PATH
test_if_installed() {
type bw >/dev/null 2>&1
}
test_if_installed && { exit 0 ; }
Linux() {
if "$(uname -m)" != "x86_64"; then
echo "Unsupported architecture. Exiting."
exit 1
fi
echo "Detected Linux and x86_64 architecture. Installing Bitwarden CLI..."
DOWNLOAD_URL="https://bitwarden.com/download/?app=cli&platform=linux"
TEMP_FILE="/tmp/bw-linux.zip"
INSTALL_PATH="/bin/bw"
# check if dependencies are installed
dependencies=("unzip" "wget")
for dependency in "${dependencies[@]}"; do
if ! command -v "$dependency" >/dev/null 2>&1; then
echo "$dependency is not installed. Please install it and try again."
exit 2
fi
done
echo "Downloading Bitwarden CLI from $DOWNLOAD_URL"
wget -O "$TEMP_FILE" "$DOWNLOAD_URL" || { echo "Failed to download Bitwarden CLI."; exit 10; }
echo "Unzipping $TEMP_FILE"
sudo unzip -o "$TEMP_FILE" || { echo "Failed to unzip $TEMP_FILE."; exit 11; }
echo "Moving bw to $INSTALL_PATH"
sudo mv bw "$INSTALL_PATH" || { echo "Failed to move bw to $INSTALL_PATH."; exit 12; }
echo "Setting execute permissions on $INSTALL_PATH"
sudo chmod +x "$INSTALL_PATH" || { echo "Failed to set permissions on $INSTALL_PATH."; exit 13; }
test_if_installed
echo "Bitwarden CLI successfully installed at $INSTALL_PATH"
}
echo "Bitwarden CLI not found. Proceeding with installation."
case "$(uname -s)" in
Linux)
Linux
;;
*)
echo "Unsupported OS. Exiting."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment