#!/usr/bin/expect -f # Check if config directory exists set config_dir "/config/.tuya-data" if { [file isdirectory $config_dir] } { puts "Skipping authentication: Configuration directory already exists." exit 0 } puts "Configuration directory not found. Proceeding with email/password authentication..." set timeout 30 # Read inputs gets stdin region if { [eof stdin] || $region eq "" } { puts stderr "Error: Could not read region from stdin." exit 1 } gets stdin email if { [eof stdin] || $email eq "" } { puts stderr "Error: Could not read email from stdin." exit 1 } gets stdin password if { [eof stdin] || $password eq "" } { puts stderr "Error: Could not read password from stdin." exit 1 } # Start authentication without --qr flag spawn tuya-ipc-terminal auth add $region $email # 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