hg 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # We want to catch any command failure, and exit immediately
  3. set -e
  4. # Download helper for hg
  5. # Call it with:
  6. # $1: hg repo
  7. # $2: hg cset
  8. # $3: package's basename (eg. foobar-1.2.3)
  9. # $4: output file
  10. # And this environment:
  11. # HG : the hg command to call
  12. # BUILD_DIR: path to Buildroot's build dir
  13. repo="${1}"
  14. cset="${2}"
  15. basename="${3}"
  16. output="${4}"
  17. repodir="${basename}.tmp-hg-checkout"
  18. tmp_output="$( mktemp "${output}.XXXXXX" )"
  19. cd "${BUILD_DIR}"
  20. # Remove leftovers from a previous failed run
  21. rm -rf "${repodir}"
  22. # Play tic-tac-toe with temp files
  23. # - first, we download to a trashable location (the build-dir)
  24. # - then we create a temporary tarball in the final location, so it is
  25. # on the same filesystem as the final file
  26. # - finally, we atomically rename to the final file
  27. ret=1
  28. if ${HG} clone --noupdate --rev "${cset}" "${repo}" "${repodir}"; then
  29. if ${HG} archive --repository "${repodir}" --type tgz \
  30. --prefix "${basename}" --rev "${cset}" \
  31. "${tmp_output}"; then
  32. mv "${tmp_output}" "${output}"
  33. ret=0
  34. fi
  35. fi
  36. # Cleanup
  37. rm -rf "${repodir}" "${tmp_output}"
  38. exit ${ret}