wget 851 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # We want to catch any command failure, and exit immediately
  3. set -e
  4. # Download helper for wget
  5. # Call it with:
  6. # $1: URL
  7. # $2: output file
  8. # And this environment:
  9. # WGET : the wget command to call
  10. # BUILD_DIR: path to Buildroot's build dir
  11. url="${1}"
  12. output="${2}"
  13. tmp_dl="$( mktemp "${BUILD_DIR}/.XXXXXX" )"
  14. tmp_output="$( mktemp "${output}.XXXXXX" )"
  15. # Play tic-tac-toe with temp files
  16. # - first, we download to a trashable location (the build-dir)
  17. # - then we copy to a temporary tarball in the final location, so it is
  18. # on the same filesystem as the final file
  19. # - finally, we atomically rename to the final file
  20. ret=1
  21. if ${WGET} -O "${tmp_dl}" "${url}"; then
  22. if mv "${tmp_dl}" "${tmp_output}"; then
  23. mv "${tmp_output}" "${output}"
  24. ret=0
  25. fi
  26. fi
  27. rm -f "${tmp_dl}" "${tmp_output}"
  28. exit ${ret}