git 893 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # We want to catch any command failure, and exit immediately
  3. set -e
  4. # Download helper for git
  5. # Call it with:
  6. # $1: git repo
  7. # $2: git cset
  8. # $3: package's basename (eg. foobar-1.2.3)
  9. # $4: output file
  10. # And this environment:
  11. # BR2_DL_DIR: path to Buildroot's download dir
  12. # GIT : the git command to call
  13. repo="${1}"
  14. cset="${2}"
  15. basename="${3}"
  16. output="${4}"
  17. repodir="${BR2_DL_DIR}/${basename}"
  18. if [ -n "$(${GIT} ls-remote "${repo}" "${cset}" 2>&1)" ]; then
  19. printf "Doing shallow clone\n"
  20. ${GIT} clone --depth 1 -b "${cset}" --bare "${repo}" "${repodir}"
  21. else
  22. printf "Doing full clone\n"
  23. ${GIT} clone --bare "${repo}" "${repodir}"
  24. fi
  25. pushd "${repodir}" >/dev/null
  26. ${GIT} archive --prefix="${basename}/" -o "${output}.tmp" --format=tar "${cset}"
  27. gzip -c "${output}.tmp" >"${output}"
  28. rm -f "${output}.tmp"
  29. popd >/dev/null
  30. rm -rf "${repodir}"