2019-04-25 10:37:13 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# fetch KeePass database passwords from kdewallet
|
2016-10-24 20:17:48 -04:00
|
|
|
|
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}
|
|
|
|
|
2019-04-25 10:37:13 -04:00
|
|
|
PROG="${0##*/}"
|
|
|
|
KEEPASSXC=$(which -a keepassxc | sed -e "\\,$0,d" -e 'q')
|
2016-10-24 20:17:48 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
declare -A DBs
|
2019-04-25 10:37:13 -04:00
|
|
|
for DBPATH in $(ls -r $KDBX_SEARCH); do
|
|
|
|
DBs[$(realpath $DBPATH)]=$(qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.readPassword "$handle" "Passwords" "${DBPATH##*/}" "$PROG")
|
2016-10-24 20:17:48 -04:00
|
|
|
done
|
|
|
|
|
2019-04-25 10:37:13 -04:00
|
|
|
# launch real keepassxc
|
2016-10-24 20:17:48 -04:00
|
|
|
IFS=$'\n\n\n'
|
2019-04-25 10:37:13 -04:00
|
|
|
"$KEEPASSXC" --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
|
2016-10-24 20:17:48 -04:00
|
|
|
|
|
|
|
# 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
|