scp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for scp, to be called from the download wrapper script
  5. #
  6. # Options:
  7. # -q Be quiet.
  8. # -o FILE Copy to local file FILE.
  9. # -f FILE Copy from remote file FILE.
  10. # -u URI Download file at URI.
  11. #
  12. # Environment:
  13. # SCP : the scp command to call
  14. quiet=
  15. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  16. case "${OPT}" in
  17. q) quiet=-q;;
  18. o) output="${OPTARG}";;
  19. f) filename="${OPTARG}";;
  20. u) uri="${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. _scp() {
  29. if [ -z "${quiet}" ]; then
  30. printf '%s ' ${SCP} "${@}"; printf '\n'
  31. fi
  32. _plain_scp "$@"
  33. }
  34. # Note: please keep command below aligned with what is printed above
  35. _plain_scp() {
  36. eval ${SCP} "${@}"
  37. }
  38. # Remove any scheme prefix
  39. uri="${uri##scp://}"
  40. _scp ${quiet} "${@}" "'${uri}/${filename}'" "'${output}'"