keepassxc-keychain 776 B

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