Last active
September 11, 2024 04:23
-
-
Save Badbird5907/716e9bb9aaff34ac037b6929af692168 to your computer and use it in GitHub Desktop.
Infisical selfhosted login expect script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
if { [regexp {Your login session has expired|You must be logged in} $env(_INFISICAL_STATUS)] } { | |
spawn infisical login --domain=$env(INFISICAL_API_URL) | |
expect { | |
"Self Hosting" { | |
puts "Found self hosting option." | |
puts "" | |
# down | |
send -- "\033\[B" | |
# enter | |
send -- "\r" | |
# it will either prompt for a domain to be entered, or "Which domain would you like to use?" | |
expect { | |
"Which domain would you like to use?" { | |
send -- "\r" | |
# Allow the user to login via browser | |
interact | |
exit 0 | |
} | |
-re ".*Domain.*" { | |
send -- "$env(INFISICAL_API_URL)" | |
send -- "\r" | |
# Allow the user to login via browser | |
interact | |
exit 0 | |
} | |
timeout { | |
puts "Error: Timeout during infisical login interaction." | |
exit 1 | |
} | |
} | |
} | |
"Use Domain" { | |
send -- "\r" | |
interact | |
exit 0 | |
} | |
timeout { | |
puts "Error: Timeout during infisical login interaction." | |
exit 1 | |
} | |
} | |
expect eof | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log_info "Checking login status..." | |
infisical_status="$(infisical secrets 2>&1)" # we're running this purely to check if the user's session is expired | |
if [[ "$infisical_status" == *"Your login session has expired"* || "$infisical_status" == *"You must be logged in"* ]]; then | |
# check if expect is installed | |
if ! command -v expect &> /dev/null; then | |
log_error "expect is not installed! Please install it to continue." | |
# check mac | |
if [ "$(uname)" == "Darwin" ]; then | |
log_info "You can install expect with brew: brew install expect" | |
elif [ -f /etc/debian_version ]; then | |
log_info "You can install expect with apt: sudo apt install expect" | |
fi | |
exit 1 | |
fi | |
log_info "Logging in with expect..." | |
export _INFISICAL_STATUS="$infisical_status" | |
# run the expect script | |
script_path=$(dirname "$0") | |
expect "$script_path/login.expect.sh" | |
#infisical login --domain="$INFISICAL_API_URL" | |
# check if the login was successful | |
if [ $? -ne 0 ]; then | |
log_error "Error: Login process failed! (try logging in manually with infisical login)" | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment