Debian Codegraph @

utils/keepassxc-keychain

raw
1 #!/usr/bin/env bash
2 # fetch KeePass database passwords from keychain
3
4 ### change the path to suit your installation or set KDBX_SEARCH before calling ###
5 : ${KDBX_SEARCH:=~/.KeePass/*.kdbx}
6
7 PROG=$(basename "$0")
8 KeePassXC=$(ls -f {/usr/local,/opt/homebrew,/Applications}/KeePassXC.app/Contents/MacOS/KeePassXC 2>/dev/null | head -1)
9
10 daemon_main() {
11 declare -A DBs
12 for DBPATH in $KDBX_SEARCH; do
13 DBs[$(python -c "import os; print os.path.realpath('$DBPATH')")]=$(security find-generic-password -a $USER -s "${DBPATH##*/}" -w)
14 done
15
16 # launch keepassxc
17 IFS=$'\n\n\n'
18 $KeePassXC --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
19 }
20
21 if [[ $1 == '-d' ]]; then
22 exec >&~/tmp/$PROG.log
23 set -vx
24 daemon_main
25 else
26 cd /
27 daemon_main </dev/null >&/dev/null &
28 disown
29 fi