file 1.2 KB

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