scp 542 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. # We want to catch any command failure, and exit immediately
  3. set -e
  4. # Download helper for scp
  5. # Call it with:
  6. # $1: URL
  7. # $2: output file
  8. # And this environment:
  9. # SCP : the scp command to call
  10. url="${1}"
  11. output="${2}"
  12. tmp_dl="$( mktemp "${BUILD_DIR}/.XXXXXX" )"
  13. tmp_output="$( mktemp "${output}.XXXXXX" )"
  14. ret=1
  15. if ${SCP} "${url}" "${tmp_dl}"; then
  16. if mv "${tmp_dl}" "${tmp_output}"; then
  17. mv "${tmp_output}" "${output}"
  18. ret=0
  19. fi
  20. fi
  21. # Cleanup
  22. rm -f "${tmp_dl}" "${tmp_output}"
  23. exit ${ret}