tuya-ipc-terminal/tuya_auth_login.exp aktualisiert

This commit is contained in:
admin 2025-10-16 17:56:57 +00:00
parent 8ecc245aab
commit 745371759d

View File

@ -1,39 +1,47 @@
#!/usr/bin/expect -f #!/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" set config_dir "/config/.tuya-data"
if { [file isdirectory $config_dir] } { if { [file isdirectory $config_dir] } {
puts "Skipping authentication: Configuration directory '$config_dir' already exists." puts "Alter Konfigurationsordner gefunden. Wird entfernt, um Neu-Authentifizierung zu erzwingen."
exit 0 # 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 set timeout 30
# Read inputs # Lese die Eingaben (Region, E-Mail, Passwort) von stdin
gets stdin region gets stdin region
if { [eof stdin] || $region eq "" } { 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 exit 1
} }
gets stdin email gets stdin email
if { [eof stdin] || $email eq "" } { 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 exit 1
} }
gets stdin password gets stdin password
if { [eof stdin] || $password eq "" } { 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 exit 1
} }
# Spawn the command # Starte den Befehl zur Authentifizierung
spawn tuya-ipc-terminal auth add $region $email --password # 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 { expect {
"Password:" { "Password:" {
send "$password\r" send "$password\r"
@ -48,49 +56,56 @@ expect {
exp_continue exp_continue
} }
"Authentication successful" { "Authentication successful" {
puts "Authentication completed successfully!" puts "Authentifizierung erfolgreich abgeschlossen!"
# Process completed successfully, wait for it to finish # Warte auf das Ende des Prozesses, um sicherzustellen, dass alles geschrieben wurde
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 0 exit 0
} }
"Login successful" { "Login successful" {
puts "Login completed successfully!" puts "Login erfolgreich abgeschlossen!"
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 0 exit 0
} }
"Authentication completed" { "Authentication completed" {
puts "Authentication completed!" puts "Authentifizierung abgeschlossen!"
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 0 exit 0
} }
"Invalid credentials" { "Invalid credentials" {
puts stderr "Authentication failed: Invalid credentials" puts stderr "Authentifizierung fehlgeschlagen: Ungültige Anmeldedaten"
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 1 exit 1
} }
"Login failed" { "Login failed" {
puts stderr "Authentication failed: Login failed" puts stderr "Authentifizierung fehlgeschlagen: Login fehlgeschlagen"
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 1 exit 1
} }
"Authentication failed" { "Authentication failed" {
puts stderr "Authentication failed" puts stderr "Authentifizierung fehlgeschlagen"
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 1 exit 1
} }
eof { eof {
puts "Process ended unexpectedly" # Ein unerwartetes EOF kann auch ein Erfolg sein, wenn das Tool keine Abschlussmeldung ausgibt.
catch {wait} # Wir prüfen den Exit-Code des Prozesses.
exit 1 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 { timeout {
puts stderr "Authentication process timeout" puts stderr "Zeitüberschreitung beim Authentifizierungsprozess"
catch {expect eof} catch {expect eof}
catch {wait} catch {wait}
exit 1 exit 1