Skip to content

Commit

Permalink
fix: check for python commands, fallback to python3 refs #386 (#389)
Browse files Browse the repository at this point in the history
Co-authored-by: abosio <[email protected]>
  • Loading branch information
abosio and abosio authored Sep 21, 2024
1 parent 24b4600 commit 7510477
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ command_exists() {

check_top_level_dependencies() {
# these are dependencies that we depend on the user to have installed
dependencies="bash curl make python3 docker git rsync"
dependencies="bash curl make docker git rsync"
missing=""

for dep in $dependencies; do
Expand All @@ -43,6 +43,13 @@ check_top_level_dependencies() {
fi
done

# Check if python commands exist
if command -v python &>/dev/null || command -v python3 &>/dev/null; then
:
else
missing="$missing python3"
fi

if [ -z "$missing" ]; then
echo "All top-level dependencies are installed."
return 0
Expand Down
16 changes: 13 additions & 3 deletions scaf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env bash

# set python command
if command -v python &>/dev/null; then
PYTHON_CMD=python
elif command -v python3 &>/dev/null; then
PYTHON_CMD=python3
else
echo "Missing python3 command. Please install python3."
exit 1;
fi

# Scaf challenge script
CHALLENGE_CONFIG_PATH=".scaf-challenge.json"

Expand Down Expand Up @@ -122,11 +132,11 @@ EOF
trap code_received SIGUSR1

# Start the Python server in the background
python temp_server.py &
$PYTHON_CMD temp_server.py &
server_pid=$!

# Example opening of the browser to auth/reg user
python -c "import webbrowser; webbrowser.open('https://scaf.withpassage.com/authorize?response_type=code&client_id=961JRDH4c4Sin8LYGGbI0Lb7&redirect_uri=http://localhost:51111&scope=openid%20email')"
$PYTHON_CMD -c "import webbrowser; webbrowser.open('https://scaf.withpassage.com/authorize?response_type=code&client_id=961JRDH4c4Sin8LYGGbI0Lb7&redirect_uri=http://localhost:51111&scope=openid%20email')"

echo "Waiting for authorization..."

Expand Down Expand Up @@ -178,7 +188,7 @@ start_challenge_session() {
token=$(echo $config | grep -o '"access_token": "[^"]*"' | sed -e 's/"access_token": "\([^"]*\)"/\1/')
base_url=$(echo $config | grep -o '"base_url": "[^"]*"' | sed -e 's/"base_url": "\([^"]*\)"/\1/')
session_id=$(echo $config | grep -o '"session_id": "[^"]*"' | sed -e 's/"session_id": "\([^"]*\)"/\1/')
start=$(python -c "import time; print('{:.6f}'.format(time.time()))")
start=$($PYTHON_CMD -c "import time; print('{:.6f}'.format(time.time()))")

# Make report API call to kick off the session
status_code=$(curl -o /dev/null -s -w "%{http_code}" --location "$base_url/Prod/report" \
Expand Down

0 comments on commit 7510477

Please sign in to comment.