tuya-ipc-terminal/tuya_auth_qr.exp aktualisiert
This commit is contained in:
parent
1b62319289
commit
d7494f8250
@ -1,40 +1,60 @@
|
|||||||
#!/usr/bin/expect -f
|
#!/usr/bin/expect -f
|
||||||
|
|
||||||
# Check if the config directory already exists.
|
# Check if config directory exists
|
||||||
set config_dir "/config/.tuya-data"
|
set config_dir "/config/.tuya-data"
|
||||||
if { [file isdirectory $config_dir] } {
|
if { [file isdirectory $config_dir] } {
|
||||||
# If it exists, print a message and exit successfully.
|
puts "Skipping authentication: Configuration directory already exists."
|
||||||
puts "Skipping authentication: Configuration directory '$config_dir' already exists. To re-authenticate, delete the folder from the addon config folder."
|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# If the directory does not exist, proceed with authentication.
|
puts "Configuration directory not found. Proceeding with email/password authentication..."
|
||||||
puts "Configuration directory not found. Proceeding with authentication..."
|
|
||||||
|
|
||||||
# Set a timeout for the expect command to wait for a response.
|
set timeout 30
|
||||||
set timeout 20
|
|
||||||
|
|
||||||
# Read the region from the first line of standard input.
|
# Read inputs
|
||||||
gets stdin region
|
gets stdin region
|
||||||
if { [eof stdin] || $region eq "" } {
|
if { [eof stdin] || $region eq "" } {
|
||||||
puts stderr "Error: Could not read region from stdin or region is empty."
|
puts stderr "Error: Could not read region from stdin."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read the email from the second line of standard input.
|
|
||||||
gets stdin email
|
gets stdin email
|
||||||
if { [eof stdin] || $email eq "" } {
|
if { [eof stdin] || $email eq "" } {
|
||||||
puts stderr "Error: Could not read email from stdin or email is empty."
|
puts stderr "Error: Could not read email from stdin."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Spawn the tuya-ipc-terminal command, using the email variable.
|
gets stdin password
|
||||||
spawn tuya-ipc-terminal auth add $region $email --qr
|
if { [eof stdin] || $password eq "" } {
|
||||||
|
puts stderr "Error: Could not read password from stdin."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
expect "Press Enter after scanning to continue"
|
# Start authentication without --qr flag
|
||||||
|
spawn tuya-ipc-terminal auth add $region $email
|
||||||
|
|
||||||
# Send the Enter key
|
# Handle different prompts
|
||||||
send "\r"
|
expect {
|
||||||
|
"Password:" {
|
||||||
|
send "$password\r"
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
"Enter password:" {
|
||||||
|
send "$password\r"
|
||||||
|
exp_continue
|
||||||
|
}
|
||||||
|
"Authentication successful" {
|
||||||
|
puts "Login successful!"
|
||||||
|
}
|
||||||
|
"Login failed" {
|
||||||
|
puts stderr "Authentication failed - check credentials"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
puts stderr "Authentication timeout"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
expect eof
|
expect eof
|
||||||
wait
|
wait
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user