blob: edb333630184643d3d7e5f47b96acb8501682f88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/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
|