1
1
#! /bin/bash
2
- VERSION=3.2.1
2
+ VERSION=3.2.3
3
3
printDownloaderHelp (){
4
4
cat << EOF
5
5
@@ -111,9 +111,21 @@ downloader() {
111
111
;;
112
112
esac
113
113
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
117
129
WGET2=1
118
130
CURL=1
119
131
WGET=1
@@ -132,15 +144,15 @@ downloader() {
132
144
for (( i = 0 ; i < ${# URLS[@]} ; i++ )) ; do
133
145
URL=" ${URLS[$i]} "
134
146
FILENAME=$( basename " $URL " )
135
- if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 0 ]]; then
147
+ if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 1 ]]; then
136
148
URLS_TO_DOWNLOAD+=" ${URL} "
137
- elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 0 ]]; then
149
+ elif [[ $CURL == 1 ]] && [[ $CURL_INSTALLED == 1 ]]; then
138
150
LOCAL_FILE=$FILENAME
139
151
REMOTE_URL=$URL
140
152
check_remote_vs_local " $LOCAL_FILE " " $REMOTE_URL "
141
153
if [ $CHECK_RESULT -eq 0 ]; then
142
154
URLS_TO_DOWNLOAD+=" ${URL} -o ${FILENAME} "
143
- if [ -n " ${ URLS[$i+1]} " ]; then
155
+ if [ $(( i + 1 )) -lt ${ # URLS[@]} ]; then
144
156
URLS_TO_DOWNLOAD+=" -k " ;
145
157
fi
146
158
else
@@ -155,29 +167,29 @@ downloader() {
155
167
echo " No URLS to download, continue"
156
168
else
157
169
if [[ " ${SILENT} " == 1 ]]; then
158
- if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 0 ]]; then
170
+ if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 1 ]]; then
159
171
echo
160
172
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
162
174
echo
163
175
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
165
177
echo
166
178
wget -nv -N -t20 ${URLS_TO_DOWNLOAD}
167
179
else
168
180
echo $ERROR_MSG ;
169
181
exit 1;
170
182
fi ;
171
183
else
172
- if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 0 ]]; then # 0 means true in this context
184
+ if [[ $WGET2 == 1 ]] && [[ $WGET2_INSTALLED == 1 ]]; then
173
185
echo " Downloading [wget2] urls:[$URLS_TO_DOWNLOAD ]"
174
186
echo
175
187
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
177
189
echo " Downloading [cURL] urls:[$URLS_TO_DOWNLOAD ]"
178
190
echo
179
191
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
181
193
echo " Downloading [wget] [$FILENAME ] urls:[$URLS_TO_DOWNLOAD ]"
182
194
echo
183
195
wget -nv --progress=bar -N -t20 $SSL_ARGS $URLS_TO_DOWNLOAD
0 commit comments