bzr 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. # We want to catch any unexpected failure, and exit immediately
  3. set -e
  4. # Download helper for bzr, to be called from the download wrapper script
  5. #
  6. # Call it as:
  7. # .../bzr [-q] OUT_FILE REPO_URL REV BASENAME
  8. #
  9. # Environment:
  10. # BZR : the bzr command to call
  11. verbose=
  12. while getopts :q OPT; do
  13. case "${OPT}" in
  14. q) verbose=-q;;
  15. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  16. esac
  17. done
  18. shift $((OPTIND-1))
  19. output="${1}"
  20. repo="${2}"
  21. rev="${3}"
  22. basename="${4}"
  23. shift 4 # Get rid of our options
  24. # Caller needs to single-quote its arguments to prevent them from
  25. # being expanded a second time (in case there are spaces in them)
  26. _bzr() {
  27. eval ${BZR} "${@}"
  28. }
  29. # --per-file-timestamps comes with bzr-2.2 (released August 2010),
  30. # so only pass it if bzr is recent enough. We compute versions as:
  31. # major*1000 + minor
  32. bzr_min_version=2002
  33. bzr_version=$(($(bzr --version |
  34. sed -r -n 's/^Bazaar \(bzr\) ([[:digit:]]+)\.([[:digit:]]+)\..*$/\1*1000+\2/p')
  35. ))
  36. # If the version is recent enough, we can generate reproducible
  37. # archives; otherwise, we just hope for the best (as it would
  38. # be downloaded from the BR mirror if what we generate here does
  39. # not match the hash we have for it).
  40. if [ ${bzr_version} -ge ${bzr_min_version} ]; then
  41. timestamp_opt="--per-file-timestamps"
  42. fi
  43. _bzr export ${verbose} --root="'${basename}/'" --format=tgz \
  44. ${timestamp_opt} - "${@}" "'${repo}'" -r "'${rev}'" \
  45. >"${output}"