Skip to content

Commit 5f5c26a

Browse files
authored
Downloader 3.2.3 - fixes for install detection and single url for curl (#8009)
1 parent 676ae97 commit 5f5c26a

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

scripts/dev/downloader.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
VERSION=3.2.1
2+
VERSION=3.2.3
33
printDownloaderHelp(){
44
cat << EOF
55
@@ -111,9 +111,21 @@ downloader() {
111111
;;
112112
esac
113113
done
114-
WGET2_INSTALLED=$(command -v wget2 > /dev/null 2>&1; echo $?)
115-
CURL_INSTALLED=$(command -v curl > /dev/null 2>&1; echo $?)
116-
WGET_INSTALLED=$(command -v wget > /dev/null 2>&1; echo $?)
114+
if command -v wget2 > /dev/null 2>&1; then
115+
WGET2_INSTALLED=1
116+
else
117+
WGET2_INSTALLED=0
118+
fi
119+
if command -v curl > /dev/null 2>&1; then
120+
CURL_INSTALLED=1
121+
else
122+
CURL_INSTALLED=0
123+
fi
124+
if command -v wget > /dev/null 2>&1; then
125+
WGET_INSTALLED=1
126+
else
127+
WGET_INSTALLED=0
128+
fi
117129
WGET2=1
118130
CURL=1
119131
WGET=1
@@ -132,15 +144,15 @@ downloader() {
132144
for ((i = 0; i < ${#URLS[@]}; i++)); do
133145
URL="${URLS[$i]}"
134146
FILENAME=$(basename "$URL")
135-
if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 0 ]]; then
147+
if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 1 ]]; then
136148
URLS_TO_DOWNLOAD+="${URL} "
137-
elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 0 ]]; then
149+
elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 1 ]]; then
138150
LOCAL_FILE=$FILENAME
139151
REMOTE_URL=$URL
140152
check_remote_vs_local "$LOCAL_FILE" "$REMOTE_URL"
141153
if [ $CHECK_RESULT -eq 0 ]; then
142154
URLS_TO_DOWNLOAD+="${URL} -o ${FILENAME} "
143-
if [ -n "${URLS[$i+1]}" ]; then
155+
if [ $((i + 1)) -lt ${#URLS[@]} ]; then
144156
URLS_TO_DOWNLOAD+="-k ";
145157
fi
146158
else
@@ -155,29 +167,29 @@ downloader() {
155167
echo " No URLS to download, continue"
156168
else
157169
if [[ "${SILENT}" == 1 ]]; then
158-
if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 0 ]]; then
170+
if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 1 ]]; then
159171
echo
160172
wget2 -nv --progress=bar -N -t20 $SSL_ARGS $URLS_TO_DOWNLOAD
161-
elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 0 ]]; then
173+
elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 1 ]]; then
162174
echo
163175
curl -L --retry 20 --progress-bar $SSL_ARGS ${URLS_TO_DOWNLOAD}
164-
elif [[ $WGET == 1 ]] && [[ $WGET_INSTALLED == 0 ]]; then
176+
elif [[ $WGET == 1 ]] && [[ $WGET_INSTALLED == 1 ]]; then
165177
echo
166178
wget -nv -N -t20 ${URLS_TO_DOWNLOAD}
167179
else
168180
echo $ERROR_MSG;
169181
exit 1;
170182
fi;
171183
else
172-
if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 0 ]]; then # 0 means true in this context
184+
if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 1 ]]; then
173185
echo " Downloading [wget2] urls:[$URLS_TO_DOWNLOAD]"
174186
echo
175187
wget2 -N -nv --progress=bar -t20 $SSL_ARGS ${URLS_TO_DOWNLOAD}
176-
elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 0 ]]; then
188+
elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 1 ]]; then
177189
echo " Downloading [cURL] urls:[$URLS_TO_DOWNLOAD]"
178190
echo
179191
curl -L --retry 20 --progress-bar $SSL_ARGS ${URLS_TO_DOWNLOAD}
180-
elif [[ $WGET == 1 ]] && [[ $WGET_INSTALLED == 0 ]]; then
192+
elif [[ $WGET == 1 ]] && [[ $WGET_INSTALLED == 1 ]]; then
181193
echo " Downloading [wget] [$FILENAME] urls:[$URLS_TO_DOWNLOAD]"
182194
echo
183195
wget -nv --progress=bar -N -t20 $SSL_ARGS $URLS_TO_DOWNLOAD

0 commit comments

Comments
 (0)