tuya-ipc-terminal/tuya_auth_login.exp aktualisiert
This commit is contained in:
parent
3f0241affd
commit
6140e7fcef
@ -1,107 +1,58 @@
|
|||||||
#!/usr/bin/expect -f
|
#!/usr/bin/with-contenv bashio
|
||||||
|
|
||||||
# Entferne den alten Konfigurationsordner, um eine Neu-Authentifizierung zu erzwingen.
|
# Konfiguration lesen
|
||||||
set config_dir "/config/.tuya-data"
|
readonly TUYA_EMAIL=$(bashio::config 'TUYA_EMAIL')
|
||||||
if { [file isdirectory $config_dir] } {
|
readonly TUYA_PASSWORD=$(bashio::config 'TUYA_PASSWORD')
|
||||||
puts "Alter Konfigurationsordner gefunden. Wird entfernt, um Neu-Authentifizierung zu erzwingen."
|
readonly TUYA_REGION=$(bashio::config 'TUYA_REGION')
|
||||||
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..."
|
# Prüfen, ob Konfiguration vorhanden ist
|
||||||
|
if [[ -z "${TUYA_EMAIL}" || -z "${TUYA_PASSWORD}" ]]; then
|
||||||
set timeout 30
|
bashio::log.fatal "Tuya-E-Mail und Passwort müssen konfiguriert sein."
|
||||||
|
|
||||||
# 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
|
exit 1
|
||||||
}
|
fi
|
||||||
|
|
||||||
gets stdin email
|
# --- START: Authentifizierung und Kamera-Sync ---
|
||||||
if { [eof stdin] || $email eq "" } {
|
bashio::log.info "Authentifizierung bei Tuya..."
|
||||||
puts stderr "Fehler: E-Mail konnte nicht von stdin gelesen werden oder ist leer."
|
printf "%s\n%s\n%s\n" "${TUYA_REGION}" "${TUYA_EMAIL}" "${TUYA_PASSWORD}" | /tuya_auth_login.exp
|
||||||
|
|
||||||
|
# --- NEU: Kamera-Refresh erzwingen ---
|
||||||
|
bashio::log.info "Synchronisiere Kameraliste mit Tuya-Cloud..."
|
||||||
|
# Dieser Befehl sorgt dafür, dass die lokale Konfiguration mit den Kameras aus Ihrem Account gefüllt wird.
|
||||||
|
tuya-ipc-terminal cameras refresh
|
||||||
|
# Eine kurze Pause kann helfen, damit alle Prozesse synchron sind.
|
||||||
|
sleep 5
|
||||||
|
# --- ENDE NEU ---
|
||||||
|
|
||||||
|
# Starte den RTSP-Server im Hintergrund
|
||||||
|
bashio::log.info "Starte den Tuya RTSP-Server im Hintergrund..."
|
||||||
|
tuya-ipc-terminal rtsp start --port 8554 &
|
||||||
|
# Speichere die Prozess-ID (PID) des RTSP-Servers
|
||||||
|
RTSP_PID=$!
|
||||||
|
bashio::log.info "RTSP-Server gestartet mit PID ${RTSP_PID}."
|
||||||
|
|
||||||
|
# Überprüfe, ob der Prozess noch läuft
|
||||||
|
if ! ps -p "${RTSP_PID}" > /dev/null; then
|
||||||
|
bashio::log.fatal "RTSP-Server konnte nicht gestartet werden. Prüfen Sie das Log auf Fehler wie 'no cameras found'."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
fi
|
||||||
|
|
||||||
gets stdin password
|
# --- Start: Watchdog-Schleife ---
|
||||||
if { [eof stdin] || $password eq "" } {
|
bashio::log.info "Starte den Watchdog zur Überwachung der Sitzung."
|
||||||
puts stderr "Fehler: Passwort konnte nicht von stdin gelesen werden oder ist leer."
|
while true; do
|
||||||
exit 1
|
# Warte für 15 Minuten
|
||||||
}
|
sleep 900
|
||||||
|
|
||||||
# --- KORRIGIERTE ZEILE ---
|
bashio::log.info "Watchdog: Überprüfe den Status der Tuya-Sitzung..."
|
||||||
# Starte den Befehl zur Authentifizierung mit dem korrekten Sub-Befehl 'auth'
|
RESPONSE=$(tuya-ipc-terminal cameras refresh 2>&1)
|
||||||
spawn tuya-ipc-terminal auth add $region $email --password
|
|
||||||
# --- ENDE DER KORREKTUR ---
|
|
||||||
|
|
||||||
# Behandele die Interaktion mit dem Prozess
|
if echo "${RESPONSE}" | grep -q -E "401|USER_SESSION_LOSS|Not login"; then
|
||||||
expect {
|
bashio::log.error "Watchdog: Abgelaufene Sitzung erkannt! Starte das Addon neu."
|
||||||
"Password:" {
|
kill "${RTSP_PID}"
|
||||||
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
|
exit 1
|
||||||
}
|
elif ! ps -p "${RTSP_PID}" > /dev/null; then
|
||||||
"Login failed" {
|
bashio::log.error "Watchdog: RTSP-Server-Prozess nicht gefunden! Starte das Addon neu."
|
||||||
puts stderr "Authentifizierung fehlgeschlagen: Login fehlgeschlagen"
|
|
||||||
catch {expect eof}
|
|
||||||
catch {wait}
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
else
|
||||||
"Authentication failed" {
|
bashio::log.info "Watchdog: Sitzung ist gültig und RTSP-Server läuft."
|
||||||
puts stderr "Authentifizierung fehlgeschlagen"
|
fi
|
||||||
catch {expect eof}
|
done
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user