2019-04-25 10:37:13 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# fetch KeePass database passwords from keychain
|
|
|
|
|
|
|
|
### change the path to suit your installation or set KDBX_SEARCH before calling ###
|
|
|
|
: ${KDBX_SEARCH:=~/.KeePass/*.kdbx}
|
|
|
|
|
2021-09-21 00:17:46 -04:00
|
|
|
PROG=$(basename "$0")
|
2022-10-17 16:21:50 -04:00
|
|
|
KeePassXC=$(ls -f {/usr/local,/opt/homebrew,/Applications}/KeePassXC.app/Contents/MacOS/KeePassXC 2>/dev/null | head -1)
|
2019-04-25 10:37:13 -04:00
|
|
|
|
2021-09-21 00:17:46 -04:00
|
|
|
daemon_main() {
|
2019-04-25 10:37:13 -04:00
|
|
|
declare -A DBs
|
|
|
|
for DBPATH in $KDBX_SEARCH; do
|
|
|
|
DBs[$(python -c "import os; print os.path.realpath('$DBPATH')")]=$(security find-generic-password -a $USER -s "${DBPATH##*/}" -w)
|
|
|
|
done
|
|
|
|
|
|
|
|
# launch keepassxc
|
|
|
|
IFS=$'\n\n\n'
|
|
|
|
$KeePassXC --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
|
|
|
|
}
|
|
|
|
|
2021-09-21 00:17:46 -04:00
|
|
|
if [[ $1 == '-d' ]]; then
|
2019-04-25 10:37:13 -04:00
|
|
|
exec >&~/tmp/$PROG.log
|
|
|
|
set -vx
|
|
|
|
daemon_main
|
|
|
|
else
|
|
|
|
cd /
|
|
|
|
daemon_main </dev/null >&/dev/null &
|
|
|
|
disown
|
|
|
|
fi
|