forked from keepassxreboot/keepassxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keepassxc-kdewallet
executable file
·38 lines (31 loc) · 1.07 KB
/
keepassxc-kdewallet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# fetch KeePass database passwords from kdewallet
### change the path to suit your installation or set KDBX_SEARCH before calling ###
: ${KDBX_SEARCH:=~/.KeePass/*.kdbx}
PROG=${0##*/}
KEEPASSXC=$(which -a keepassxc | sed -e "\\,$0,d" -e 'q')
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
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")
done
# launch real keepassxc
IFS=$'\n\n\n'
"$KEEPASSXC" --pw-stdin "${!DBs[@]}" <<<"${DBs[*]}" &
# done with kdewallet
qdbus org.kde.kwalletd5 /modules/kwalletd5 org.kde.KWallet.close "$handle" "false" "$PROG"
}
if [[ $1 == '-d' ]]; then
exec >&~/tmp/$PROG.log
set -vx
daemon_main
else
cd /
daemon_main </dev/null >&/dev/null &
disown
fi