sync_rsync zur ordner sync. erweiter
This commit is contained in:
parent
3b3f9075f6
commit
18fb402404
4 changed files with 110 additions and 57 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
*.log
|
||||
.env
|
||||
sync.conf
|
||||
node_modules/
|
||||
|
|
|
|||
77
find.sh
77
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
|
||||
40
sync_rsync.sh
Executable file
40
sync_rsync.sh
Executable file
|
|
@ -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
|
||||
49
toolbox.sh
49
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
|
||||
Loading…
Add table
Reference in a new issue