wget 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for wget, 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. # -e ENCODE Tell wget to urlencode the filename passed to it
  12. #
  13. # Environment:
  14. # WGET : the wget command to call
  15. quiet=
  16. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  17. case "${OPT}" in
  18. q) quiet=-q;;
  19. o) output="${OPTARG}";;
  20. f) filename="${OPTARG}";;
  21. u) url="${OPTARG}";;
  22. e) encode="-e";;
  23. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  24. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  25. esac
  26. done
  27. shift $((OPTIND-1)) # Get rid of our options
  28. # Caller needs to single-quote its arguments to prevent them from
  29. # being expanded a second time (in case there are spaces in them)
  30. _wget() {
  31. if [ -z "${quiet}" ]; then
  32. printf '%s ' ${WGET} "${@}"; printf '\n'
  33. fi
  34. _plain_wget "$@"
  35. }
  36. # Note: please keep command below aligned with what is printed above
  37. _plain_wget() {
  38. eval ${WGET} "${@}"
  39. }
  40. # Replace every '?' with '%3F' in the filename; only for the PRIMARY and BACKUP
  41. # mirror
  42. [ -n "${encode}" ] && filename=${filename//\?/%3F}
  43. _wget ${quiet} "${@}" -O "'${output}'" "'${url}/${filename}'"