#!/usr/bin/env bash ### BEFORE USE ### # 1. Create .config/uwupass # 2. Set the following variables in it: # DATABASE (path to keepass db) (REQUIRED) # PGP_KEY (path to your pgp encrypted password file) (REQUIRED) # DMENU (dmenu script to feed options into, will fall back to dmenu) # KEYFILE (if you have a keyfile encrypted db) # YUBIKEY (if you have a yubikey encrypted db) ### # Load configuration script set -euo pipefail config="${XDG_CONFIG_HOME:-$HOME/.config}/uwupass" message() { notify-send -u low "uwupass" "$@" } if [[ -e $config ]]; then source "$config" else message "Configuration file not found; check the source code for more information." exit 1 fi if [[ -z ${DATABASE} || -z ${PGP_KEY} ]]; then message "Required settings not specified; check the source code for more information." exit 1 fi if ! command -v keepassxc-cli; then message "keepassxc-cli not found; please install keepassxc-cli." exit 1 fi if ! command -v gpg; then message "gpg not found; please install gpg." exit 1 fi # Compose the database opening command # needs to be suffixed with entry name dbQuery() { command="keepassxc-cli $*" [[ -e ${KEYFILE:-} ]] && command="$command --key-file $KEYFILE" [[ -e ${YUBIKEY:-} ]] && command="$command --yubikey" command="$command $DATABASE" echo "$command" } # Decrypt the pgp password decryptPass=$(gpg --decrypt "$PGP_KEY") # Send the entries to dmenu query=$(dbQuery ls -R -f) entries=$(echo $decryptPass | $query) entry=$(echo "$entries" | ${DMENU:-dmenu} -p "Select entry") pass=$(echo "$decryptPass" | $(dbQuery show --show-protected --attributes Password) "$entry") # Retrieve the target password echo -n "$pass" | wl-copy --sensitive message "Copied password for $entry." exit # Copy TOTP ~~to clipboard~~ totp=$(echo "$decryptPass" | $(dbQuery show --show-protected --totp) $entry || true) if [[ -n "$totp" ]]; then message "Your TOTP is $totp." fi