2
1

scp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. verbose=
  15. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  16. case "${OPT}" in
  17. q) verbose=-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. eval ${SCP} "${@}"
  30. }
  31. # Remove any scheme prefix
  32. uri="${uri##scp://}"
  33. _scp ${verbose} "${@}" "'${uri}/${filename}'" "'${output}'"