From 18fb402404db8bfc8eccecba9994d7f7e3a405ca Mon Sep 17 00:00:00 2001 From: christian Date: Fri, 1 May 2026 12:41:49 +0200 Subject: [PATCH] sync_rsync zur ordner sync. erweiter --- .gitignore | 1 + find.sh | 77 +++++++++++++++++++++------------------------------ sync_rsync.sh | 40 ++++++++++++++++++++++++++ toolbox.sh | 49 ++++++++++++++++++++++++-------- 4 files changed, 110 insertions(+), 57 deletions(-) create mode 100755 sync_rsync.sh diff --git a/.gitignore b/.gitignore index e4f1e76..0e48b88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.log .env +sync.conf node_modules/ diff --git a/find.sh b/find.sh index 37ea2cc..52f9420 100755 --- a/find.sh +++ b/find.sh @@ -1,69 +1,56 @@ #!/bin/bash -# Robustere Ermittlung des Skript-Verzeichnisses +# Pfad ermitteln SCRIPT_PATH=$(readlink -f "$0") BASE_DIR=$(dirname "$SCRIPT_PATH") while true; do - # 1. Tags sammeln und zählen - # Wir extrahieren die Tags, sortieren sie und lassen 'uniq -c' die Vorkommen zählen + # 1. Tags sammeln (optimiert) + # Wir filtern hier noch aggressiver nach sauberen Text-Tags tag_counts=$(grep -rhioE "(#\w+|Tags:.*)" "$BASE_DIR" --include="README.md" 2>/dev/null | \ - sed 's/Tags://g' | tr ',' '\n' | tr -d ' ' | sort | uniq -c | sort -rn) + sed 's/Tags://g' | tr ',' '\n' | tr -d '\r' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | \ + grep -v '^$' | sort | uniq -c | sort -rn) if [ -z "$tag_counts" ]; then - zenity --error --title="Fehler" --text="Keine Tags gefunden.\nSuche in: $BASE_DIR" + zenity --error --title="Fehler" --text="Keine Tags gefunden in:\n$BASE_DIR" break fi - # 2. Formatierung für Zenity (Anzahl und Tag trennen) - # Wir wandeln die Ausgabe "5 #Weihnachten" in eine Liste um, die Zenity versteht - zenity_list=$(echo "$tag_counts" | awk '{print $2 " (" $1 ")"}') + # 2. Anzeige-Liste erstellen + zenity_list=$(echo "$tag_counts" | awk '{count=$1; $1=""; print $0 " (" count ")"}' | sed 's/^[[:space:]]*//') - # 3. Grafische Auswahl des Tags + # 3. Auswahl selected_item=$(echo "$zenity_list" | zenity --list \ --title="Projekt-Tag-Suche" \ --column="Tag (Anzahl)" \ --width=400 --height=500 \ --text="Wähle einen Tag aus:") - if [ -z "$selected_item" ]; then - break + if [ -z "$selected_item" ]; then break; fi + + # Extrahiere den reinen Tag (nimmt alles vor der ersten Klammer) + selected_tag=$(echo "$selected_item" | sed 's/ (.*)//') + + # 4. Suche nach den Projekten + # Wir suchen jetzt nach dem exakten String im gesamten Verzeichnisbaum + results=$(grep -rlF "$selected_tag" "$BASE_DIR" --include="README.md" 2>/dev/null | while read -r file; do + dirname "$file" + done | sort -u) + + if [ -z "$results" ]; then + zenity --info --text="Keine Projekte für den Tag '$selected_tag' gefunden.\n\nSuchpfad: $BASE_DIR" + continue fi - # Extrahiere den reinen Tag-Namen (alles vor dem Leerzeichen/Klammer) - selected_tag=$(echo "$selected_item" | awk '{print $1}') + # 5. Projektauswahl + selected_project=$(echo "$results" | zenity --list \ + --title="Ergebnisse für: $selected_tag" \ + --column="Projekt-Pfad" \ + --width=800 --height=400 \ + --ok-label="README öffnen" \ + --cancel-label="Zurück") - # 4. Projektauswahl-Schleife für den gewählten Tag - while true; do - results=$(grep -rl "$selected_tag" "$BASE_DIR" --include="README.md" 2>/dev/null | while read -r file; do - dirname "$(realpath "$file")" - done)[cite: 3] - - if [ -z "$results" ]; then - zenity --info --text="Keine Projekte für '$selected_tag' gefunden." - break - fi - - selected_project=$(echo "$results" | zenity --list \ - --title="Ergebnisse für: $selected_tag" \ - --column="Projekt-Pfad" \ - --text="Gefundene Projekte:" \ - --width=800 --height=400 \ - --ok-label="README öffnen" \ - --cancel-label="Zurück zur Tag-Suche") - - if [ -z "$selected_project" ]; then - break - fi - - # 5. README öffnen[cite: 3] - if [ -f "$selected_project/README.md" ]; then - xdg-open "$selected_project/README.md" &>/dev/null & - zenity --info --text="Öffne README von:\n$selected_project" --timeout=2 - fi - done - - if ! zenity --question --text="Möchtest du nach einem anderen Tag suchen?"; then - break + if [ -n "$selected_project" ] && [ -f "$selected_project/README.md" ]; then + xdg-open "$selected_project/README.md" &>/dev/null & fi done \ No newline at end of file diff --git a/sync_rsync.sh b/sync_rsync.sh new file mode 100755 index 0000000..12c0d41 --- /dev/null +++ b/sync_rsync.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) +CONF_FILE="$SCRIPT_DIR/sync.conf" + +if [ ! -f "$CONF_FILE" ]; then + zenity --error --text="sync.conf nicht gefunden!" + exit 1 +fi + +source "$CONF_FILE" + +# 1. Passwort abfragen +SSH_PASS=$(zenity --password --title="SSH Authentifizierung" --text="Passwort für $SSH_USER@$SSH_HOST:") + +# Abbrechen wenn kein Passwort eingegeben wurde +[ -z "$SSH_PASS" ] && exit 0 + +LOCAL_DIR="$SCRIPT_DIR/" + +# 2. Synchronisation (Download & Upload) +# Wir fügen '-o StrictHostKeyChecking=no' hinzu, damit SSH nicht bei unbekannten Hosts blockiert. +zenity --info --text="Synchronisation wird gestartet..." --timeout=2 + +# Download +sshpass -p "$SSH_PASS" rsync -auvz -e "ssh -p $SSH_PORT -o StrictHostKeyChecking=no" "$SSH_USER@$SSH_HOST:$REMOTE_DIR" "$LOCAL_DIR" 2>/tmp/rsync_error + +# Upload +sshpass -p "$SSH_PASS" rsync -auvz -e "ssh -p $SSH_PORT -o StrictHostKeyChecking=no" "$LOCAL_DIR" "$SSH_USER@$SSH_HOST:$REMOTE_DIR" 2>>/tmp/rsync_error + +# 3. Erfolgskontrolle +if [ $? -eq 0 ]; then + zenity --info --title="Erfolg" --text="Synchronisation erfolgreich abgeschlossen!" +else + ERROR_MSG=$(cat /tmp/rsync_error) + zenity --error --title="Fehler" --text="Synchronisation fehlgeschlagen!\n\nDetails:\n$ERROR_MSG" +fi + +# Temporäre Fehlerdatei löschen +rm -f /tmp/rsync_error \ No newline at end of file diff --git a/toolbox.sh b/toolbox.sh index 8cc0c8b..3aa43fb 100755 --- a/toolbox.sh +++ b/toolbox.sh @@ -1,29 +1,54 @@ #!/bin/bash +# Pfad zum Skript-Ordner ermitteln SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) -# Pfade zu den Modulen -SCRIPT_SETUP="$SCRIPT_DIR/setup_Projekt.sh" -SCRIPT_FIND="$SCRIPT_DIR/find.sh" - while true; do + # Hauptmenü mit Zenity - Korrigierte Version CHOICE=$(zenity --list \ --title="Christian's Projekt-Toolbox" \ + --text="Wählen Sie eine Aktion aus:" \ --column="Aktion" --column="Beschreibung" \ - --width=500 --height=350 \ - "1. Projekt erstellen" "Grafischer Konfigurator für neue Ordner" \ - "2. Projekt suchen" "Durchsucht Readmes nach Tags" \ - "3. Beenden" "Schließt die Toolbox") + --width=600 --height=450 \ + "1. Projekt erstellen" "Neuen Ordner mit Struktur anlegen" \ + "2. Projekt suchen" "Tags in READMEs durchsuchen" \ + "3. Cloud Sync (rsync)" "Abgleich mit Server (Zwei-Wege-Sync)" \ + "4. Beenden" "Schließt die Toolbox") + # Falls Abbrechen gedrückt wurde oder das Fenster geschlossen wurde + if [ $? -ne 0 ]; then + echo "Toolbox wird beendet." + break + fi + + # Auswahl auswerten case "$CHOICE" in "1. Projekt erstellen") - bash "$SCRIPT_SETUP" # Einfacher Aufruf ohne Terminal + bash "$SCRIPT_DIR/setup_Projekt.sh" ;; + "2. Projekt suchen") - bash "$SCRIPT_FIND" + bash "$SCRIPT_DIR/find.sh" ;; - "3. Beenden" | "") - exit 0 + + "3. Cloud Sync (rsync)") + if [ -f "$SCRIPT_DIR/sync_rsync.sh" ]; then + bash "$SCRIPT_DIR/sync_rsync.sh" + else + zenity --error --text="Skript 'sync_rsync.sh' nicht gefunden!" + fi + ;; + + "4. Beenden") + echo "Toolbox wird beendet." + break + ;; + + *) + # Sicherheitshalber, falls CHOICE leer ist + if [ -n "$CHOICE" ]; then + zenity --info --text="Aktion abgebrochen." --timeout=1 + fi ;; esac done \ No newline at end of file