From 745371759d982f022944b6f06fc135bc87c52148 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 16 Oct 2025 17:56:57 +0000 Subject: [PATCH] tuya-ipc-terminal/tuya_auth_login.exp aktualisiert --- tuya-ipc-terminal/tuya_auth_login.exp | 59 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/tuya-ipc-terminal/tuya_auth_login.exp b/tuya-ipc-terminal/tuya_auth_login.exp index 293e7cd..d450742 100644 --- a/tuya-ipc-terminal/tuya_auth_login.exp +++ b/tuya-ipc-terminal/tuya_auth_login.exp @@ -1,39 +1,47 @@ #!/usr/bin/expect -f -# Check if the config directory already exists. +# --- START: Anpassung für erzwungene Neu-Authentifizierung --- +# Entferne den alten Konfigurationsordner, falls er existiert, um eine neue Sitzung zu erzwingen. set config_dir "/config/.tuya-data" if { [file isdirectory $config_dir] } { - puts "Skipping authentication: Configuration directory '$config_dir' already exists." - exit 0 + puts "Alter Konfigurationsordner gefunden. Wird entfernt, um Neu-Authentifizierung zu erzwingen." + # Der 'catch'-Befehl fängt mögliche Fehler beim Löschen ab. + if {[catch {file delete -force -- $config_dir} err]} { + puts stderr "Fehler: Konnte den existierenden Ordner '$config_dir' nicht löschen: $err" + exit 1 + } } +# --- ENDE: Anpassung --- -puts "Configuration directory not found. Proceeding with authentication..." +puts "Starte den Authentifizierungsprozess..." set timeout 30 -# Read inputs +# Lese die Eingaben (Region, E-Mail, Passwort) von stdin gets stdin region if { [eof stdin] || $region eq "" } { - puts stderr "Error: Could not read region from stdin or region is empty." + puts stderr "Fehler: Region konnte nicht von stdin gelesen werden oder ist leer." exit 1 } gets stdin email if { [eof stdin] || $email eq "" } { - puts stderr "Error: Could not read email from stdin or email is empty." + puts stderr "Fehler: E-Mail konnte nicht von stdin gelesen werden oder ist leer." exit 1 } gets stdin password if { [eof stdin] || $password eq "" } { - puts stderr "Error: Could not read password from stdin or password is empty." + puts stderr "Fehler: Passwort konnte nicht von stdin gelesen werden oder ist leer." exit 1 } -# Spawn the command -spawn tuya-ipc-terminal auth add $region $email --password +# Starte den Befehl zur Authentifizierung +# Hinweis: Der Befehl wurde von 'auth add' auf 'users add' geändert, falls sich die CLI-Syntax geändert hat. +# Passen Sie dies bei Bedarf an die von Ihnen verwendete Version an. +spawn tuya-ipc-terminal users add $region $email --password -# Handle the interaction +# Behandele die Interaktion mit dem Prozess expect { "Password:" { send "$password\r" @@ -48,49 +56,56 @@ expect { exp_continue } "Authentication successful" { - puts "Authentication completed successfully!" - # Process completed successfully, wait for it to finish + puts "Authentifizierung erfolgreich abgeschlossen!" + # Warte auf das Ende des Prozesses, um sicherzustellen, dass alles geschrieben wurde catch {expect eof} catch {wait} exit 0 } "Login successful" { - puts "Login completed successfully!" + puts "Login erfolgreich abgeschlossen!" catch {expect eof} catch {wait} exit 0 } "Authentication completed" { - puts "Authentication completed!" + puts "Authentifizierung abgeschlossen!" catch {expect eof} catch {wait} exit 0 } "Invalid credentials" { - puts stderr "Authentication failed: Invalid credentials" + puts stderr "Authentifizierung fehlgeschlagen: Ungültige Anmeldedaten" catch {expect eof} catch {wait} exit 1 } "Login failed" { - puts stderr "Authentication failed: Login failed" + puts stderr "Authentifizierung fehlgeschlagen: Login fehlgeschlagen" catch {expect eof} catch {wait} exit 1 } "Authentication failed" { - puts stderr "Authentication failed" + puts stderr "Authentifizierung fehlgeschlagen" catch {expect eof} catch {wait} exit 1 } eof { - puts "Process ended unexpectedly" - catch {wait} - exit 1 + # Ein unerwartetes EOF kann auch ein Erfolg sein, wenn das Tool keine Abschlussmeldung ausgibt. + # Wir prüfen den Exit-Code des Prozesses. + set exit_code [lindex [wait] 2] + if { $exit_code == 0 } { + puts "Prozess beendet, vermutlich erfolgreich." + exit 0 + } else { + puts stderr "Prozess unerwartet beendet mit Exit-Code $exit_code." + exit 1 + } } timeout { - puts stderr "Authentication process timeout" + puts stderr "Zeitüberschreitung beim Authentifizierungsprozess" catch {expect eof} catch {wait} exit 1