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
|
||||
|
||||
# Check if the config directory already exists.
|
||||
# Check if config directory exists
|
||||
set config_dir "/config/.tuya-data"
|
||||
if { [file isdirectory $config_dir] } {
|
||||
# If it exists, print a message and exit successfully.
|
||||
puts "Skipping authentication: Configuration directory '$config_dir' already exists. To re-authenticate, delete the folder from the addon config folder."
|
||||
puts "Skipping authentication: Configuration directory already exists."
|
||||
exit 0
|
||||
}
|
||||
|
||||
# If the directory does not exist, proceed with authentication.
|
||||
puts "Configuration directory not found. Proceeding with authentication..."
|
||||
puts "Configuration directory not found. Proceeding with email/password authentication..."
|
||||
|
||||
# Set a timeout for the expect command to wait for a response.
|
||||
set timeout 20
|
||||
set timeout 30
|
||||
|
||||
# Read the region from the first line of standard input.
|
||||
# Read inputs
|
||||
gets stdin region
|
||||
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
|
||||
}
|
||||
|
||||
# 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."
|
||||
puts stderr "Error: Could not read email from stdin."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Spawn the tuya-ipc-terminal command, using the email variable.
|
||||
spawn tuya-ipc-terminal auth add $region $email --qr
|
||||
gets stdin password
|
||||
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
|
||||
send "\r"
|
||||
# Handle different prompts
|
||||
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
|
||||
wait
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user