2016-10-24 20:17:48 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-10-25 12:18:23 -04:00
|
|
|
### change the path to suit your installation or set KDBX_SEARCH before calling ###
|
|
|
|
: ${KDBX_SEARCH:=~/.KeePass/*.kdbx}
|
|
|
|
|
2016-10-24 20:17:48 -04:00
|
|
|
PROG="$(basename $0)"
|
|
|
|
|
|
|
|
function daemon_main {
|
|
|
|
# open kdewallet
|
|
|
|
handle=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.open kdewallet 0 "$PROG")
|
|
|
|
while [[ true != $(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.isOpen kdewallet) ]]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
# fetch KeePass database passwords from kdewallet
|
|
|
|
declare -A DBs
|
2016-10-25 12:18:23 -04:00
|
|
|
for DBPATH in $KDBX_SEARCH; do
|
|
|
|
[[ -L "$DBPATH" ]] && DBPATH=$(readlink --canonicalize "$DBPATH")
|
2016-10-24 20:17:48 -04:00
|
|
|
DBs[$DBPATH]=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.readPassword "$handle" "Passwords" "$DBPATH" "$PROG")
|
|
|
|
done
|
|
|
|
|
|
|
|
# launch keepassx
|
|
|
|
IFS=$'\n\n\n'
|
|
|
|
keepassx --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
|
|
|
|
|
|
|
|
# done with kdewallet
|
|
|
|
qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.close "$handle" "false" "$PROG"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ '-d' = "$1" ]]; then
|
|
|
|
exec >&~/tmp/$PROG.log
|
|
|
|
set -vx
|
|
|
|
daemon_main
|
|
|
|
else
|
|
|
|
cd /
|
|
|
|
daemon_main </dev/null >&/dev/null &
|
|
|
|
disown
|
|
|
|
fi
|