diff --git a/README.md b/README.md index bafebb3..a655b9c 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,10 @@ should be using curl directly if your use case is not covered. * By default, **wcurl** will: * Encode whitespaces in URLs; - * Download multiple URLs in parallel; + * Download multiple URLs in parallel if the installed curl's version is >= 7.66.0; * Follow redirects; * Automatically choose a filename as output; - * Avoid overwriting files if the installed curl version is 7.83 or higher (--no-clobber); + * Avoid overwriting files if the installed curl's version is >= 7.83.0 (--no-clobber); * Perform retries; * Set the downloaded file timestamp to the value provided by the server, if available; * Disable **curl**'s URL globbing parser so **{}** and **\[\]** characters in URLs are not treated specially. diff --git a/wcurl b/wcurl index 496b38a..0c2df3a 100755 --- a/wcurl +++ b/wcurl @@ -113,17 +113,28 @@ sanitize() exec_curl() { CMD="curl " - # Store version to check if it supports --no-clobber. + # Store version to check if it supports --no-clobber and --parallel. curl_version=$($CMD --version | cut -f2 -d' ' | head -n1) - # --no-clobber is only supported since 7.83. + # --no-clobber is only supported since 7.83.0. + # --parallel is only supported since 7.66.0. if [ "$(echo "$curl_version" | cut -f1 -d.)" -ge 8 ]; then - NO_CLOBBER="--no-clobber" - elif [ "$(echo "$curl_version" | cut -f1 -d.)" -eq 7 ] && \ - [ "$(echo "$curl_version" | cut -f2 -d.)" -ge 83 ]; then - NO_CLOBBER="--no-clobber" + CURL_HAS_NO_CLOBBER="--no-clobber" + CURL_HAS_PARALLEL="--parallel" + elif [ "$(echo "$curl_version" | cut -f1 -d.)" -eq 7 ];then + if [ "$(echo "$curl_version" | cut -f2 -d.)" -ge 83 ]; then + CURL_HAS_NO_CLOBBER="--no-clobber" + else + CURL_HAS_NO_CLOBBER="" + fi + if [ "$(echo "$curl_version" | cut -f2 -d.)" -ge 66 ]; then + CURL_HAS_PARALLEL="--parallel" + else + CURL_HAS_PARALLEL="" + fi else - NO_CLOBBER="" + CURL_HAS_NO_CLOBBER="" + CURL_HAS_PARALLEL="" fi # Detecting whether we need --parallel. It's easier to rely on @@ -132,9 +143,9 @@ exec_curl() { set -- $URLS if [ "$#" -gt 1 ]; then - CURL_PARALLEL="--parallel" + CURL_PARALLEL="$CURL_HAS_PARALLEL" else - CURL_PARALLEL="" + CURL_PARALLEL="" fi # Start assembling the command. @@ -149,7 +160,7 @@ exec_curl() { NEXT_PARAMETER="" for url in ${URLS}; do # shellcheck disable=SC2086 - set -- "$@" ${NEXT_PARAMETER} ${PER_URL_PARAMETERS} ${NO_CLOBBER} ${CURL_OPTIONS} "${url}" + set -- "$@" ${NEXT_PARAMETER} ${PER_URL_PARAMETERS} ${CURL_HAS_NO_CLOBBER} ${CURL_OPTIONS} "${url}" NEXT_PARAMETER="--next" done diff --git a/wcurl.1 b/wcurl.1 index e40070e..31622d6 100644 --- a/wcurl.1 +++ b/wcurl.1 @@ -25,13 +25,13 @@ By default, \fBwcurl\fR will: .br \[bu] Encode whitespaces in URLs; .br -\[bu] Download multiple URLs in parallel; +\[bu] Download multiple URLs in parallel if the installed curl's version is >= 7.66.0; .br \[bu] Follow redirects; .br \[bu] Automatically choose a filename as output; .br -\[bu] Avoid overwriting files if the installed curl version is 7.83 or higher (--no-clobber); +\[bu] Avoid overwriting files if the installed curl's version is >= 7.83.0 (--no-clobber); .br \[bu] Perform retries; .br