64 lines
1.9 KiB
Plaintext
64 lines
1.9 KiB
Plaintext
#!/usr/bin/expect -f
|
|
|
|
# Aktiviere internes Debugging, um den Ablauf zu verfolgen
|
|
exp_internal 1
|
|
puts "DEBUG: Expect-Skript gestartet."
|
|
|
|
# Entferne alte Konfiguration, um eine neue Sitzung zu erzwingen
|
|
set config_dir "/config/.tuya-data"
|
|
if { [file isdirectory $config_dir] } {
|
|
puts "DEBUG: Altes Konfigurationsverzeichnis gefunden, wird entfernt."
|
|
if {[catch {file delete -force -- $config_dir} err]} {
|
|
puts stderr "FATAL: Konnte Verzeichnis '$config_dir' nicht löschen: $err"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
puts "DEBUG: Starte Authentifizierungsprozess."
|
|
set timeout 60
|
|
|
|
# Lese Eingaben
|
|
gets stdin region
|
|
gets stdin email
|
|
gets stdin password
|
|
|
|
if { $region eq "" || $email eq "" || $password eq "" } {
|
|
puts stderr "FATAL: Eine der Eingaben ist leer."
|
|
exit 1
|
|
}
|
|
|
|
spawn tuya-ipc-terminal auth add $region $email --password
|
|
|
|
# --- START DER ENTSCHEIDENDEN KORREKTUR ---
|
|
# Verwende einen regulären Ausdruck (-re), der auf verschiedene Passwortabfragen reagiert.
|
|
# "Enter ?[Pp]assword:" fängt "Enter password:" und "Enter Password:" ab.
|
|
expect {
|
|
-re {Password:|Enter ?[Pp]assword:?|Please enter your password:} {
|
|
puts "DEBUG: Passwortabfrage erkannt. Sende Passwort..."
|
|
send "$password\r"
|
|
puts "DEBUG: Passwort gesendet."
|
|
# exp_continue sorgt dafür, dass das Skript auf weitere Ausgaben wartet
|
|
exp_continue
|
|
}
|
|
# --- ENDE DER KORREKTUR ---
|
|
|
|
"Authentication successful" {
|
|
puts "DEBUG: Erfolgsmeldung 'Authentication successful' erkannt."
|
|
# Warte, bis der Prozess sich beendet hat
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 0
|
|
}
|
|
eof {
|
|
puts "DEBUG: Prozess hat sich beendet (EOF)."
|
|
# Prüfe den Exit-Code des beendeten Prozesses
|
|
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
|
|
}
|
|
}
|