bzr 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # Options:
  7. # -q Be quiet
  8. # -o FILE Generate archive in FILE.
  9. # -u URI Clone from repository at URI.
  10. # -c CSET Use changeset (or revision) CSET.
  11. # -n NAME Use basename NAME.
  12. #
  13. # Environment:
  14. # BZR : the bzr command to call
  15. quiet=
  16. while getopts "${BR_BACKEND_DL_GETOPTS}" OPT; do
  17. case "${OPT}" in
  18. q) quiet=-q;;
  19. o) output="${OPTARG}";;
  20. u) uri="${OPTARG}";;
  21. c) cset="${OPTARG}";;
  22. n) basename="${OPTARG}";;
  23. :) printf "option '%s' expects a mandatory argument\n" "${OPTARG}"; exit 1;;
  24. \?) printf "unknown option '%s'\n" "${OPTARG}" >&2; exit 1;;
  25. esac
  26. done
  27. shift $((OPTIND-1)) # Get rid of our options
  28. # Caller needs to single-quote its arguments to prevent them from
  29. # being expanded a second time (in case there are spaces in them)
  30. _bzr() {
  31. if [ -z "${quiet}" ]; then
  32. printf '%s ' ${BZR} "${@}"; printf '\n'
  33. fi
  34. _plain_bzr "$@"
  35. }
  36. # Note: please keep command below aligned with what is printed above
  37. _plain_bzr() {
  38. eval ${BZR} "${@}"
  39. }
  40. # --per-file-timestamps comes with bzr-2.2 (released August 2010),
  41. # so only pass it if bzr is recent enough. We compute versions as:
  42. # major*1000 + minor
  43. bzr_min_version=2002
  44. bzr_version=$(($(bzr --version |
  45. sed -r -n 's/^Bazaar \(bzr\) ([[:digit:]]+)\.([[:digit:]]+)\..*$/\1*1000+\2/p')
  46. ))
  47. # If the version is recent enough, we can generate reproducible
  48. # archives; otherwise, we just hope for the best (as it would
  49. # be downloaded from the BR mirror if what we generate here does
  50. # not match the hash we have for it).
  51. if [ ${bzr_version} -ge ${bzr_min_version} ]; then
  52. timestamp_opt="--per-file-timestamps"
  53. fi
  54. _bzr export ${quiet} --root="'${basename}/'" --format=tgz \
  55. ${timestamp_opt} - "${@}" "'${uri}'" -r "'${cset}'" \
  56. >"${output}"