From ad480f6362215a59ce1fa3de6bca1767afc2b613 Mon Sep 17 00:00:00 2001 From: Russ Long Date: Thu, 2 Jul 2020 10:29:54 -0400 Subject: [PATCH] Add bwunlock.sh --- README.md | 18 ++++++++++++++++++ bwunlock.sh | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 bwunlock.sh diff --git a/README.md b/README.md index 634d7b4..325d242 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # bitwarden-helper-scripts +These are just some helper scripts I put together to help when using the official Bitwarden CLI. + +## bwunlock.sh + +Used to unlock a bitwarden vault and set the appropriate environment variables to keep the vault unlocked. + +### Usage Instructions + +1. Copy the file to a location of your choosing, I use `/home/$USER/scripts` + +2. Set the following alias in your `~/.bashrc`: +```alias bw-unlock="source /home/$USER/scripts/bwunlock.sh"``` + +3. Source your bashrc or close and re-open your shell + +4. Run `bw-unlock` and imput your Bitwarden Master Password when prompted + +5. Run any Bitwarden command to ensure the script worked, like `bw list items` diff --git a/bwunlock.sh b/bwunlock.sh new file mode 100755 index 0000000..87db41f --- /dev/null +++ b/bwunlock.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# To unlock and set session vars for bitwarden vault +unset BWPASSWORD +prompt="Enter Bitwarden Master Password: " +while IFS= read -p "$prompt" -r -s -n 1 char +do + if [[ $char == $'\0' ]] + then + break + fi + prompt='*' + BWPASSWORD+="$char" +done +echo + +export BW_SESSION="$(bw unlock $BWPASSWORD --raw)" +echo "Bitwarden vault unlocked, session variable set" +echo +unset BWPASSWORD