-
Notifications
You must be signed in to change notification settings - Fork 0
/
kpt2bitwarden
executable file
·35 lines (29 loc) · 1.1 KB
/
kpt2bitwarden
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
#!/usr/bin/env bash
# kpt2bitwarden - Enter keepassx text into bitwarden .csv format:
# <group>,,login,<name>,<notes>,,<url>,<user>,<pw>,^M
# Usage: kpt2bitwarden keepassx.kpt >bitwarden.csv
[[ ! -f $1 ]] && echo "Need filename of Text Export from KeepassX" && exit 1
in=$1 out=&1
echo "folder,favorite,type,name,notes,fields,login_uri,login_username,login_password,login_totp"$'\xd' >"$out"
group=
while read -r
do
r=$REPLY
case "$r" in
'*** Group: '*) [[ $group ]] && # Unprocessed previous entry
echo "$group,,login,$name,\"${notes//\"/\"\"}\",,$url,$user,$pw,"$'\xd' >>"$out"
group=${r:11} group=${group% ???} name= ;;
' Title: '*)
[[ $name ]] && # Unprocessed previous entry
echo "$group,,login,$name,\"${notes//\"/\"\"}\",,$url,$user,$pw,"$'\xd' >>"$out"
name=${r:12} notes= ;;
' Username: '*) user=${r:12} ;;
' Url: '*) url=${r:12} ;;
' Password: '*) pw=${r:12} ;;
' Comment: '*) notes=${r:12} ;;
' '*) notes+=$'\n'${r:12} ;;
esac
done <"$in"
# Output final entry
echo "$group,,login,$name,\"${notes//\"/\"\"}\",,$url,$user,$pw,"$'\xd' >>"$out"
exit 0