file 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. set -x
  5. # Download helper for cp, to be called from the download wrapper script
  6. #
  7. # Options:
  8. # -q Be quiet.
  9. # -o FILE Copy to file FILE.
  10. # -f FILE Copy from basename file FILE.
  11. # -u DIR Copy from FILE in DIR.
  12. #
  13. # Environment:
  14. # LOCALFILES: the cp command to call
  15. # 'cp' usually does not print anything on its stdout, whereas the
  16. # other download backends, even if not verbose, at least print some
  17. # progress information.
  18. # Make 'cp' verbose by default, so it behaves a bit like the others.
  19. verbose=-v
  20. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  21. case "${OPT}" in
  22. q) verbose=;;
  23. o) output="${OPTARG}";;
  24. f) file="${OPTARG}";;
  25. u) dir="${OPTARG}";;
  26. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  27. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  28. esac
  29. done
  30. shift $((OPTIND-1)) # Get rid of our options
  31. # Caller needs to single-quote its arguments to prevent them from
  32. # being expanded a second time (in case there are spaces in them)
  33. _localfiles() {
  34. eval ${LOCALFILES} "${@}"
  35. }
  36. _localfiles ${verbose} "'${dir}${file}'" "'${output}'"