tuya-ipc-terminal/tuya_auth_login.exp aktualisiert
This commit is contained in:
parent
557f5cc32a
commit
715d82c3a9
@ -1,41 +1,4 @@
|
|||||||
#!/usr/bin/expect -f
|
# Handle the interaction
|
||||||
|
|
||||||
# Check if the config directory already exists.
|
|
||||||
set config_dir "/config/.tuya-data"
|
|
||||||
if { [file isdirectory $config_dir] } {
|
|
||||||
puts "Skipping authentication: Configuration directory '$config_dir' already exists."
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
puts "Configuration directory not found. Proceeding with authentication..."
|
|
||||||
|
|
||||||
set timeout 30
|
|
||||||
|
|
||||||
# Read the region from the first line of standard input.
|
|
||||||
gets stdin region
|
|
||||||
if { [eof stdin] || $region eq "" } {
|
|
||||||
puts stderr "Error: Could not read region from stdin or region is empty."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read the email from the second line of standard input.
|
|
||||||
gets stdin email
|
|
||||||
if { [eof stdin] || $email eq "" } {
|
|
||||||
puts stderr "Error: Could not read email from stdin or email is empty."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read the password from the third line of standard input.
|
|
||||||
gets stdin password
|
|
||||||
if { [eof stdin] || $password eq "" } {
|
|
||||||
puts stderr "Error: Could not read password from stdin or password is empty."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Spawn the tuya-ipc-terminal command WITH --password flag
|
|
||||||
spawn tuya-ipc-terminal auth add $region $email --password
|
|
||||||
|
|
||||||
# Handle password prompt
|
|
||||||
expect {
|
expect {
|
||||||
"Password:" {
|
"Password:" {
|
||||||
send "$password\r"
|
send "$password\r"
|
||||||
@ -51,23 +14,50 @@ expect {
|
|||||||
}
|
}
|
||||||
"Authentication successful" {
|
"Authentication successful" {
|
||||||
puts "Authentication completed successfully!"
|
puts "Authentication completed successfully!"
|
||||||
|
# Process completed successfully, wait for it to finish
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
"Login successful" {
|
"Login successful" {
|
||||||
puts "Login completed successfully!"
|
puts "Login completed successfully!"
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
"Authentication completed" {
|
||||||
|
puts "Authentication completed!"
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
"Invalid credentials" {
|
"Invalid credentials" {
|
||||||
puts stderr "Authentication failed: Invalid credentials"
|
puts stderr "Authentication failed: Invalid credentials"
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
"Login failed" {
|
"Login failed" {
|
||||||
puts stderr "Authentication failed: Login failed"
|
puts stderr "Authentication failed: Login failed"
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
"Authentication failed" {
|
||||||
|
puts stderr "Authentication failed"
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
eof {
|
||||||
|
puts "Process ended unexpectedly"
|
||||||
|
catch {wait}
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
timeout {
|
timeout {
|
||||||
puts stderr "Authentication timeout"
|
puts stderr "Authentication process timeout"
|
||||||
|
catch {expect eof}
|
||||||
|
catch {wait}
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect eof
|
|
||||||
wait
|
|
||||||
Loading…
x
Reference in New Issue
Block a user