Skip to content

Commit

Permalink
Merge pull request #17 from aws/CheckForHttpClient
Browse files Browse the repository at this point in the history
Verify a valid HTTP client tool exists prior to installing Python
  • Loading branch information
rahulrajaram authored May 13, 2019
2 parents abfeacd + e37918a commit 81e3ee9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/python_installer
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function echo_with_indentation() {
echo -e " $message"
}

function echo_error_message () {
local message=$1
echo_with_indentation "\033[38;5;9m$message\033[0m"
}

function echo_recommendation_message() {
local message=$1
echo_with_indentation "\033[38;5;11m$message\033[0m"
Expand Down Expand Up @@ -146,6 +151,20 @@ function export_pyenv_and_pyenv_repository_paths() {
export PATH="$PYENV_ROOT/bin:$PYENV_REPOSITORY_LOCATION/bin:$PATH"
}

function verify_http_client_exists() {
if type curl &>/dev/null; then
return
elif type aria2c &>/dev/null; then
return
elif [[ "$(wget --version 2>/dev/null || true)" = "GNU Wget 1.1"[0-3]* ]]; then
echo_error_message "wget (>= 1.14) or curl (>= 7.18.1) is required to download and install Python."
exit 1
else
echo_error_message "Could not find \`curl\`, \`wget\`, or \`aria2c\`. Please install one of these tools to continue Python installation"
exit 1
fi
}

function main() {
echo_step_title "Determining whether pyenv is already installed and in PATH"

Expand All @@ -161,6 +180,9 @@ function main() {
echo_step_title "Temporarily export necessary pyenv paths"
export_pyenv_and_pyenv_repository_paths

echo_step_title "Checking whether Python can be downloaded (through curl, wget, or aria2c)"
verify_http_client_exists

echo_step_title "Installing Python $PYTHON_VERSION"
install_python

Expand Down

0 comments on commit 81e3ee9

Please sign in to comment.