From 7510477414c60b35a517c1416137164e98e7a5d8 Mon Sep 17 00:00:00 2001 From: Anthony Bosio Date: Sat, 21 Sep 2024 19:02:28 -0400 Subject: [PATCH] fix: check for python commands, fallback to python3 refs #386 (#389) Co-authored-by: abosio --- install.sh | 9 ++++++++- scaf | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index aee1a34e..030011b1 100755 --- a/install.sh +++ b/install.sh @@ -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 @@ -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 diff --git a/scaf b/scaf index 66c151dd..e45801ee 100755 --- a/scaf +++ b/scaf @@ -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" @@ -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..." @@ -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" \