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}
|
|
|
|
|
2021-09-21 00:17:46 -04:00
|
|
|
PROG=${0##*/}
|
2019-04-25 10:37:13 -04:00
|
|
|
KEEPASSXC=$(which -a keepassxc | sed -e "\\,$0,d" -e 'q')
|
2016-10-24 20:17:48 -04:00
|
|
|
|
2021-09-21 00:17:46 -04:00
|
|
|
daemon_main() {
|
2016-10-24 20:17:48 -04:00
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
|
2021-09-21 00:17:46 -04:00
|
|
|
if [[ $1 == '-d' ]]; then
|
2016-10-24 20:17:48 -04:00
|
|
|
exec >&~/tmp/$PROG.log
|
|
|
|
set -vx
|
|
|
|
daemon_main
|
|
|
|
else
|
|
|
|
cd /
|
|
|
|
daemon_main </dev/null >&/dev/null &
|
|
|
|
disown
|
|
|
|
fi
|