#!/bin/bash # Pfad zum Verzeichnis mit den JSON-Dateien (aktuelles Verzeichnis) json_dir="$(pwd)" # Überprüfen, ob das Verzeichnis existiert if [ ! -d "$json_dir" ]; then echo "Verzeichnis nicht gefunden!" exit 1 fi # CSS-Variablen für Stile # Hintergrundfarbe background_color="#ffffff" # Standard-Hintergrundfarbe (Weiß) # h1 header1_font_size="24px" header1_font_size_print="48px" header1_font_weight="bold" header1_font_family="Arial, sans-serif" header1_color="#000000" # h2 header2_font_size="20px" header2_font_size_print="40px" header2_font_weight="bold" header2_font_family="Arial, sans-serif" header2_color="#000000" # strong strong_font_size="16px" strong_font_size_print="32px" strong_font_weight="bold" strong_font_family="Arial, sans-serif" strong_color="#000000" # Normaler Text normal_font_size="14px" normal_font_size_print="28px" normal_font_weight="normal" normal_font_family="Arial, sans-serif" normal_color="#555555" # Margin-Left und Margin-Right für alle Elemente margin_left="10px" margin_right="10px" # Hinzugefügt für Konsistenz auf der Webansicht margin_left_print="30px" margin_right_print="30px" # Abstand der Trennstriche zum Text hr_margin="10px 0" # Beispiel: 10px Abstand oben und unten hr_margin_print="20px 0" # Erhöhter Abstand für die Druckansicht # Durchlaufe alle JSON-Dateien im Verzeichnis for json_file in "$json_dir"/*.json; do # Überprüfen, ob die Datei existiert if [ ! -f "$json_file" ]; then echo "Keine JSON-Dateien gefunden!" continue fi # Ausgabe-HTML-Datei basierend auf dem Namen der JSON-Datei output_file="${json_file%.json}.html" # HTML-Kopfzeile mit CSS-Styles schreiben echo "" > "$output_file" echo "Passwort Manager Daten" >> "$output_file" echo "" >> "$output_file" echo "" >> "$output_file" echo "" >> "$output_file" echo "" >> "$output_file" echo "

Passwort Manager Daten

" >> "$output_file" # Sammlung-Namen in eine Variable laden collections=$(jq -r '.collections | map({(.id): .name}) | add' "$json_file") # Items in HTML umwandeln jq -r --argjson collections "$collections" ' .items[] | "

\(.name)

" + (if .login.username != null then "

Nutzername: \(.login.username)

" else "" end) + (if .login.password != null then "

Passwort: \(.login.password)

" else "" end) + (if .notes != null then "

Notizen: \(.notes)

" else "" end) + (if (.login.uris | length) > 0 then "

URIs:

" + (.login.uris | to_entries | map("

URI \(.key + 1): " + .value.uri + "

") | join("")) else "" end) + (if (.fields | length) > 0 then "

Benutzerdefinierte Felder:

" + (.fields | map("

\(.name): \(.value)

") | join("")) else "" end) + (if (.collectionIds | length) > 0 then "

Sammlungen:

" + (.collectionIds | map($collections[.] // "Unbekannt") | sort_by(length) | to_entries | map( "

Sammlung \(.key + 1): " + .value + "

" ) | join("")) else "" end) + "
" ' "$json_file" >> "$output_file" # Überprüfen, ob jq einen Fehler hatte if [ $? -ne 0 ]; then echo "Fehler beim Parsen der JSON-Datei: $json_file" continue fi # HTML-Fußzeile schreiben echo "" >> "$output_file" echo "" >> "$output_file" echo "HTML-Datei wurde erstellt: $output_file" # PDF-Datei basierend auf der HTML-Datei erstellen pdf_file="${output_file%.html}.pdf" # Überprüfen, ob wkhtmltopdf installiert ist if ! command -v wkhtmltopdf &> /dev/null; then echo "PDF Erzeugung nicht möglich. Installieren sie wkhtmltopdf wenn sie Ausgabe in PDF Form benötigen." exit 1 fi wkhtmltopdf --page-size A4 --dpi 600 "$output_file" "$pdf_file" # Überprüfen, ob wkhtmltopdf erfolgreich war if [ $? -ne 0 ]; then echo "Fehler beim Erstellen der PDF-Datei: $pdf_file" else echo "PDF-Datei wurde erstellt: $pdf_file" fi done