Bw : Add bash wrappers.

This commit is contained in:
Dmitry Voronin 2024-10-04 13:50:06 +03:00
parent b394a57bf4
commit e59d82784e
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
3 changed files with 62 additions and 4 deletions

View file

@ -13,8 +13,8 @@
} }
# Unlock encrypted disk file. # Unlock encrypted disk file.
# Usage: unlock <FILE> <DIR> # Usage: funlock <FILE> <DIR>
function unlock() { function funlock() {
if [[ "''${UID}" != 0 ]]; then if [[ "''${UID}" != 0 ]]; then
_error "Must be root." _error "Must be root."
return 2 return 2
@ -24,7 +24,7 @@
local dir="''${2}" local dir="''${2}"
if [[ "''${dir}" = "" ]]; then if [[ "''${dir}" = "" ]]; then
help unlock help funlock
return 2 return 2
fi fi

View file

@ -1,7 +1,7 @@
{ ... }: { { ... }: {
text = '' text = ''
# Check smartcard pin. # Check smartcard pin.
function pincheck() { function scunlock() {
pkill keyboxd &> /dev/null pkill keyboxd &> /dev/null
# pkill gpg-agent &> /dev/null # pkill gpg-agent &> /dev/null
echo verify | gpg --card-edit --no-tty --command-fd=0 echo verify | gpg --card-edit --no-tty --command-fd=0

View file

@ -0,0 +1,58 @@
{ ... }: {
text = ''
# Setup the pw manager.
function pwsetup() {
bw config server 'https://pass.voronind.com'
bw login
}
# Unlock the vault for current shell.
function pwunlock() {
if [ -z ''${BW_SESSION} ]; then
export BW_SESSION=$(bw unlock --raw)
fi
}
# Lock the vault for current shell.
function pwlock() {
bw lock
unset BW_SESSION
}
# List all password entries.
function pwlist() {
bw list items | jq -r '.[] | .name'
}
# Get entry data.
# Usage: pwget <NAME>
function pwget() {
local IFS=$'\n'
local entry="''${*}"
if [[ "''${entry}" = "" ]]; then
help pwget
return 2
fi
local ids=($(_pwids "''${entry}"))
for id in "''${ids[@]}"; do
local result=($(bw get item "''${id}" | jq -r '(.name), (.login | .username, .password, .uris[].uri)'))
local name="''${result[0]}"
local login="''${result[1]}"
local password="''${result[2]}"
local urls=(''${result[@]:3})
printf "\nName: %s\n" "''${name}"
printf "Login: %s\n" "''${login}"
printf "Password: %s\n" "''${password}"
printf "Url: %s\n" "''${urls[@]}"
done
}
function _pwids() {
bw list items | jq -r '.[] | select(.name | match(".*'$*'.*")) | .id'
}
'';
}