Skip to content

Commit 81e3ee9

Browse files
authored
Merge pull request #17 from aws/CheckForHttpClient
Verify a valid HTTP client tool exists prior to installing Python
2 parents abfeacd + e37918a commit 81e3ee9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/python_installer

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ function echo_with_indentation() {
6464
echo -e " $message"
6565
}
6666

67+
function echo_error_message () {
68+
local message=$1
69+
echo_with_indentation "\033[38;5;9m$message\033[0m"
70+
}
71+
6772
function echo_recommendation_message() {
6873
local message=$1
6974
echo_with_indentation "\033[38;5;11m$message\033[0m"
@@ -146,6 +151,20 @@ function export_pyenv_and_pyenv_repository_paths() {
146151
export PATH="$PYENV_ROOT/bin:$PYENV_REPOSITORY_LOCATION/bin:$PATH"
147152
}
148153

154+
function verify_http_client_exists() {
155+
if type curl &>/dev/null; then
156+
return
157+
elif type aria2c &>/dev/null; then
158+
return
159+
elif [[ "$(wget --version 2>/dev/null || true)" = "GNU Wget 1.1"[0-3]* ]]; then
160+
echo_error_message "wget (>= 1.14) or curl (>= 7.18.1) is required to download and install Python."
161+
exit 1
162+
else
163+
echo_error_message "Could not find \`curl\`, \`wget\`, or \`aria2c\`. Please install one of these tools to continue Python installation"
164+
exit 1
165+
fi
166+
}
167+
149168
function main() {
150169
echo_step_title "Determining whether pyenv is already installed and in PATH"
151170

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

183+
echo_step_title "Checking whether Python can be downloaded (through curl, wget, or aria2c)"
184+
verify_http_client_exists
185+
164186
echo_step_title "Installing Python $PYTHON_VERSION"
165187
install_python
166188

0 commit comments

Comments
 (0)