@@ -4,7 +4,7 @@ set -o pipefail
44
55# ## Requirements
66# ## ----------------------------------------
7- # ## Minimum: wget and unzip
7+ # ## Minimum: ( wget or curl) and unzip
88# ## v1: Python v2.7+ or 3.4+
99# ## v2: Nothing special
1010# ## ----------------------------------------
@@ -89,17 +89,37 @@ get_download_url(){
8989 echo " $download_url "
9090}
9191
92+ set_download_tool (){
93+ # Default is "wget", fallback is "curl", fails otherwise
94+ if which wget 1> /dev/null; then
95+ _AWS_CLI_DOWNLOAD_TOOL=" wget"
96+ elif which curl 1> /dev/null; then
97+ _AWS_CLI_DOWNLOAD_TOOL=" curl"
98+ else
99+ msg_error " Both 'wget' and 'curl' are not installed"
100+ fi
101+ }
102+
92103
93104check_version_exists (){
94105 local provided_url
106+ local response=" "
95107 local exists=" "
96108 provided_url=" $1 "
97109 [[ " $_VERBOSE " = " true" ]] && msg_log " Checking if the provided version exists in AWS"
98- exists=" $( wget -q -S --spider " $provided_url " 2>&1 | grep ' HTTP/1.1 200 OK' || true) "
110+
111+ if [[ " $_AWS_CLI_DOWNLOAD_TOOL " = " wget" ]]; then
112+ response=" $( wget -q -S --spider " $provided_url " 2>&1 || true) "
113+ elif [[ " $_AWS_CLI_DOWNLOAD_TOOL " = " curl" ]]; then
114+ response=" $( curl -I -sL " $provided_url " 2>&1 || true) "
115+ fi
116+
117+ exists=" $( echo " $response " | grep ' HTTP/1.1 200 OK' || true) "
118+ # If exists is not empty then everything is ok, otherwise should fail and print resposne message
99119 if [[ -n " $exists " ]]; then
100120 msg_log " Provided version exists - ${provided_url} "
101121 else
102- msg_error " Provided version does not exist - ${provided_url} "
122+ msg_error " Provided version does not exist - ${provided_url} \nResponse message:\n ${response} "
103123 fi
104124}
105125
@@ -109,8 +129,14 @@ download_aws_cli(){
109129 local provided_url
110130 provided_filename=" $1 "
111131 provided_url=" $2 "
112- msg_log " Downloading ..."
113- wget -q -O " $provided_filename " " $provided_url "
132+ msg_log " Downloading with ${_AWS_CLI_DOWNLOAD_TOOL} ..."
133+
134+ if [[ " $_AWS_CLI_DOWNLOAD_TOOL " = " wget" ]]; then
135+ wget -q -O " $provided_filename " " $provided_url "
136+ elif [[ " $_AWS_CLI_DOWNLOAD_TOOL " = " curl" ]]; then
137+ curl -sL -o " $provided_filename " " $provided_url "
138+ fi
139+
114140 [[ " $_VERBOSE " = " true" ]] && ls -lah " $provided_filename "
115141 wait
116142}
@@ -178,7 +204,11 @@ install_lightsailctl(){
178204 provided_version=" $1 "
179205 if [[ $provided_version =~ ^2.* $ ]]; then
180206 msg_log " Installing Lightsailctl"
181- wget -q -O " /usr/local/bin/lightsailctl" " https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl"
207+ if [[ " $_AWS_CLI_DOWNLOAD_TOOL " = " wget" ]]; then
208+ wget -q -O " /usr/local/bin/lightsailctl" " https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl"
209+ elif [[ " $_AWS_CLI_DOWNLOAD_TOOL " = " curl" ]]; then
210+ curl -sL -o " /usr/local/bin/lightsailctl" " https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl"
211+ fi
182212 wait
183213 chmod +x /usr/local/bin/lightsailctl
184214 msg_log " Installation complete"
@@ -226,6 +256,7 @@ _AWS_CLI_ARCH="${_AWS_CLI_ARCH:-"$_DEFAULT_ARCH"}"
226256# ## Main
227257set_workdir " $_WORKDIR "
228258validate_semantic_version " $_AWS_CLI_VERSION "
259+ set_download_tool
229260
230261# Set Download URL and check if file exists on server
231262_AWS_CLI_DOWNLOAD_URL=" ${AWS_CLI_DOWNLOAD_URL:- " $( get_download_url " $_AWS_CLI_VERSION " " $_AWS_CLI_ARCH " 2>&1 ) " } "
0 commit comments