2
1

curl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for curl, to be called from the download wrapper script
  5. #
  6. # Options:
  7. # -q Be quiet.
  8. # -o FILE Save into file FILE.
  9. # -f FILENAME The filename of the tarball to get at URL
  10. # -u URL Download file at URL.
  11. #
  12. # Environment:
  13. # CURL : the curl command to call
  14. quiet=
  15. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  16. case "${OPT}" in
  17. q) quiet=-s;;
  18. o) output="${OPTARG}";;
  19. f) filename="${OPTARG}";;
  20. u) url="${OPTARG}";;
  21. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  22. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  23. esac
  24. done
  25. shift $((OPTIND-1)) # Get rid of our options
  26. # Caller needs to single-quote its arguments to prevent them from
  27. # being expanded a second time (in case there are spaces in them)
  28. _curl() {
  29. if [ -z "${quiet}" ]; then
  30. printf '%s ' "${CURL}" "${@}"; printf '\n'
  31. fi
  32. _plain_curl "$@"
  33. }
  34. # Note: please keep command below aligned with what is printed above
  35. _plain_curl() {
  36. # shellcheck disable=SC2086 # We want splitting
  37. # shellcheck disable=SC2294
  38. eval ${CURL} "${@}"
  39. }
  40. _curl ${quiet} "${@}" --output "'${output}'" "'${url}/${filename}'"