108 lines
2.9 KiB
Plaintext
108 lines
2.9 KiB
Plaintext
#!/usr/bin/expect -f
|
|
|
|
# Entferne den alten Konfigurationsordner, um eine Neu-Authentifizierung zu erzwingen.
|
|
set config_dir "/config/.tuya-data"
|
|
if { [file isdirectory $config_dir] } {
|
|
puts "Alter Konfigurationsordner gefunden. Wird entfernt, um Neu-Authentifizierung zu erzwingen."
|
|
if {[catch {file delete -force -- $config_dir} err]} {
|
|
puts stderr "Fehler: Konnte den existierenden Ordner '$config_dir' nicht löschen: $err"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
puts "Starte den Authentifizierungsprozess..."
|
|
|
|
set timeout 30
|
|
|
|
# Lese die Eingaben (Region, E-Mail, Passwort) von stdin
|
|
gets stdin region
|
|
if { [eof stdin] || $region eq "" } {
|
|
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 "Fehler: E-Mail konnte nicht von stdin gelesen werden oder ist leer."
|
|
exit 1
|
|
}
|
|
|
|
gets stdin password
|
|
if { [eof stdin] || $password eq "" } {
|
|
puts stderr "Fehler: Passwort konnte nicht von stdin gelesen werden oder ist leer."
|
|
exit 1
|
|
}
|
|
|
|
# --- KORRIGIERTE ZEILE ---
|
|
# Starte den Befehl zur Authentifizierung mit dem korrekten Sub-Befehl 'auth'
|
|
spawn tuya-ipc-terminal auth add $region $email --password
|
|
# --- ENDE DER KORREKTUR ---
|
|
|
|
# Behandele die Interaktion mit dem Prozess
|
|
expect {
|
|
"Password:" {
|
|
send "$password\r"
|
|
exp_continue
|
|
}
|
|
"Enter password:" {
|
|
send "$password\r"
|
|
exp_continue
|
|
}
|
|
"Please enter your password:" {
|
|
send "$password\r"
|
|
exp_continue
|
|
}
|
|
"Authentication successful" {
|
|
puts "Authentifizierung erfolgreich abgeschlossen!"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 0
|
|
}
|
|
"Login successful" {
|
|
puts "Login erfolgreich abgeschlossen!"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 0
|
|
}
|
|
"Authentication completed" {
|
|
puts "Authentifizierung abgeschlossen!"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 0
|
|
}
|
|
"Invalid credentials" {
|
|
puts stderr "Authentifizierung fehlgeschlagen: Ungültige Anmeldedaten"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 1
|
|
}
|
|
"Login failed" {
|
|
puts stderr "Authentifizierung fehlgeschlagen: Login fehlgeschlagen"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 1
|
|
}
|
|
"Authentication failed" {
|
|
puts stderr "Authentifizierung fehlgeschlagen"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 1
|
|
}
|
|
eof {
|
|
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 "Zeitüberschreitung beim Authentifizierungsprozess"
|
|
catch {expect eof}
|
|
catch {wait}
|
|
exit 1
|
|
}
|
|
}
|