#!/usr/bin/expect -f # --- START SUPER-DEBUG --- # Aktiviere das interne Debugging von Expect. Dies erzeugt SEHR viel Output. exp_internal 1 puts "DEBUG: Expect-Skript gestartet. Internes Debugging ist aktiviert." # --- ENDE SUPER-DEBUG --- # Entferne den alten Konfigurationsordner, um eine Neu-Authentifizierung zu erzwingen. set config_dir "/config/.tuya-data" puts "DEBUG: Prüfe auf Verzeichnis: $config_dir" if { [file isdirectory $config_dir] } { puts "DEBUG: Altes Konfigurationsverzeichnis gefunden. Wird entfernt." if {[catch {file delete -force -- $config_dir} err]} { puts stderr "FATAL: Konnte existierendes Verzeichnis '$config_dir' nicht löschen: $err" exit 1 } puts "DEBUG: Verzeichnis erfolgreich entfernt." } else { puts "DEBUG: Kein altes Konfigurationsverzeichnis gefunden. Fortfahren." } puts "DEBUG: Starte den Authentifizierungsprozess..." set timeout 60 # Lese die Eingaben puts "DEBUG: Lese Region von stdin..." gets stdin region puts "DEBUG: Region gelesen: $region" puts "DEBUG: Lese Email von stdin..." gets stdin email puts "DEBUG: Email gelesen: $email" puts "DEBUG: Lese Passwort von stdin..." gets stdin password # Das Passwort selbst nicht loggen puts "DEBUG: Passwort wurde gelesen." if { $region eq "" || $email eq "" || $password eq "" } { puts stderr "FATAL: Eine der Eingaben (Region, Email, Passwort) ist leer." exit 1 } puts "DEBUG: Starte 'spawn tuya-ipc-terminal auth add ...'" spawn tuya-ipc-terminal auth add $region $email --password # Interaktion expect { "Password:" { puts "DEBUG: 'Password:' Prompt erkannt. Sende Passwort..." send "$password\r" puts "DEBUG: Passwort gesendet." exp_continue } "Authentication successful" { puts "DEBUG: Erfolg-Nachricht 'Authentication successful' erkannt." catch {expect eof} catch {wait} exit 0 } eof { puts "DEBUG: 'eof' (End of File) vom Prozess erreicht." set exit_code [lindex [wait] 2] puts "DEBUG: Prozess beendet mit Exit-Code $exit_code." exit $exit_code } timeout { puts stderr "FATAL: Timeout nach 60 Sekunden." exit 1 } }