2
1

bzr 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. # Caller needs to single-quote its arguments to prevent them from
  24. # being expanded a second time (in case there are spaces in them)
  25. _bzr() {
  26. eval ${BZR} "${@}"
  27. }
  28. # --per-file-timestamps comes with bzr-2.2 (released August 2010),
  29. # so only pass it if bzr is recent enough. We compute versions as:
  30. # major*1000 + minor
  31. bzr_min_version=2002
  32. bzr_version=$(($(bzr --version |
  33. sed -r -n 's/^Bazaar \(bzr\) ([[:digit:]]+)\.([[:digit:]]+)\..*$/\1*1000+\2/p')
  34. ))
  35. # If the version is recent enough, we can generate reproducible
  36. # archives; otherwise, we just hope for the best (as it would
  37. # be downloaded from the BR mirror if what we generate here does
  38. # not match the hash we have for it).
  39. if [ ${bzr_version} -ge ${bzr_min_version} ]; then
  40. timestamp_opt="--per-file-timestamps"
  41. fi
  42. _bzr export ${verbose} --root="'${basename}/'" --format=tgz \
  43. ${timestamp_opt} - "'${repo}'" -r "'${rev}'" \
  44. >"${output}"