add script to extract passwords from unix password manager

This commit is contained in:
Simon Rieger 2024-07-10 20:02:43 +02:00
parent 4f278ad3ce
commit 6027f91c9c

30
extract_pass.sh Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
# Pfad zum Passwortspeicher
PASSWORD_STORE_DIR="${HOME}/.password-store"
# CSV-Datei für den Export
OUTPUT_FILE="vaultwarden_export.csv"
# CSV-Header hinzufügen
echo "folder,favorite,type,name,notes,fields,login_uri,login_username,login_password,login_totp" > "$OUTPUT_FILE"
# Funktion zum Konvertieren eines Passworts
convert_pass() {
name=$1
mapfile -t lines < <(pass show "$name")
url=$(basename "$name")
username=$(echo "${lines[1]}" | sed 's/^.*: //')
password=${lines[0]}
folder=$(dirname "$name")
notes=$(printf "%s\n" "${lines[@]:2}")
echo "$folder,,login,$url,$notes,,$url,$username,$password," >> "$OUTPUT_FILE"
}
# Alle Passwortdateien finden und konvertieren
find "$PASSWORD_STORE_DIR" -type f -name "*.gpg" | while read -r file; do
pass_name=$(echo "$file" | sed "s|^$PASSWORD_STORE_DIR/||" | sed 's/\.gpg$//')
convert_pass "$pass_name"
done
echo "Export abgeschlossen. Die CSV-Datei wurde in $OUTPUT_FILE gespeichert."